From 7d6aa5ee68962f91de3690ce4bb39ec7c9776e9e Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 May 2012 12:05:07 -0400 Subject: [PATCH] Add an event_base_loopcontinue() to tell libevent to rescan right away --- event.c | 19 +++++++++++++++++++ include/event2/event.h | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/event.c b/event.c index 56d12ab6..5cb5d28c 100644 --- a/event.c +++ b/event.c @@ -1619,6 +1619,25 @@ event_base_loopbreak(struct event_base *event_base) return r; } +int +event_base_loopcontinue(struct event_base *event_base) +{ + int r = 0; + if (event_base == NULL) + return (-1); + + EVBASE_ACQUIRE_LOCK(event_base, th_base_lock); + event_base->event_continue = 1; + + if (EVBASE_NEED_NOTIFY(event_base)) { + r = evthread_notify_base(event_base); + } else { + r = (0); + } + EVBASE_RELEASE_LOCK(event_base, th_base_lock); + return r; +} + int event_base_got_break(struct event_base *event_base) { diff --git a/include/event2/event.h b/include/event2/event.h index 1cfc3ce9..4f5a7c83 100644 --- a/include/event2/event.h +++ b/include/event2/event.h @@ -754,6 +754,25 @@ int event_base_loopexit(struct event_base *, const struct timeval *); */ int event_base_loopbreak(struct event_base *); +/** + Tell the active event_base_loop() to scan for new events immediately. + + Calling this function makes the currently active event_base_loop() + start the loop over again (scanning for new events) after the current + event callback finishes. If the event loop is not running, this + function has no effect. + + event_base_loopbreak() is typically invoked from this event's callback. + This behavior is analogous to the "continue;" statement. + + Subsequent invocations of event loop will proceed normally. + + @param eb the event_base structure returned by event_init() + @return 0 if successful, or -1 if an error occurred + @see event_base_loopbreak() + */ +int event_base_loopcontinue(struct event_base *); + /** Checks if the event loop was told to exit by event_loopexit(). -- 2.40.0