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

Comparing libev/ev.c (file contents):
Revision 1.17 by root, Wed Oct 31 14:44:15 2007 UTC vs.
Revision 1.20 by root, Wed Oct 31 18:28:00 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/*****************************************************************************/
416} 430}
417 431
418static void 432static void
419call_pending () 433call_pending ()
420{ 434{
421 int i; 435 while (pendingcnt)
422
423 for (i = 0; i < pendingcnt; ++i)
424 { 436 {
425 ANPENDING *p = pendings + i; 437 ANPENDING *p = pendings + --pendingcnt;
426 438
427 if (p->w) 439 if (p->w)
428 { 440 {
429 p->w->pending = 0; 441 p->w->pending = 0;
430 p->w->cb (p->w, p->events); 442 p->w->cb (p->w, p->events);
431 } 443 }
432 } 444 }
433
434 pendingcnt = 0;
435} 445}
436 446
437static void 447static void
438timers_reify () 448timers_reify ()
439{ 449{
546void ev_loop (int flags) 556void ev_loop (int flags)
547{ 557{
548 double block; 558 double block;
549 ev_loop_done = flags & EVLOOP_ONESHOT ? 1 : 0; 559 ev_loop_done = flags & EVLOOP_ONESHOT ? 1 : 0;
550 560
551 if (checkcnt)
552 {
553 queue_events ((W *)checks, checkcnt, EV_CHECK);
554 call_pending ();
555 }
556
557 do 561 do
558 { 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
559 /* update fd-related kernel structures */ 570 /* update fd-related kernel structures */
560 fd_reify (); 571 fd_reify ();
561 572
562 /* calculate blocking time */ 573 /* calculate blocking time */
563 574
589 600
590 /* update ev_now, do magic */ 601 /* update ev_now, do magic */
591 time_update (); 602 time_update ();
592 603
593 /* queue pending timers and reschedule them */ 604 /* queue pending timers and reschedule them */
605 timers_reify (); /* relative timers called last */
594 periodics_reify (); /* absolute timers first */ 606 periodics_reify (); /* absolute timers called first */
595 timers_reify (); /* relative timers second */
596 607
597 /* queue idle watchers unless io or timers are pending */ 608 /* queue idle watchers unless io or timers are pending */
598 if (!pendingcnt) 609 if (!pendingcnt)
599 queue_events ((W *)idles, idlecnt, EV_IDLE); 610 queue_events ((W *)idles, idlecnt, EV_IDLE);
600 611
601 /* queue check and possibly idle watchers */ 612 /* queue check watchers, to be executed first */
613 if (checkcnt)
602 queue_events ((W *)checks, checkcnt, EV_CHECK); 614 queue_events ((W *)checks, checkcnt, EV_CHECK);
603 615
604 call_pending (); 616 call_pending ();
605 } 617 }
606 while (!ev_loop_done); 618 while (!ev_loop_done);
607 619
823 ev_clear ((W)w); 835 ev_clear ((W)w);
824 if (ev_is_active (w)) 836 if (ev_is_active (w))
825 return; 837 return;
826 838
827 idles [w->active - 1] = idles [--idlecnt]; 839 idles [w->active - 1] = idles [--idlecnt];
840 ev_stop ((W)w);
841}
842
843void 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
853void 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];
828 ev_stop ((W)w); 860 ev_stop ((W)w);
829} 861}
830 862
831void evcheck_start (struct ev_check *w) 863void evcheck_start (struct ev_check *w)
832{ 864{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines