… | |
… | |
100 | #endif |
100 | #endif |
101 | |
101 | |
102 | #define expect_false(expr) expect ((expr) != 0, 0) |
102 | #define expect_false(expr) expect ((expr) != 0, 0) |
103 | #define expect_true(expr) expect ((expr) != 0, 1) |
103 | #define expect_true(expr) expect ((expr) != 0, 1) |
104 | |
104 | |
|
|
105 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
|
|
106 | #define ABSPRI(w) ((w)->priority - EV_MINPRI) |
|
|
107 | |
105 | typedef struct ev_watcher *W; |
108 | typedef struct ev_watcher *W; |
106 | typedef struct ev_watcher_list *WL; |
109 | typedef struct ev_watcher_list *WL; |
107 | typedef struct ev_watcher_time *WT; |
110 | typedef struct ev_watcher_time *WT; |
108 | |
111 | |
109 | static ev_tstamp now_floor, now, diff; /* monotonic clock */ |
112 | static ev_tstamp now_floor, now, diff; /* monotonic clock */ |
… | |
… | |
193 | { |
196 | { |
194 | W w; |
197 | W w; |
195 | int events; |
198 | int events; |
196 | } ANPENDING; |
199 | } ANPENDING; |
197 | |
200 | |
198 | static ANPENDING *pendings; |
201 | static ANPENDING *pendings [NUMPRI]; |
199 | static int pendingmax, pendingcnt; |
202 | static int pendingmax [NUMPRI], pendingcnt [NUMPRI]; |
200 | |
203 | |
201 | static void |
204 | static void |
202 | event (W w, int events) |
205 | event (W w, int events) |
203 | { |
206 | { |
204 | if (w->pending) |
207 | if (w->pending) |
205 | { |
208 | { |
206 | pendings [w->pending - 1].events |= events; |
209 | pendings [ABSPRI (w)][w->pending - 1].events |= events; |
207 | return; |
210 | return; |
208 | } |
211 | } |
209 | |
212 | |
210 | w->pending = ++pendingcnt; |
213 | w->pending = ++pendingcnt [ABSPRI (w)]; |
211 | array_needsize (pendings, pendingmax, pendingcnt, ); |
214 | array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], ); |
212 | pendings [pendingcnt - 1].w = w; |
215 | pendings [ABSPRI (w)][w->pending - 1].w = w; |
213 | pendings [pendingcnt - 1].events = events; |
216 | pendings [ABSPRI (w)][w->pending - 1].events = events; |
214 | } |
217 | } |
215 | |
218 | |
216 | static void |
219 | static void |
217 | queue_events (W *events, int eventcnt, int type) |
220 | queue_events (W *events, int eventcnt, int type) |
218 | { |
221 | { |
… | |
… | |
593 | /*****************************************************************************/ |
596 | /*****************************************************************************/ |
594 | |
597 | |
595 | static void |
598 | static void |
596 | call_pending (void) |
599 | call_pending (void) |
597 | { |
600 | { |
|
|
601 | int pri; |
|
|
602 | |
|
|
603 | for (pri = NUMPRI; pri--; ) |
598 | while (pendingcnt) |
604 | while (pendingcnt [pri]) |
599 | { |
605 | { |
600 | ANPENDING *p = pendings + --pendingcnt; |
606 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
601 | |
607 | |
602 | if (p->w) |
608 | if (p->w) |
603 | { |
609 | { |
604 | p->w->pending = 0; |
610 | p->w->pending = 0; |
605 | p->w->cb (p->w, p->events); |
611 | p->w->cb (p->w, p->events); |
606 | } |
612 | } |
607 | } |
613 | } |
608 | } |
614 | } |
609 | |
615 | |
610 | static void |
616 | static void |
611 | timers_reify (void) |
617 | timers_reify (void) |
612 | { |
618 | { |
… | |
… | |
844 | static void |
850 | static void |
845 | ev_clear_pending (W w) |
851 | ev_clear_pending (W w) |
846 | { |
852 | { |
847 | if (w->pending) |
853 | if (w->pending) |
848 | { |
854 | { |
849 | pendings [w->pending - 1].w = 0; |
855 | pendings [ABSPRI (w)][w->pending - 1].w = 0; |
850 | w->pending = 0; |
856 | w->pending = 0; |
851 | } |
857 | } |
852 | } |
858 | } |
853 | |
859 | |
854 | static void |
860 | static void |