… | |
… | |
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 | |
105 | typedef struct ev_watcher *W; |
112 | typedef struct ev_watcher *W; |
106 | typedef struct ev_watcher_list *WL; |
113 | typedef struct ev_watcher_list *WL; |
107 | typedef struct ev_watcher_time *WT; |
114 | typedef 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 | |
198 | static ANPENDING *pendings; |
205 | static ANPENDING *pendings [NUMPRI]; |
199 | static int pendingmax, pendingcnt; |
206 | static int pendingmax [NUMPRI], pendingcnt [NUMPRI]; |
200 | |
207 | |
201 | static void |
208 | static void |
202 | event (W w, int events) |
209 | event (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 | |
216 | static void |
223 | static void |
217 | queue_events (W *events, int eventcnt, int type) |
224 | queue_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 | |
595 | static void |
608 | static void |
596 | call_pending (void) |
609 | call_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 | |
610 | static void |
626 | static void |
611 | timers_reify (void) |
627 | timers_reify (void) |
612 | { |
628 | { |
… | |
… | |
844 | static void |
860 | static void |
845 | ev_clear_pending (W w) |
861 | ev_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 | |
854 | static void |
870 | static void |
855 | ev_start (W w, int active) |
871 | ev_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 | |
860 | static void |
879 | static void |
861 | ev_stop (W w) |
880 | ev_stop (W w) |