Reinitialize timers correctly when created from their own callbacks
o9000 mrovi9000@gmail.com
5 files changed,
9 insertions(+),
9 deletions(-)
M
src/battery/battery.c
→
src/battery/battery.c
@@ -226,8 +226,7 @@ return;
battery_found = battery_os_init(); - if (!battery_timeout) - battery_timeout = add_timeout(10, 30000, update_battery_tick, 0, &battery_timeout); + battery_timeout = add_timeout(10, 30000, update_battery_tick, 0, &battery_timeout); update_battery(); }
M
src/clock/clock.c
→
src/clock/clock.c
@@ -154,8 +154,8 @@
void update_clocks_sec(void *arg) { gettimeofday(&time_clock, 0); - clock_timeout = add_timeout(ms_until_second_change(&time_clock), 0, update_clocks_sec, 0, NULL); update_clocks(); + clock_timeout = add_timeout(ms_until_second_change(&time_clock), 0, update_clocks_sec, 0, &clock_timeout); } void update_clocks_min(void *arg)@@ -164,10 +164,10 @@ // remember old_sec because after suspend/hibernate the clock should be updated directly, and not
// on next minute change static time_t old_sec = 0; gettimeofday(&time_clock, 0); - clock_timeout = add_timeout(ms_until_second_change(&time_clock), 0, update_clocks_min, 0, NULL); if (time_clock.tv_sec % 60 == 0 || time_clock.tv_sec - old_sec > 60) update_clocks(); old_sec = time_clock.tv_sec; + clock_timeout = add_timeout(ms_until_second_change(&time_clock), 0, update_clocks_min, 0, &clock_timeout); } gboolean time_format_needs_sec_ticks(char *time_format)
M
src/execplugin/execplugin.c
→
src/execplugin/execplugin.c
@@ -196,8 +196,7 @@ execp->area.resize_needed = TRUE;
execp->area.on_screen = TRUE; instantiate_area_gradients(&execp->area); - if (!execp->backend->timer) - execp->backend->timer = add_timeout(10, 0, execp_timer_callback, execp, &execp->backend->timer); + execp->backend->timer = add_timeout(10, 0, execp_timer_callback, execp, &execp->backend->timer); execp_update_post_read(execp); }
M
src/systray/systraybar.c
→
src/systray/systraybar.c
@@ -1498,7 +1498,7 @@ unsigned int width, height, depth;
Window root; if (!XGetGeometry(server.display, traywin->win, &root, &xpos, &ypos, &width, &height, &border_width, &depth)) { stop_timeout(traywin->render_timeout); - if (!traywin->resize_timeout) + if (!traywin->render_timeout) traywin->render_timeout = add_timeout(min_refresh_period, 0, systray_render_icon, traywin, &traywin->render_timeout); systray_render_icon_from_image(traywin);@@ -1507,7 +1507,7 @@ return;
} else { if (xpos != 0 || ypos != 0 || width != traywin->width || height != traywin->height) { stop_timeout(traywin->render_timeout); - if (!traywin->resize_timeout) + if (!traywin->render_timeout) traywin->render_timeout = add_timeout(min_refresh_period, 0, systray_render_icon, traywin, &traywin->render_timeout); systray_render_icon_from_image(traywin);
M
src/util/timer.c
→
src/util/timer.c
@@ -44,6 +44,7 @@ void (*_callback)(void *);
void *arg; multi_timeout *multi_timeout; timeout **self; + gboolean expired; }; void add_timeout_intern(int value_msec, int interval_msec, void (*_callback)(void *), void *arg, timeout *t);@@ -106,7 +107,7 @@ // however it's save to call it.
timeout *add_timeout(int value_msec, int interval_msec, void (*_callback)(void *), void *arg, timeout **self) { - if (self && *self) + if (self && *self && !(*self)->expired) return *self; timeout *t = calloc(1, sizeof(timeout)); t->self = self;@@ -155,6 +156,7 @@ gettime(&cur_time);
t = timeout_list->data; if (compare_timespecs(&t->timeout_expires, &cur_time) <= 0) { // it's time for the callback function + t->expired = t->interval_msec == 0; t->_callback(t->arg); // If _callback() calls stop_timeout(t) the timer 't' was freed and is not in the timeout_list if (g_slist_find(timeout_list, t)) {