… | |
… | |
324 | /*****************************************************************************/ |
324 | /*****************************************************************************/ |
325 | |
325 | |
326 | static struct ev_idle **idles; |
326 | static struct ev_idle **idles; |
327 | static int idlemax, idlecnt; |
327 | static int idlemax, idlecnt; |
328 | |
328 | |
|
|
329 | static struct ev_prepare **prepares; |
|
|
330 | static int preparemax, preparecnt; |
|
|
331 | |
329 | static struct ev_check **checks; |
332 | static struct ev_check **checks; |
330 | static int checkmax, checkcnt; |
333 | static int checkmax, checkcnt; |
331 | |
334 | |
332 | /*****************************************************************************/ |
335 | /*****************************************************************************/ |
333 | |
336 | |
… | |
… | |
553 | void ev_loop (int flags) |
556 | void ev_loop (int flags) |
554 | { |
557 | { |
555 | double block; |
558 | double block; |
556 | ev_loop_done = flags & EVLOOP_ONESHOT ? 1 : 0; |
559 | ev_loop_done = flags & EVLOOP_ONESHOT ? 1 : 0; |
557 | |
560 | |
558 | if (checkcnt) |
|
|
559 | { |
|
|
560 | queue_events ((W *)checks, checkcnt, EV_CHECK); |
|
|
561 | call_pending (); |
|
|
562 | } |
|
|
563 | |
|
|
564 | do |
561 | do |
565 | { |
562 | { |
|
|
563 | /* queue check watchers (and execute them) */ |
|
|
564 | if (checkcnt) |
|
|
565 | { |
|
|
566 | queue_events ((W *)prepares, preparecnt, EV_PREPARE); |
|
|
567 | call_pending (); |
|
|
568 | } |
|
|
569 | |
566 | /* update fd-related kernel structures */ |
570 | /* update fd-related kernel structures */ |
567 | fd_reify (); |
571 | fd_reify (); |
568 | |
572 | |
569 | /* calculate blocking time */ |
573 | /* calculate blocking time */ |
570 | |
574 | |
… | |
… | |
596 | |
600 | |
597 | /* update ev_now, do magic */ |
601 | /* update ev_now, do magic */ |
598 | time_update (); |
602 | time_update (); |
599 | |
603 | |
600 | /* queue pending timers and reschedule them */ |
604 | /* queue pending timers and reschedule them */ |
|
|
605 | timers_reify (); /* relative timers called last */ |
601 | periodics_reify (); /* absolute timers first */ |
606 | periodics_reify (); /* absolute timers called first */ |
602 | timers_reify (); /* relative timers second */ |
|
|
603 | |
607 | |
604 | /* queue idle watchers unless io or timers are pending */ |
608 | /* queue idle watchers unless io or timers are pending */ |
605 | if (!pendingcnt) |
609 | if (!pendingcnt) |
606 | queue_events ((W *)idles, idlecnt, EV_IDLE); |
610 | queue_events ((W *)idles, idlecnt, EV_IDLE); |
607 | |
611 | |
608 | /* queue check and possibly idle watchers */ |
612 | /* queue check watchers, to be executed first */ |
|
|
613 | if (checkcnt) |
609 | queue_events ((W *)checks, checkcnt, EV_CHECK); |
614 | queue_events ((W *)checks, checkcnt, EV_CHECK); |
610 | |
615 | |
611 | call_pending (); |
616 | call_pending (); |
612 | } |
617 | } |
613 | while (!ev_loop_done); |
618 | while (!ev_loop_done); |
614 | |
619 | |
… | |
… | |
830 | ev_clear ((W)w); |
835 | ev_clear ((W)w); |
831 | if (ev_is_active (w)) |
836 | if (ev_is_active (w)) |
832 | return; |
837 | return; |
833 | |
838 | |
834 | idles [w->active - 1] = idles [--idlecnt]; |
839 | idles [w->active - 1] = idles [--idlecnt]; |
|
|
840 | ev_stop ((W)w); |
|
|
841 | } |
|
|
842 | |
|
|
843 | void evprepare_start (struct ev_prepare *w) |
|
|
844 | { |
|
|
845 | if (ev_is_active (w)) |
|
|
846 | return; |
|
|
847 | |
|
|
848 | ev_start ((W)w, ++preparecnt); |
|
|
849 | array_needsize (prepares, preparemax, preparecnt, ); |
|
|
850 | prepares [preparecnt - 1] = w; |
|
|
851 | } |
|
|
852 | |
|
|
853 | void evprepare_stop (struct ev_prepare *w) |
|
|
854 | { |
|
|
855 | ev_clear ((W)w); |
|
|
856 | if (ev_is_active (w)) |
|
|
857 | return; |
|
|
858 | |
|
|
859 | prepares [w->active - 1] = prepares [--preparecnt]; |
835 | ev_stop ((W)w); |
860 | ev_stop ((W)w); |
836 | } |
861 | } |
837 | |
862 | |
838 | void evcheck_start (struct ev_check *w) |
863 | void evcheck_start (struct ev_check *w) |
839 | { |
864 | { |