… | |
… | |
113 | |
113 | |
114 | typedef struct ev_watcher *W; |
114 | typedef struct ev_watcher *W; |
115 | typedef struct ev_watcher_list *WL; |
115 | typedef struct ev_watcher_list *WL; |
116 | typedef struct ev_watcher_time *WT; |
116 | typedef struct ev_watcher_time *WT; |
117 | |
117 | |
118 | static ev_tstamp now_floor, mn_now, diff; /* monotonic clock */ |
118 | /*****************************************************************************/ |
119 | static ev_tstamp rt_now; |
|
|
120 | static int method; |
|
|
121 | |
119 | |
122 | static int have_monotonic; /* runtime */ |
120 | typedef struct |
|
|
121 | { |
|
|
122 | struct ev_watcher_list *head; |
|
|
123 | unsigned char events; |
|
|
124 | unsigned char reify; |
|
|
125 | } ANFD; |
123 | |
126 | |
124 | static ev_tstamp method_fudge; /* stupid epoll-returns-early bug */ |
127 | typedef struct |
125 | static void (*method_modify)(EV_P_ int fd, int oev, int nev); |
128 | { |
126 | static void (*method_poll)(EV_P_ ev_tstamp timeout); |
129 | W w; |
|
|
130 | int events; |
|
|
131 | } ANPENDING; |
127 | |
132 | |
128 | static int activecnt; /* number of active events */ |
133 | #ifdef EV_MULTIPLICITY |
129 | |
134 | struct ev_loop |
130 | #if EV_USE_SELECT |
135 | { |
131 | static unsigned char *vec_ri, *vec_ro, *vec_wi, *vec_wo; |
136 | # define VAR(name,decl) decl |
132 | static int vec_max; |
137 | # include "ev_vars.h" |
|
|
138 | }; |
|
|
139 | #else |
|
|
140 | # define VAR(name,decl) static decl |
|
|
141 | # include "ev_vars.h" |
133 | #endif |
142 | #endif |
134 | |
143 | #undef VAR |
135 | #if EV_USEV_POLL |
|
|
136 | static struct pollfd *polls; |
|
|
137 | static int pollmax, pollcnt; |
|
|
138 | static int *pollidxs; /* maps fds into structure indices */ |
|
|
139 | static int pollidxmax; |
|
|
140 | #endif |
|
|
141 | |
|
|
142 | #if EV_USE_EPOLL |
|
|
143 | static int epoll_fd = -1; |
|
|
144 | |
|
|
145 | static struct epoll_event *events; |
|
|
146 | static int eventmax; |
|
|
147 | #endif |
|
|
148 | |
|
|
149 | #if EV_USE_KQUEUE |
|
|
150 | static int kqueue_fd; |
|
|
151 | static struct kevent *kqueue_changes; |
|
|
152 | static int kqueue_changemax, kqueue_changecnt; |
|
|
153 | static struct kevent *kqueue_events; |
|
|
154 | static int kqueue_eventmax; |
|
|
155 | #endif |
|
|
156 | |
144 | |
157 | /*****************************************************************************/ |
145 | /*****************************************************************************/ |
158 | |
146 | |
159 | inline ev_tstamp |
147 | inline ev_tstamp |
160 | ev_time (void) |
148 | ev_time (void) |
… | |
… | |
208 | cur = newcnt; \ |
196 | cur = newcnt; \ |
209 | } |
197 | } |
210 | |
198 | |
211 | /*****************************************************************************/ |
199 | /*****************************************************************************/ |
212 | |
200 | |
213 | typedef struct |
|
|
214 | { |
|
|
215 | struct ev_watcher_list *head; |
|
|
216 | unsigned char events; |
|
|
217 | unsigned char reify; |
|
|
218 | } ANFD; |
|
|
219 | |
|
|
220 | static ANFD *anfds; |
|
|
221 | static int anfdmax; |
|
|
222 | |
|
|
223 | static void |
201 | static void |
224 | anfds_init (ANFD *base, int count) |
202 | anfds_init (ANFD *base, int count) |
225 | { |
203 | { |
226 | while (count--) |
204 | while (count--) |
227 | { |
205 | { |
… | |
… | |
230 | base->reify = 0; |
208 | base->reify = 0; |
231 | |
209 | |
232 | ++base; |
210 | ++base; |
233 | } |
211 | } |
234 | } |
212 | } |
235 | |
|
|
236 | typedef struct |
|
|
237 | { |
|
|
238 | W w; |
|
|
239 | int events; |
|
|
240 | } ANPENDING; |
|
|
241 | |
|
|
242 | static ANPENDING *pendings [NUMPRI]; |
|
|
243 | static int pendingmax [NUMPRI], pendingcnt [NUMPRI]; |
|
|
244 | |
213 | |
245 | static void |
214 | static void |
246 | event (EV_P_ W w, int events) |
215 | event (EV_P_ W w, int events) |
247 | { |
216 | { |
248 | if (w->pending) |
217 | if (w->pending) |
… | |
… | |
280 | event (EV_A_ (W)w, ev); |
249 | event (EV_A_ (W)w, ev); |
281 | } |
250 | } |
282 | } |
251 | } |
283 | |
252 | |
284 | /*****************************************************************************/ |
253 | /*****************************************************************************/ |
285 | |
|
|
286 | static int *fdchanges; |
|
|
287 | static int fdchangemax, fdchangecnt; |
|
|
288 | |
254 | |
289 | static void |
255 | static void |
290 | fd_reify (EV_P) |
256 | fd_reify (EV_P) |
291 | { |
257 | { |
292 | int i; |
258 | int i; |
… | |
… | |
366 | } |
332 | } |
367 | } |
333 | } |
368 | |
334 | |
369 | /*****************************************************************************/ |
335 | /*****************************************************************************/ |
370 | |
336 | |
371 | static struct ev_timer **timers; |
|
|
372 | static int timermax, timercnt; |
|
|
373 | |
|
|
374 | static struct ev_periodic **periodics; |
|
|
375 | static int periodicmax, periodiccnt; |
|
|
376 | |
|
|
377 | static void |
337 | static void |
378 | upheap (WT *timers, int k) |
338 | upheap (WT *timers, int k) |
379 | { |
339 | { |
380 | WT w = timers [k]; |
340 | WT w = timers [k]; |
381 | |
341 | |
… | |
… | |
426 | static ANSIG *signals; |
386 | static ANSIG *signals; |
427 | static int signalmax; |
387 | static int signalmax; |
428 | |
388 | |
429 | static int sigpipe [2]; |
389 | static int sigpipe [2]; |
430 | static sig_atomic_t volatile gotsig; |
390 | static sig_atomic_t volatile gotsig; |
431 | static struct ev_io sigev; |
|
|
432 | |
391 | |
433 | static void |
392 | static void |
434 | signals_init (ANSIG *base, int count) |
393 | signals_init (ANSIG *base, int count) |
435 | { |
394 | { |
436 | while (count--) |
395 | while (count--) |
… | |
… | |
491 | ev_io_start (&sigev); |
450 | ev_io_start (&sigev); |
492 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
451 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
493 | } |
452 | } |
494 | |
453 | |
495 | /*****************************************************************************/ |
454 | /*****************************************************************************/ |
496 | |
|
|
497 | static struct ev_idle **idles; |
|
|
498 | static int idlemax, idlecnt; |
|
|
499 | |
|
|
500 | static struct ev_prepare **prepares; |
|
|
501 | static int preparemax, preparecnt; |
|
|
502 | |
|
|
503 | static struct ev_check **checks; |
|
|
504 | static int checkmax, checkcnt; |
|
|
505 | |
|
|
506 | /*****************************************************************************/ |
|
|
507 | |
|
|
508 | static struct ev_child *childs [PID_HASHSIZE]; |
|
|
509 | static struct ev_signal childev; |
|
|
510 | |
455 | |
511 | #ifndef WIN32 |
456 | #ifndef WIN32 |
512 | |
457 | |
513 | #ifndef WCONTINUED |
458 | #ifndef WCONTINUED |
514 | # define WCONTINUED 0 |
459 | # define WCONTINUED 0 |
… | |
… | |
592 | } |
537 | } |
593 | |
538 | |
594 | int |
539 | int |
595 | ev_init (EV_P_ int methods) |
540 | ev_init (EV_P_ int methods) |
596 | { |
541 | { |
|
|
542 | #ifdef EV_MULTIPLICITY |
|
|
543 | memset (loop, 0, sizeof (struct ev_loop)); |
|
|
544 | #endif |
|
|
545 | |
597 | if (!method) |
546 | if (!method) |
598 | { |
547 | { |
599 | #if EV_USE_MONOTONIC |
548 | #if EV_USE_MONOTONIC |
600 | { |
549 | { |
601 | struct timespec ts; |
550 | struct timespec ts; |