From 79cc87d28d7abb92d24ae39eae1cfad2eab0a727 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Thu, 9 Feb 2012 22:24:54 +0100 Subject: [PATCH] Main: hook_add() is guaranteed to reschedule the hook --- ucw/mainloop.c | 5 +++-- ucw/mainloop.h | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ucw/mainloop.c b/ucw/mainloop.c index 52a63489..23eed5e1 100644 --- a/ucw/mainloop.c +++ b/ucw/mainloop.c @@ -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 diff --git a/ucw/mainloop.h b/ucw/mainloop.h index 9cd97453..0a4a8bbf 100644 --- a/ucw/mainloop.h +++ b/ucw/mainloop.h @@ -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); -- 2.39.2