X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/756a6378f76a80c595335d4a78ab426cc44d247d..614930116ff2c76f9954eee0cf4c5194ee4204e0:/ev.c diff --git a/ev.c b/ev.c index 3518002..8cb6141 100644 --- a/ev.c +++ b/ev.c @@ -888,6 +888,12 @@ ev_backend (EV_P) return backend; } +unsigned int +ev_loop_count (EV_P) +{ + return loop_count; +} + static void noinline loop_init (EV_P_ unsigned int flags) { @@ -1344,7 +1350,7 @@ ev_loop (EV_P_ int flags) call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ - while (activecnt) + do { #ifndef _WIN32 if (expect_false (curpid)) /* penalise the forking check even more */ @@ -1372,6 +1378,9 @@ ev_loop (EV_P_ int flags) call_pending (EV_A); } + if (expect_false (!activecnt)) + break; + /* we might have forked, so reify kernel state if necessary */ if (expect_false (postfork)) loop_fork (EV_A); @@ -1383,7 +1392,7 @@ ev_loop (EV_P_ int flags) { ev_tstamp block; - if (flags & EVLOOP_NONBLOCK || idlecnt) + if (expect_false (flags & EVLOOP_NONBLOCK || idlecnt || !activecnt)) block = 0.; /* do not block at all */ else { @@ -1417,6 +1426,7 @@ ev_loop (EV_P_ int flags) if (expect_false (block < 0.)) block = 0.; } + ++loop_count; backend_poll (EV_A_ block); } @@ -1439,9 +1449,8 @@ ev_loop (EV_P_ int flags) call_pending (EV_A); - if (expect_false (loop_done)) - break; } + while (expect_true (activecnt && !loop_done)); if (loop_done == EVUNLOOP_ONE) loop_done = EVUNLOOP_CANCEL;