From: Pavel Charvat Date: Wed, 16 Jun 2010 18:10:25 +0000 (+0200) Subject: mainloop: Improved deletion and insertion of hooks. X-Git-Tag: holmes-import~5 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=1e43161840b05a63cf2e67ff5bbde007db7952a9;p=libucw.git mainloop: Improved deletion and insertion of hooks. It is now guaranted that: * You can safely remove hook anytime, even from other hook. * Newly inserted hook will be called at least once before next sleep. --- diff --git a/ucw/mainloop.c b/ucw/mainloop.c index b87ed862..c532b890 100644 --- a/ucw/mainloop.c +++ b/ucw/mainloop.c @@ -425,7 +425,6 @@ main_loop(void) struct main_hook *ho; struct main_timer *tm; struct main_process *pr; - cnode *tmp; main_get_time(); for (;;) @@ -438,13 +437,17 @@ main_loop(void) } int hook_min = HOOK_RETRY; int hook_max = HOOK_SHUTDOWN; - CLIST_WALK_DELSAFE(ho, main_hook_list, tmp) + clist hook_done; + clist_init(&hook_done); + while (ho = clist_remove_head(&main_hook_list)) { + clist_add_tail(&hook_done, &ho->n); DBG("MAIN: Hook %p", ho); int ret = ho->handler(ho); hook_min = MIN(hook_min, ret); hook_max = MAX(hook_max, ret); } + clist_move(&main_hook_list, &hook_done); if (hook_min == HOOK_SHUTDOWN || hook_min == HOOK_DONE && hook_max == HOOK_DONE || main_shutdown)