[statusbar] Remove multi-threading code

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-05-31 16:04:46 +02:00
parent 5e01a24ac3
commit 01fe4e3331
7 changed files with 23 additions and 71 deletions

View File

@ -99,7 +99,7 @@ AM_CPPFLAGS = $(pangocairo_CFLAGS) $(AWESOME_CFLAGS) \
$(xcb_CFLAGS) $(xcb_event_CFLAGS) \ $(xcb_CFLAGS) $(xcb_event_CFLAGS) \
$(xcb_randr_CFLAGS) $(xcb_xinerama_CFLAGS) $(xcb_shape_CFLAGS) \ $(xcb_randr_CFLAGS) $(xcb_xinerama_CFLAGS) $(xcb_shape_CFLAGS) \
$(xcb_aux_CFLAGS) $(xcb_atom_CFLAGS) $(xcb_keysyms_CFLAGS) \ $(xcb_aux_CFLAGS) $(xcb_atom_CFLAGS) $(xcb_keysyms_CFLAGS) \
$(xcb_icccm_CFLAGS) $(dbus_CFLAGS) $(Lua_CFLAGS) $(gthread_CLFAGS) $(xcb_icccm_CFLAGS) $(dbus_CFLAGS) $(Lua_CFLAGS)
bin_PROGRAMS += awesome bin_PROGRAMS += awesome
awesome_SOURCES = \ awesome_SOURCES = \
@ -138,7 +138,7 @@ awesome_SOURCES += $(WIDGETS)
awesome_LDADD = $(pangocairo_LIBS) $(xcb_LIBS) $(xcb_event_LIBS) \ awesome_LDADD = $(pangocairo_LIBS) $(xcb_LIBS) $(xcb_event_LIBS) \
$(xcb_randr_LIBS) $(xcb_xinerama_LIBS) $(xcb_shape_LIBS) $(xcb_aux_LIBS) \ $(xcb_randr_LIBS) $(xcb_xinerama_LIBS) $(xcb_shape_LIBS) $(xcb_aux_LIBS) \
$(xcb_atom_LIBS) $(xcb_keysyms_LIBS) $(xcb_icccm_LIBS) $(dbus_LIBS)\ $(xcb_atom_LIBS) $(xcb_keysyms_LIBS) $(xcb_icccm_LIBS) $(dbus_LIBS)\
$(imlib2_LIBS) $(GTK_LIBS) $(Lua_LIBS) $(gthread_LIBS) $(imlib2_LIBS) $(GTK_LIBS) $(Lua_LIBS)
bin_PROGRAMS += awesome-client bin_PROGRAMS += awesome-client
awesome_client_SOURCES = \ awesome_client_SOURCES = \

View File

@ -53,6 +53,7 @@
#include "ewmh.h" #include "ewmh.h"
#include "tag.h" #include "tag.h"
#include "dbus.h" #include "dbus.h"
#include "statusbar.h"
#include "common/socket.h" #include "common/socket.h"
#include "common/version.h" #include "common/version.h"
#include "common/configopts.h" #include "common/configopts.h"
@ -332,9 +333,6 @@ main(int argc, char **argv)
/* Text won't be printed correctly otherwise */ /* Text won't be printed correctly otherwise */
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
/* initialize Glib for thread safeness */
g_thread_init(NULL);
/* X stuff */ /* X stuff */
globalconf.connection = xcb_connect(NULL, &globalconf.default_screen); globalconf.connection = xcb_connect(NULL, &globalconf.default_screen);
if(xcb_connection_has_error(globalconf.connection)) if(xcb_connection_has_error(globalconf.connection))
@ -479,6 +477,7 @@ main(int argc, char **argv)
/* refresh everything before waiting events */ /* refresh everything before waiting events */
layout_refresh(); layout_refresh();
statusbar_refresh();
/* main event loop */ /* main event loop */
while(running) while(running)
@ -540,11 +539,13 @@ main(int argc, char **argv)
} while((ev = xcb_poll_for_event(globalconf.connection))); } while((ev = xcb_poll_for_event(globalconf.connection)));
layout_refresh(); layout_refresh();
statusbar_refresh();
/* need to resync */ /* need to resync */
xcb_aux_sync(globalconf.connection); xcb_aux_sync(globalconf.connection);
} }
layout_refresh(); layout_refresh();
statusbar_refresh();
xcb_aux_sync(globalconf.connection); xcb_aux_sync(globalconf.connection);
if(tv && lastrun + globalconf.stimeout <= time(NULL)) if(tv && lastrun + globalconf.stimeout <= time(NULL))

View File

@ -123,8 +123,6 @@ PKG_CHECK_MODULES([Lua], [lua >= 5.1],,
[AC_MSG_ERROR([awesome requires Lua >= 5.1.])])]) [AC_MSG_ERROR([awesome requires Lua >= 5.1.])])])
PKG_CHECK_MODULES([glib], [glib-2.0],, PKG_CHECK_MODULES([glib], [glib-2.0],,
[AC_MSG_ERROR([awesome requires glib-2.0.])]) [AC_MSG_ERROR([awesome requires glib-2.0.])])
PKG_CHECK_MODULES([gthread], [gthread-2.0],,
[AC_MSG_ERROR([awesome requires gthread-2.0.])])
AC_ARG_WITH([dbus], AS_HELP_STRING([--with-dbus], [Build with D-BUS (default: enabled)]), [], [with_dbus=yes]) AC_ARG_WITH([dbus], AS_HELP_STRING([--with-dbus], [Build with D-BUS (default: enabled)]), [], [with_dbus=yes])
if test "x$with_dbus" == "xyes"; then if test "x$with_dbus" == "xyes"; then
@ -165,7 +163,6 @@ PKG_CHECK_MODULES([xcb_icccm], [xcb-icccm],,
[AC_MSG_ERROR([awesome requires xcb-icccm.])]) [AC_MSG_ERROR([awesome requires xcb-icccm.])])
PKG_CHECK_MODULES([cairo_xcb], [cairo-xcb],, PKG_CHECK_MODULES([cairo_xcb], [cairo-xcb],,
[AC_MSG_ERROR([awesome requires cairo-xcb.])]) [AC_MSG_ERROR([awesome requires cairo-xcb.])])
AC_CHECK_LIB(pthread, pthread_create)
AC_CHECK_LIB(readline, readline, AC_CHECK_LIB(readline, readline,
[AC_SUBST([readline_LIBS], ["-lreadline -lncurses"])], [AC_SUBST([readline_LIBS], ["-lreadline -lncurses"])],
[AC_MSG_FAILURE([awesome needs readline])], -lncurses) [AC_MSG_FAILURE([awesome needs readline])], -lncurses)

View File

@ -22,8 +22,6 @@
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <pthread.h>
#include <xcb/xcb.h> #include <xcb/xcb.h>
#include <xcb/xcb_aux.h> #include <xcb/xcb_aux.h>
@ -53,7 +51,7 @@ statusbar_draw(statusbar_t *statusbar)
xcb_atom_t rootpix_atom, pixmap_atom; xcb_atom_t rootpix_atom, pixmap_atom;
xutil_intern_atom_request_t rootpix_atom_req, pixmap_atom_req; xutil_intern_atom_request_t rootpix_atom_req, pixmap_atom_req;
statusbar->need_update.value = false; statusbar->need_update = false;
if(!statusbar->position) if(!statusbar->position)
return; return;
@ -154,27 +152,20 @@ statusbar_draw(statusbar_t *statusbar)
xcb_aux_sync(globalconf.connection); xcb_aux_sync(globalconf.connection);
} }
/** Statusbar thread main function. /** Statusbar refresh function.
* \param p A pointer to a statusbar_t. * \param p A pointer to a statusbar_t.
* \return Return NULL. * \return Return NULL.
*/ */
static void * void
statusbar_refresh(void *p) statusbar_refresh(void)
{ {
statusbar_t *statusbar = (statusbar_t *) p; int screen;
statusbar_t *statusbar;
while(running) for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
{ for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next)
pthread_mutex_lock(&statusbar->need_update.lock); if(statusbar->need_update)
statusbar_draw(statusbar);
while(!statusbar->need_update.value)
pthread_cond_wait(&statusbar->need_update.cond, &statusbar->need_update.lock);
statusbar_draw(statusbar);
pthread_mutex_unlock(&statusbar->need_update.lock);
}
return NULL;
} }
/** Update the statusbar position. It deletes every statusbar resources and /** Update the statusbar position. It deletes every statusbar resources and
@ -193,18 +184,11 @@ statusbar_position_update(statusbar_t *statusbar, position_t position)
globalconf.screens[statusbar->screen].need_arrange = true; globalconf.screens[statusbar->screen].need_arrange = true;
/* Lock the update thread.
* We will reinit every stuff so, it better do nothing at this moment. */
pthread_mutex_lock(&statusbar->need_update.lock);
simplewindow_delete(&statusbar->sw); simplewindow_delete(&statusbar->sw);
draw_context_delete(&statusbar->ctx); draw_context_delete(&statusbar->ctx);
if((statusbar->position = position) == Off) if((statusbar->position = position) == Off)
{
pthread_mutex_unlock(&statusbar->need_update.lock);
return; return;
}
area = screen_get_area(statusbar->screen, area = screen_get_area(statusbar->screen,
NULL, NULL,
@ -383,22 +367,8 @@ statusbar_position_update(statusbar_t *statusbar, position_t position)
xcb_map_window(globalconf.connection, statusbar->sw->window); xcb_map_window(globalconf.connection, statusbar->sw->window);
/* Set need update, and release everything out! */ /* Set need update */
statusbar->need_update.value = true; statusbar->need_update = true;
pthread_mutex_unlock(&statusbar->need_update.lock);
pthread_cond_broadcast(&statusbar->need_update.cond);
}
/** Update the need_update attribute of a statusbar to true.
* \param statusbar The statusbar to flag.
*/
void
statusbar_needupdate(statusbar_t *statusbar)
{
pthread_mutex_lock(&statusbar->need_update.lock);
statusbar->need_update.value = true;
pthread_mutex_unlock(&statusbar->need_update.lock);
pthread_cond_broadcast(&statusbar->need_update.cond);
} }
/** Check for statusbar equality. /** Check for statusbar equality.
@ -481,7 +451,7 @@ luaA_statusbar_widget_add(lua_State *L)
widget_t **widget = luaL_checkudata(L, 2, "widget"); widget_t **widget = luaL_checkudata(L, 2, "widget");
widget_node_t *w = p_new(widget_node_t, 1); widget_node_t *w = p_new(widget_node_t, 1);
statusbar_needupdate(*sb); (*sb)->need_update = true;
w->widget = *widget; w->widget = *widget;
widget_node_list_append(&(*sb)->widgets, w); widget_node_list_append(&(*sb)->widgets, w);
widget_ref(widget); widget_ref(widget);
@ -515,11 +485,6 @@ luaA_statusbar_add(lua_State *L)
(*sb)->screen = screen; (*sb)->screen = screen;
(*sb)->phys_screen = screen_virttophys(screen); (*sb)->phys_screen = screen_virttophys(screen);
/* Initialize thread stuffs before any position update, since it will
* set a need_update and so lock */
pthread_cond_init(&(*sb)->need_update.cond, NULL);
pthread_mutex_init(&(*sb)->need_update.lock, NULL);
statusbar_list_append(&globalconf.screens[screen].statusbar, *sb); statusbar_list_append(&globalconf.screens[screen].statusbar, *sb);
statusbar_ref(sb); statusbar_ref(sb);
@ -527,10 +492,6 @@ luaA_statusbar_add(lua_State *L)
for(s = globalconf.screens[screen].statusbar; s; s = s->next) for(s = globalconf.screens[screen].statusbar; s; s = s->next)
statusbar_position_update(s, s->position); statusbar_position_update(s, s->position);
/* Start the thread */
if(pthread_create(&(*sb)->tid, NULL, statusbar_refresh, *sb))
perror("unable to create thread");
return 0; return 0;
} }

View File

@ -35,7 +35,7 @@ statusbar_delete(statusbar_t **statusbar)
p_delete(statusbar); p_delete(statusbar);
} }
void statusbar_needupdate(statusbar_t *); void statusbar_refresh(void);
DO_RCNT(statusbar_t, statusbar, statusbar_delete) DO_RCNT(statusbar_t, statusbar, statusbar_delete)
DO_SLIST(statusbar_t, statusbar, statusbar_delete) DO_SLIST(statusbar_t, statusbar, statusbar_delete)

View File

@ -215,14 +215,7 @@ struct statusbar_t
/** Draw context */ /** Draw context */
draw_context_t *ctx; draw_context_t *ctx;
/** Need update */ /** Need update */
struct bool need_update;
{
bool value;
pthread_mutex_t lock;
pthread_cond_t cond;
} need_update;
/** Thread id */
pthread_t tid;
/** Default colors */ /** Default colors */
struct struct
{ {

View File

@ -129,7 +129,7 @@ widget_invalidate_cache(int screen, int flags)
for(widget = statusbar->widgets; widget; widget = widget->next) for(widget = statusbar->widgets; widget; widget = widget->next)
if(widget->widget->cache_flags & flags) if(widget->widget->cache_flags & flags)
{ {
statusbar_needupdate(statusbar); statusbar->need_update = true;
break; break;
} }
} }
@ -151,7 +151,7 @@ widget_invalidate_statusbar_bywidget(widget_t *widget)
for(witer = statusbar->widgets; witer; witer = witer->next) for(witer = statusbar->widgets; witer; witer = witer->next)
if(witer->widget == widget) if(witer->widget == widget)
{ {
statusbar_needupdate(statusbar); statusbar->need_update = true;
break; break;
} }
} }