]> mj.ucw.cz Git - libucw.git/commitdiff
mainloop: Improved deletion and insertion of hooks.
authorPavel Charvat <pchar@ucw.cz>
Wed, 16 Jun 2010 18:10:25 +0000 (20:10 +0200)
committerPavel Charvat <pchar@ucw.cz>
Wed, 16 Jun 2010 18:10:25 +0000 (20:10 +0200)
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

index b87ed8620108231ad47ed79a0546e723247609f3..c532b89000718b335532c2be3e2fbf858cdb5ef0 100644 (file)
@@ -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)