--- libev/ev.c 2007/11/24 09:48:38 1.138 +++ libev/ev.c 2007/11/25 09:24:37 1.139 @@ -1076,6 +1076,8 @@ if (expect_true (p->w)) { + assert (("non-pending watcher on pending list", p->w->pending)); + p->w->pending = 0; EV_CB_INVOKE (p->w, p->events); } @@ -1191,7 +1193,15 @@ { ev_tstamp odiff = rtmn_diff; - for (i = 4; --i; ) /* loop a few times, before making important decisions */ + /* loop a few times, before making important decisions. + * on the choice of "4": one iteration isn't enough, + * in case we get preempted during the calls to + * ev_time and get_clock. a second call is almost guarenteed + * to succeed in that case, though. and looping a few more times + * doesn't hurt either as we only do this on time-jumps or + * in the unlikely event of getting preempted here. + */ + for (i = 4; --i; ) { rtmn_diff = ev_rt_now - mn_now; @@ -1553,7 +1563,12 @@ if (expect_false (!ev_is_active (w))) return; - idles [((W)w)->active - 1] = idles [--idlecnt]; + { + int active = ((W)w)->active; + idles [active - 1] = idles [--idlecnt]; + ((W)idles [active - 1])->active = active; + } + ev_stop (EV_A_ (W)w); } @@ -1575,7 +1590,12 @@ if (expect_false (!ev_is_active (w))) return; - prepares [((W)w)->active - 1] = prepares [--preparecnt]; + { + int active = ((W)w)->active; + prepares [active - 1] = prepares [--preparecnt]; + ((W)prepares [active - 1])->active = active; + } + ev_stop (EV_A_ (W)w); } @@ -1597,7 +1617,12 @@ if (expect_false (!ev_is_active (w))) return; - checks [((W)w)->active - 1] = checks [--checkcnt]; + { + int active = ((W)w)->active; + checks [active - 1] = checks [--checkcnt]; + ((W)checks [active - 1])->active = active; + } + ev_stop (EV_A_ (W)w); }