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

Comparing libev/ev.c (file contents):
Revision 1.18 by root, Wed Oct 31 16:29:52 2007 UTC vs.
Revision 1.21 by root, Wed Oct 31 18:37:38 2007 UTC

39#include <assert.h> 39#include <assert.h>
40#include <errno.h> 40#include <errno.h>
41#include <sys/time.h> 41#include <sys/time.h>
42#include <time.h> 42#include <time.h>
43 43
44#define HAVE_EPOLL 1
45
46#ifndef HAVE_MONOTONIC 44#ifndef HAVE_MONOTONIC
47# ifdef CLOCK_MONOTONIC 45# ifdef CLOCK_MONOTONIC
48# define HAVE_MONOTONIC 1 46# define HAVE_MONOTONIC 1
49# endif 47# endif
50#endif 48#endif
188 186
189 for (i = 0; i < eventcnt; ++i) 187 for (i = 0; i < eventcnt; ++i)
190 event (events [i], type); 188 event (events [i], type);
191} 189}
192 190
191/* called on EBADF to verify fds */
192static void
193fd_recheck ()
194{
195 int fd;
196
197 for (fd = 0; fd < anfdmax; ++fd)
198 if (anfds [fd].wev)
199 if (fcntl (fd, F_GETFD) == -1 && errno == EBADF)
200 while (anfds [fd].head)
201 evio_stop (anfds [fd].head);
202}
203
193/*****************************************************************************/ 204/*****************************************************************************/
194 205
195static struct ev_timer **timers; 206static struct ev_timer **timers;
196static int timermax, timercnt; 207static int timermax, timercnt;
197 208
312 323
313/*****************************************************************************/ 324/*****************************************************************************/
314 325
315static struct ev_idle **idles; 326static struct ev_idle **idles;
316static int idlemax, idlecnt; 327static int idlemax, idlecnt;
328
329static struct ev_prepare **prepares;
330static int preparemax, preparecnt;
317 331
318static struct ev_check **checks; 332static struct ev_check **checks;
319static int checkmax, checkcnt; 333static int checkmax, checkcnt;
320 334
321/*****************************************************************************/ 335/*****************************************************************************/
542void ev_loop (int flags) 556void ev_loop (int flags)
543{ 557{
544 double block; 558 double block;
545 ev_loop_done = flags & EVLOOP_ONESHOT ? 1 : 0; 559 ev_loop_done = flags & EVLOOP_ONESHOT ? 1 : 0;
546 560
547 if (checkcnt)
548 {
549 queue_events ((W *)checks, checkcnt, EV_CHECK);
550 call_pending ();
551 }
552
553 do 561 do
554 { 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
555 /* update fd-related kernel structures */ 570 /* update fd-related kernel structures */
556 fd_reify (); 571 fd_reify ();
557 572
558 /* calculate blocking time */ 573 /* calculate blocking time */
559 574
560 /* 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 */
561 ev_now = ev_time (); 577 ev_now = ev_time ();
562 578
563 if (flags & EVLOOP_NONBLOCK || idlecnt) 579 if (flags & EVLOOP_NONBLOCK || idlecnt)
564 block = 0.; 580 block = 0.;
565 else 581 else
585 601
586 /* update ev_now, do magic */ 602 /* update ev_now, do magic */
587 time_update (); 603 time_update ();
588 604
589 /* queue pending timers and reschedule them */ 605 /* queue pending timers and reschedule them */
606 timers_reify (); /* relative timers called last */
590 periodics_reify (); /* absolute timers first */ 607 periodics_reify (); /* absolute timers called first */
591 timers_reify (); /* relative timers second */
592 608
593 /* queue idle watchers unless io or timers are pending */ 609 /* queue idle watchers unless io or timers are pending */
594 if (!pendingcnt) 610 if (!pendingcnt)
595 queue_events ((W *)idles, idlecnt, EV_IDLE); 611 queue_events ((W *)idles, idlecnt, EV_IDLE);
596 612
597 /* queue check and possibly idle watchers */ 613 /* queue check watchers, to be executed first */
614 if (checkcnt)
598 queue_events ((W *)checks, checkcnt, EV_CHECK); 615 queue_events ((W *)checks, checkcnt, EV_CHECK);
599 616
600 call_pending (); 617 call_pending ();
601 } 618 }
602 while (!ev_loop_done); 619 while (!ev_loop_done);
603 620
819 ev_clear ((W)w); 836 ev_clear ((W)w);
820 if (ev_is_active (w)) 837 if (ev_is_active (w))
821 return; 838 return;
822 839
823 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];
824 ev_stop ((W)w); 861 ev_stop ((W)w);
825} 862}
826 863
827void evcheck_start (struct ev_check *w) 864void evcheck_start (struct ev_check *w)
828{ 865{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines