]> mj.ucw.cz Git - libucw.git/commitdiff
Main: hook_add() is guaranteed to reschedule the hook
authorMartin Mares <mj@ucw.cz>
Thu, 9 Feb 2012 21:24:54 +0000 (22:24 +0100)
committerMartin Mares <mj@ucw.cz>
Thu, 9 Feb 2012 21:24:54 +0000 (22:24 +0100)
ucw/mainloop.c
ucw/mainloop.h

index 52a634898d73327b9a86cee232678795caa25e33..23eed5e14a4874c6134a4eaed5508bef2438bc6c 100644 (file)
@@ -379,8 +379,9 @@ hook_add(struct main_hook *ho)
   struct main_context *m = main_current();
 
   DBG("MAIN: Adding hook %p", ho);
-  if (!hook_is_active(ho))
-    clist_add_tail(&m->hook_list, &ho->n);
+  if (hook_is_active(ho))
+    clist_unlink(&ho->n);
+  clist_add_tail(&m->hook_list, &ho->n);
 }
 
 void
index 9cd97453a96b54e2466a85736e58c3d4b1760df4..0a4a8bbf78a88b89a35d594eff50cf8c39277d2c 100644 (file)
@@ -247,7 +247,8 @@ enum main_hook_return {
  * Inserts a new hook into the loop.
  * The hook will be scheduled at least once before next sleep.
  * May be called from inside a hook handler too.
- * Adding an already added hook does nothing.
+ * Adding an already added hook is permitted and if the hook has been run,
+ * it will be run again before next sleep.
  **/
 void hook_add(struct main_hook *ho);