ev_run() might exit even when ev_pending_count() > 0

Denis Bilenko denis.bilenko at gmail.com
Sat May 5 12:52:31 CEST 2012


Hi Marc,

It is currently possible for this to happen:

    ev_run(&loop, 0); // exits naturally (that is, without being
interrupted with ev_break())
    assert(ev_pending_count() == 0); // FAILS, ev_pending_count() is positive.

The documentation says that ev_run() loops until there are active
watchers and says nothing about pending watchers. But it seems that
the intended behavior is for ev_run() to exit when there's nothing
left to do, so a pending event should keep ev_run() running.

There proposed patch below changes ev_run() to keep running when # of
pending is not zero.


diff -r 28a348b81610 libev/ev.c
--- a/libev/ev.c        Fri May 04 21:10:10 2012 +0400
+++ b/libev/ev.c        Sat May 05 14:35:14 2012 +0400
@@ -2896,6 +2896,19 @@
     }
 }

+inline_speed int
+has_pending (EV_P)
+{
+  int pri;
+
+  for (pri = NUMPRI; pri--; )
+    if (pendingcnt [pri])
+        return 1;
+
+  return 0;
+}
+
+
 void
 ev_run (EV_P_ int flags)
 {
@@ -3052,7 +3065,7 @@
       EV_INVOKE_PENDING;
     }
   while (expect_true (
-    activecnt
+    (activecnt || has_pending(EV_A))
     && !loop_done
     && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT))
   ));


Cheers,
Denis.



More information about the libev mailing list