From 0dfc9152bd05b9a10dd0a51fd4fb70fc02a2d18c Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Tue, 24 Oct 2017 00:33:28 +0200 Subject: [PATCH] uev_run(): Exit event loop as soon as there are no more watchers The purpose of the event loop is to process events on all registered watches. When all watchers have completed the event loop should exit. Having implemented a workaround for issue #12 in commit e0cebc3 it has become evident we need to check the list of watchers at the beginning of the event loop rather than the end, since the workaround skips past the end. Signed-off-by: Joachim Nilsson --- src/uev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uev.c b/src/uev.c index 89d5e5a..1d788c5 100644 --- a/src/uev.c +++ b/src/uev.c @@ -284,7 +284,7 @@ int uev_run(uev_ctx_t *ctx, int flags) uev_timer_set(w, w->u.t.timeout, w->u.t.period); } - while (ctx->running) { + while (ctx->running && !LIST_EMPTY(&ctx->watchers)) { int i, nfds, rerun = 0; struct epoll_event events[UEV_MAX_EVENTS]; @@ -408,7 +408,7 @@ int uev_run(uev_ctx_t *ctx, int flags) } } - if ((flags & UEV_ONCE) || LIST_EMPTY(&ctx->watchers)) + if (flags & UEV_ONCE) break; }