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 <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2017-10-24 00:33:28 +02:00
parent 9642443a7c
commit 0dfc9152bd
+2 -2
View File
@@ -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;
}