… | |
… | |
113 | #endif |
113 | #endif |
114 | |
114 | |
115 | return ev_time (); |
115 | return ev_time (); |
116 | } |
116 | } |
117 | |
117 | |
118 | #define array_nextsize(n) (((n) << 1) | 4 & ~3) |
118 | #define array_roundsize(base,n) ((n) | 4 & ~3) |
119 | #define array_prevsize(n) (((n) >> 1) | 4 & ~3) |
|
|
120 | |
119 | |
121 | #define array_needsize(base,cur,cnt,init) \ |
120 | #define array_needsize(base,cur,cnt,init) \ |
122 | if ((cnt) > cur) \ |
121 | if ((cnt) > cur) \ |
123 | { \ |
122 | { \ |
124 | int newcnt = cur; \ |
123 | int newcnt = cur; \ |
125 | do \ |
124 | do \ |
126 | { \ |
125 | { \ |
127 | newcnt = array_nextsize (newcnt); \ |
126 | newcnt = array_roundsize (base, newcnt << 1); \ |
128 | } \ |
127 | } \ |
129 | while ((cnt) > newcnt); \ |
128 | while ((cnt) > newcnt); \ |
130 | \ |
129 | \ |
131 | base = realloc (base, sizeof (*base) * (newcnt)); \ |
130 | base = realloc (base, sizeof (*base) * (newcnt)); \ |
132 | init (base + cur, newcnt - cur); \ |
131 | init (base + cur, newcnt - cur); \ |
… | |
… | |
165 | static int pendingmax, pendingcnt; |
164 | static int pendingmax, pendingcnt; |
166 | |
165 | |
167 | static void |
166 | static void |
168 | event (W w, int events) |
167 | event (W w, int events) |
169 | { |
168 | { |
170 | if (w->active) |
|
|
171 | { |
|
|
172 | w->pending = ++pendingcnt; |
169 | w->pending = ++pendingcnt; |
173 | array_needsize (pendings, pendingmax, pendingcnt, ); |
170 | array_needsize (pendings, pendingmax, pendingcnt, ); |
174 | pendings [pendingcnt - 1].w = w; |
171 | pendings [pendingcnt - 1].w = w; |
175 | pendings [pendingcnt - 1].events = events; |
172 | pendings [pendingcnt - 1].events = events; |
176 | } |
|
|
177 | } |
173 | } |
178 | |
174 | |
179 | static void |
175 | static void |
180 | queue_events (W *events, int eventcnt, int type) |
176 | queue_events (W *events, int eventcnt, int type) |
181 | { |
177 | { |
… | |
… | |
529 | { |
525 | { |
530 | while (timercnt && timers [0]->at <= now) |
526 | while (timercnt && timers [0]->at <= now) |
531 | { |
527 | { |
532 | struct ev_timer *w = timers [0]; |
528 | struct ev_timer *w = timers [0]; |
533 | |
529 | |
534 | event ((W)w, EV_TIMEOUT); |
|
|
535 | |
|
|
536 | /* first reschedule or stop timer */ |
530 | /* first reschedule or stop timer */ |
537 | if (w->repeat) |
531 | if (w->repeat) |
538 | { |
532 | { |
539 | w->at = now + w->repeat; |
533 | w->at = now + w->repeat; |
540 | assert (("timer timeout in the past, negative repeat?", w->at > now)); |
534 | assert (("timer timeout in the past, negative repeat?", w->at > now)); |
541 | downheap ((WT *)timers, timercnt, 0); |
535 | downheap ((WT *)timers, timercnt, 0); |
542 | } |
536 | } |
543 | else |
537 | else |
544 | ev_timer_stop (w); /* nonrepeating: stop timer */ |
538 | ev_timer_stop (w); /* nonrepeating: stop timer */ |
|
|
539 | |
|
|
540 | event ((W)w, EV_TIMEOUT); |
545 | } |
541 | } |
546 | } |
542 | } |
547 | |
543 | |
548 | static void |
544 | static void |
549 | periodics_reify (void) |
545 | periodics_reify (void) |