From 1e43161840b05a63cf2e67ff5bbde007db7952a9 Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Wed, 16 Jun 2010 20:10:25 +0200 Subject: [PATCH] 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. --- ucw/mainloop.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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) -- 2.39.2