[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_randr_CFLAGS) $(xcb_xinerama_CFLAGS) $(xcb_shape_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
awesome_SOURCES = \
@ -138,7 +138,7 @@ awesome_SOURCES += $(WIDGETS)
awesome_LDADD = $(pangocairo_LIBS) $(xcb_LIBS) $(xcb_event_LIBS) \
$(xcb_randr_LIBS) $(xcb_xinerama_LIBS) $(xcb_shape_LIBS) $(xcb_aux_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
awesome_client_SOURCES = \

View File

@ -53,6 +53,7 @@
#include "ewmh.h"
#include "tag.h"
#include "dbus.h"
#include "statusbar.h"
#include "common/socket.h"
#include "common/version.h"
#include "common/configopts.h"
@ -332,9 +333,6 @@ main(int argc, char **argv)
/* Text won't be printed correctly otherwise */
setlocale(LC_CTYPE, "");
/* initialize Glib for thread safeness */
g_thread_init(NULL);
/* X stuff */
globalconf.connection = xcb_connect(NULL, &globalconf.default_screen);
if(xcb_connection_has_error(globalconf.connection))
@ -479,6 +477,7 @@ main(int argc, char **argv)
/* refresh everything before waiting events */
layout_refresh();
statusbar_refresh();
/* main event loop */
while(running)
@ -540,11 +539,13 @@ main(int argc, char **argv)
} while((ev = xcb_poll_for_event(globalconf.connection)));
layout_refresh();
statusbar_refresh();
/* need to resync */
xcb_aux_sync(globalconf.connection);
}
layout_refresh();
statusbar_refresh();
xcb_aux_sync(globalconf.connection);
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.])])])
PKG_CHECK_MODULES([glib], [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])
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.])])
PKG_CHECK_MODULES([cairo_xcb], [cairo-xcb],,
[AC_MSG_ERROR([awesome requires cairo-xcb.])])
AC_CHECK_LIB(pthread, pthread_create)
AC_CHECK_LIB(readline, readline,
[AC_SUBST([readline_LIBS], ["-lreadline -lncurses"])],
[AC_MSG_FAILURE([awesome needs readline])], -lncurses)

View File

@ -22,8 +22,6 @@
#include <stdio.h>
#include <math.h>
#include <pthread.h>
#include <xcb/xcb.h>
#include <xcb/xcb_aux.h>
@ -53,7 +51,7 @@ statusbar_draw(statusbar_t *statusbar)
xcb_atom_t rootpix_atom, pixmap_atom;
xutil_intern_atom_request_t rootpix_atom_req, pixmap_atom_req;
statusbar->need_update.value = false;
statusbar->need_update = false;
if(!statusbar->position)
return;
@ -154,27 +152,20 @@ statusbar_draw(statusbar_t *statusbar)
xcb_aux_sync(globalconf.connection);
}
/** Statusbar thread main function.
/** Statusbar refresh function.
* \param p A pointer to a statusbar_t.
* \return Return NULL.
*/
static void *
statusbar_refresh(void *p)
void
statusbar_refresh(void)
{
statusbar_t *statusbar = (statusbar_t *) p;
int screen;
statusbar_t *statusbar;
while(running)
{
pthread_mutex_lock(&statusbar->need_update.lock);
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;
for(screen = 0; screen < globalconf.screens_info->nscreen; screen++)
for(statusbar = globalconf.screens[screen].statusbar; statusbar; statusbar = statusbar->next)
if(statusbar->need_update)
statusbar_draw(statusbar);
}
/** 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;
/* 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);
draw_context_delete(&statusbar->ctx);
if((statusbar->position = position) == Off)
{
pthread_mutex_unlock(&statusbar->need_update.lock);
return;
}
area = screen_get_area(statusbar->screen,
NULL,
@ -383,22 +367,8 @@ statusbar_position_update(statusbar_t *statusbar, position_t position)
xcb_map_window(globalconf.connection, statusbar->sw->window);
/* Set need update, and release everything out! */
statusbar->need_update.value = 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);
/* Set need update */
statusbar->need_update = true;
}
/** Check for statusbar equality.
@ -481,7 +451,7 @@ luaA_statusbar_widget_add(lua_State *L)
widget_t **widget = luaL_checkudata(L, 2, "widget");
widget_node_t *w = p_new(widget_node_t, 1);
statusbar_needupdate(*sb);
(*sb)->need_update = true;
w->widget = *widget;
widget_node_list_append(&(*sb)->widgets, w);
widget_ref(widget);
@ -515,11 +485,6 @@ luaA_statusbar_add(lua_State *L)
(*sb)->screen = 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_ref(sb);
@ -527,10 +492,6 @@ luaA_statusbar_add(lua_State *L)
for(s = globalconf.screens[screen].statusbar; s; s = s->next)
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;
}

View File

@ -35,7 +35,7 @@ statusbar_delete(statusbar_t **statusbar)
p_delete(statusbar);
}
void statusbar_needupdate(statusbar_t *);
void statusbar_refresh(void);
DO_RCNT(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_t *ctx;
/** Need update */
struct
{
bool value;
pthread_mutex_t lock;
pthread_cond_t cond;
} need_update;
/** Thread id */
pthread_t tid;
bool need_update;
/** Default colors */
struct
{

View File

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