… | |
… | |
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--) |
… | |
… | |
487 | fcntl (sigpipe [1], F_SETFL, O_NONBLOCK); |
446 | fcntl (sigpipe [1], F_SETFL, O_NONBLOCK); |
488 | #endif |
447 | #endif |
489 | |
448 | |
490 | ev_io_set (&sigev, sigpipe [0], EV_READ); |
449 | ev_io_set (&sigev, sigpipe [0], EV_READ); |
491 | ev_io_start (&sigev); |
450 | ev_io_start (&sigev); |
|
|
451 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
492 | } |
452 | } |
493 | |
453 | |
494 | /*****************************************************************************/ |
454 | /*****************************************************************************/ |
495 | |
|
|
496 | static struct ev_idle **idles; |
|
|
497 | static int idlemax, idlecnt; |
|
|
498 | |
|
|
499 | static struct ev_prepare **prepares; |
|
|
500 | static int preparemax, preparecnt; |
|
|
501 | |
|
|
502 | static struct ev_check **checks; |
|
|
503 | static int checkmax, checkcnt; |
|
|
504 | |
|
|
505 | /*****************************************************************************/ |
|
|
506 | |
|
|
507 | static struct ev_child *childs [PID_HASHSIZE]; |
|
|
508 | static struct ev_signal childev; |
|
|
509 | |
455 | |
510 | #ifndef WIN32 |
456 | #ifndef WIN32 |
511 | |
457 | |
512 | #ifndef WCONTINUED |
458 | #ifndef WCONTINUED |
513 | # define WCONTINUED 0 |
459 | # define WCONTINUED 0 |
… | |
… | |
591 | } |
537 | } |
592 | |
538 | |
593 | int |
539 | int |
594 | ev_init (EV_P_ int methods) |
540 | ev_init (EV_P_ int methods) |
595 | { |
541 | { |
|
|
542 | #ifdef EV_MULTIPLICITY |
|
|
543 | memset (loop, 0, sizeof (struct ev_loop)); |
|
|
544 | #endif |
|
|
545 | |
596 | if (!method) |
546 | if (!method) |
597 | { |
547 | { |
598 | #if EV_USE_MONOTONIC |
548 | #if EV_USE_MONOTONIC |
599 | { |
549 | { |
600 | struct timespec ts; |
550 | struct timespec ts; |
… | |
… | |
639 | |
589 | |
640 | #ifndef WIN32 |
590 | #ifndef WIN32 |
641 | ev_signal_init (&childev, childcb, SIGCHLD); |
591 | ev_signal_init (&childev, childcb, SIGCHLD); |
642 | ev_set_priority (&childev, EV_MAXPRI); |
592 | ev_set_priority (&childev, EV_MAXPRI); |
643 | ev_signal_start (EV_A_ &childev); |
593 | ev_signal_start (EV_A_ &childev); |
|
|
594 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
644 | #endif |
595 | #endif |
645 | } |
596 | } |
646 | } |
597 | } |
647 | |
598 | |
648 | return method; |
599 | return method; |
… | |
… | |
911 | /* queue check watchers, to be executed first */ |
862 | /* queue check watchers, to be executed first */ |
912 | if (checkcnt) |
863 | if (checkcnt) |
913 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
864 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
914 | |
865 | |
915 | call_pending (EV_A); |
866 | call_pending (EV_A); |
916 | printf ("activecnt %d\n", activecnt);//D |
|
|
917 | } |
867 | } |
918 | while (activecnt && !loop_done); |
868 | while (activecnt && !loop_done); |
919 | |
869 | |
920 | if (loop_done != 2) |
870 | if (loop_done != 2) |
921 | loop_done = 0; |
871 | loop_done = 0; |