ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.19 by root, Wed Oct 31 17:55:55 2007 UTC vs.
Revision 1.21 by root, Wed Oct 31 18:37:38 2007 UTC

324/*****************************************************************************/ 324/*****************************************************************************/
325 325
326static struct ev_idle **idles; 326static struct ev_idle **idles;
327static int idlemax, idlecnt; 327static int idlemax, idlecnt;
328 328
329static struct ev_prepare **prepares;
330static int preparemax, preparecnt;
331
329static struct ev_check **checks; 332static struct ev_check **checks;
330static int checkmax, checkcnt; 333static int checkmax, checkcnt;
331 334
332/*****************************************************************************/ 335/*****************************************************************************/
333 336
553void ev_loop (int flags) 556void 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
844void 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
854void 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
838void evcheck_start (struct ev_check *w) 864void evcheck_start (struct ev_check *w)
839{ 865{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines