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

Comparing libev/ev.c (file contents):
Revision 1.41 by root, Fri Nov 2 16:54:34 2007 UTC vs.
Revision 1.44 by root, Fri Nov 2 20:59:14 2007 UTC

64 64
65#ifndef EV_USE_EPOLL 65#ifndef EV_USE_EPOLL
66# define EV_USE_EPOLL 0 66# define EV_USE_EPOLL 0
67#endif 67#endif
68 68
69#ifndef EV_USE_KQUEUE
70# define EV_USE_KQUEUE 0
71#endif
72
69#ifndef EV_USE_REALTIME 73#ifndef EV_USE_REALTIME
70# define EV_USE_REALTIME 1 74# define EV_USE_REALTIME 1
71#endif 75#endif
72 76
73/**/ 77/**/
99# define inline static 103# define inline static
100#endif 104#endif
101 105
102#define expect_false(expr) expect ((expr) != 0, 0) 106#define expect_false(expr) expect ((expr) != 0, 0)
103#define expect_true(expr) expect ((expr) != 0, 1) 107#define expect_true(expr) expect ((expr) != 0, 1)
108
109#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
110#define ABSPRI(w) ((w)->priority - EV_MINPRI)
104 111
105typedef struct ev_watcher *W; 112typedef struct ev_watcher *W;
106typedef struct ev_watcher_list *WL; 113typedef struct ev_watcher_list *WL;
107typedef struct ev_watcher_time *WT; 114typedef struct ev_watcher_time *WT;
108 115
193{ 200{
194 W w; 201 W w;
195 int events; 202 int events;
196} ANPENDING; 203} ANPENDING;
197 204
198static ANPENDING *pendings; 205static ANPENDING *pendings [NUMPRI];
199static int pendingmax, pendingcnt; 206static int pendingmax [NUMPRI], pendingcnt [NUMPRI];
200 207
201static void 208static void
202event (W w, int events) 209event (W w, int events)
203{ 210{
204 if (w->pending) 211 if (w->pending)
205 { 212 {
206 pendings [w->pending - 1].events |= events; 213 pendings [ABSPRI (w)][w->pending - 1].events |= events;
207 return; 214 return;
208 } 215 }
209 216
210 w->pending = ++pendingcnt; 217 w->pending = ++pendingcnt [ABSPRI (w)];
211 array_needsize (pendings, pendingmax, pendingcnt, ); 218 array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], );
212 pendings [pendingcnt - 1].w = w; 219 pendings [ABSPRI (w)][w->pending - 1].w = w;
213 pendings [pendingcnt - 1].events = events; 220 pendings [ABSPRI (w)][w->pending - 1].events = events;
214} 221}
215 222
216static void 223static void
217queue_events (W *events, int eventcnt, int type) 224queue_events (W *events, int eventcnt, int type)
218{ 225{
479 } 486 }
480} 487}
481 488
482/*****************************************************************************/ 489/*****************************************************************************/
483 490
491#if EV_USE_KQUEUE
492# include "ev_kqueue.c"
493#endif
484#if EV_USE_EPOLL 494#if EV_USE_EPOLL
485# include "ev_epoll.c" 495# include "ev_epoll.c"
486#endif 496#endif
487#if EV_USE_POLL 497#if EV_USE_POLL
488# include "ev_poll.c" 498# include "ev_poll.c"
536 methods = atoi (getenv ("LIBEV_METHODS")); 546 methods = atoi (getenv ("LIBEV_METHODS"));
537 else 547 else
538 methods = EVMETHOD_ANY; 548 methods = EVMETHOD_ANY;
539 549
540 ev_method = 0; 550 ev_method = 0;
551#if EV_USE_KQUEUE
552 if (!ev_method && (methods & EVMETHOD_KQUEUE)) kqueue_init (methods);
553#endif
541#if EV_USE_EPOLL 554#if EV_USE_EPOLL
542 if (!ev_method && (methods & EVMETHOD_EPOLL )) epoll_init (methods); 555 if (!ev_method && (methods & EVMETHOD_EPOLL )) epoll_init (methods);
543#endif 556#endif
544#if EV_USE_POLL 557#if EV_USE_POLL
545 if (!ev_method && (methods & EVMETHOD_POLL )) poll_init (methods); 558 if (!ev_method && (methods & EVMETHOD_POLL )) poll_init (methods);
593/*****************************************************************************/ 606/*****************************************************************************/
594 607
595static void 608static void
596call_pending (void) 609call_pending (void)
597{ 610{
611 int pri;
612
613 for (pri = NUMPRI; pri--; )
598 while (pendingcnt) 614 while (pendingcnt [pri])
599 { 615 {
600 ANPENDING *p = pendings + --pendingcnt; 616 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
601 617
602 if (p->w) 618 if (p->w)
603 { 619 {
604 p->w->pending = 0; 620 p->w->pending = 0;
605 p->w->cb (p->w, p->events); 621 p->w->cb (p->w, p->events);
606 } 622 }
607 } 623 }
608} 624}
609 625
610static void 626static void
611timers_reify (void) 627timers_reify (void)
612{ 628{
844static void 860static void
845ev_clear_pending (W w) 861ev_clear_pending (W w)
846{ 862{
847 if (w->pending) 863 if (w->pending)
848 { 864 {
849 pendings [w->pending - 1].w = 0; 865 pendings [ABSPRI (w)][w->pending - 1].w = 0;
850 w->pending = 0; 866 w->pending = 0;
851 } 867 }
852} 868}
853 869
854static void 870static void
855ev_start (W w, int active) 871ev_start (W w, int active)
856{ 872{
873 if (w->priority < EV_MINPRI) w->priority = EV_MINPRI;
874 if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI;
875
857 w->active = active; 876 w->active = active;
858} 877}
859 878
860static void 879static void
861ev_stop (W w) 880ev_stop (W w)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines