--- libev/ev.c 2007/10/31 17:55:55 1.19 +++ libev/ev.c 2007/10/31 18:28:00 1.20 @@ -326,6 +326,9 @@ static struct ev_idle **idles; static int idlemax, idlecnt; +static struct ev_prepare **prepares; +static int preparemax, preparecnt; + static struct ev_check **checks; static int checkmax, checkcnt; @@ -555,14 +558,15 @@ double block; ev_loop_done = flags & EVLOOP_ONESHOT ? 1 : 0; - if (checkcnt) - { - queue_events ((W *)checks, checkcnt, EV_CHECK); - call_pending (); - } - do { + /* queue check watchers (and execute them) */ + if (checkcnt) + { + queue_events ((W *)prepares, preparecnt, EV_PREPARE); + call_pending (); + } + /* update fd-related kernel structures */ fd_reify (); @@ -598,15 +602,16 @@ time_update (); /* queue pending timers and reschedule them */ - periodics_reify (); /* absolute timers first */ - timers_reify (); /* relative timers second */ + timers_reify (); /* relative timers called last */ + periodics_reify (); /* absolute timers called first */ /* queue idle watchers unless io or timers are pending */ if (!pendingcnt) queue_events ((W *)idles, idlecnt, EV_IDLE); - /* queue check and possibly idle watchers */ - queue_events ((W *)checks, checkcnt, EV_CHECK); + /* queue check watchers, to be executed first */ + if (checkcnt) + queue_events ((W *)checks, checkcnt, EV_CHECK); call_pending (); } @@ -835,6 +840,26 @@ ev_stop ((W)w); } +void evprepare_start (struct ev_prepare *w) +{ + if (ev_is_active (w)) + return; + + ev_start ((W)w, ++preparecnt); + array_needsize (prepares, preparemax, preparecnt, ); + prepares [preparecnt - 1] = w; +} + +void evprepare_stop (struct ev_prepare *w) +{ + ev_clear ((W)w); + if (ev_is_active (w)) + return; + + prepares [w->active - 1] = prepares [--preparecnt]; + ev_stop ((W)w); +} + void evcheck_start (struct ev_check *w) { if (ev_is_active (w))