… | |
… | |
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 (preparecnt) |
|
|
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 | |
571 | /* we only need this for !monotonic clock, but as we always have timers, we just calculate it every time */ |
575 | /* we only need this for !monotonic clockor timers, but as we basically |
|
|
576 | always have timers, we just calculate it always */ |
572 | ev_now = ev_time (); |
577 | ev_now = ev_time (); |
573 | |
578 | |
574 | if (flags & EVLOOP_NONBLOCK || idlecnt) |
579 | if (flags & EVLOOP_NONBLOCK || idlecnt) |
575 | block = 0.; |
580 | block = 0.; |
576 | else |
581 | else |
… | |
… | |
596 | |
601 | |
597 | /* update ev_now, do magic */ |
602 | /* update ev_now, do magic */ |
598 | time_update (); |
603 | time_update (); |
599 | |
604 | |
600 | /* queue pending timers and reschedule them */ |
605 | /* queue pending timers and reschedule them */ |
|
|
606 | timers_reify (); /* relative timers called last */ |
601 | periodics_reify (); /* absolute timers first */ |
607 | periodics_reify (); /* absolute timers called first */ |
602 | timers_reify (); /* relative timers second */ |
|
|
603 | |
608 | |
604 | /* queue idle watchers unless io or timers are pending */ |
609 | /* queue idle watchers unless io or timers are pending */ |
605 | if (!pendingcnt) |
610 | if (!pendingcnt) |
606 | queue_events ((W *)idles, idlecnt, EV_IDLE); |
611 | queue_events ((W *)idles, idlecnt, EV_IDLE); |
607 | |
612 | |
608 | /* queue check and possibly idle watchers */ |
613 | /* queue check watchers, to be executed first */ |
|
|
614 | if (checkcnt) |
609 | queue_events ((W *)checks, checkcnt, EV_CHECK); |
615 | queue_events ((W *)checks, checkcnt, EV_CHECK); |
610 | |
616 | |
611 | call_pending (); |
617 | call_pending (); |
612 | } |
618 | } |
613 | while (!ev_loop_done); |
619 | while (!ev_loop_done); |
614 | |
620 | |
… | |
… | |
830 | ev_clear ((W)w); |
836 | ev_clear ((W)w); |
831 | if (ev_is_active (w)) |
837 | if (ev_is_active (w)) |
832 | return; |
838 | return; |
833 | |
839 | |
834 | idles [w->active - 1] = idles [--idlecnt]; |
840 | idles [w->active - 1] = idles [--idlecnt]; |
|
|
841 | ev_stop ((W)w); |
|
|
842 | } |
|
|
843 | |
|
|
844 | void evprepare_start (struct ev_prepare *w) |
|
|
845 | { |
|
|
846 | if (ev_is_active (w)) |
|
|
847 | return; |
|
|
848 | |
|
|
849 | ev_start ((W)w, ++preparecnt); |
|
|
850 | array_needsize (prepares, preparemax, preparecnt, ); |
|
|
851 | prepares [preparecnt - 1] = w; |
|
|
852 | } |
|
|
853 | |
|
|
854 | void evprepare_stop (struct ev_prepare *w) |
|
|
855 | { |
|
|
856 | ev_clear ((W)w); |
|
|
857 | if (ev_is_active (w)) |
|
|
858 | return; |
|
|
859 | |
|
|
860 | prepares [w->active - 1] = prepares [--preparecnt]; |
835 | ev_stop ((W)w); |
861 | ev_stop ((W)w); |
836 | } |
862 | } |
837 | |
863 | |
838 | void evcheck_start (struct ev_check *w) |
864 | void evcheck_start (struct ev_check *w) |
839 | { |
865 | { |