… | |
… | |
79 | # endif |
79 | # endif |
80 | # endif |
80 | # endif |
81 | |
81 | |
82 | # ifndef EV_USE_NANOSLEEP |
82 | # ifndef EV_USE_NANOSLEEP |
83 | # if HAVE_NANOSLEEP |
83 | # if HAVE_NANOSLEEP |
84 | # define EV_USE_NANOSLEEP 1 |
84 | # define EV_USE_NANOSLEEP EV_FEATURE_OS |
85 | # else |
85 | # else |
86 | # define EV_USE_NANOSLEEP 0 |
86 | # define EV_USE_NANOSLEEP 0 |
87 | # endif |
87 | # endif |
88 | # endif |
88 | # endif |
89 | |
89 | |
90 | # ifndef EV_USE_SELECT |
90 | # ifndef EV_USE_SELECT |
91 | # if HAVE_SELECT && HAVE_SYS_SELECT_H |
91 | # if HAVE_SELECT && HAVE_SYS_SELECT_H |
92 | # define EV_USE_SELECT 1 |
92 | # define EV_USE_SELECT EV_FEATURE_BACKENDS |
93 | # else |
93 | # else |
94 | # define EV_USE_SELECT 0 |
94 | # define EV_USE_SELECT 0 |
95 | # endif |
95 | # endif |
96 | # endif |
96 | # endif |
97 | |
97 | |
98 | # ifndef EV_USE_POLL |
98 | # ifndef EV_USE_POLL |
99 | # if HAVE_POLL && HAVE_POLL_H |
99 | # if HAVE_POLL && HAVE_POLL_H |
100 | # define EV_USE_POLL 1 |
100 | # define EV_USE_POLL EV_FEATURE_BACKENDS |
101 | # else |
101 | # else |
102 | # define EV_USE_POLL 0 |
102 | # define EV_USE_POLL 0 |
103 | # endif |
103 | # endif |
104 | # endif |
104 | # endif |
105 | |
105 | |
106 | # ifndef EV_USE_EPOLL |
106 | # ifndef EV_USE_EPOLL |
107 | # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H |
107 | # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H |
108 | # define EV_USE_EPOLL 1 |
108 | # define EV_USE_EPOLL EV_FEATURE_BACKENDS |
109 | # else |
109 | # else |
110 | # define EV_USE_EPOLL 0 |
110 | # define EV_USE_EPOLL 0 |
111 | # endif |
111 | # endif |
112 | # endif |
112 | # endif |
113 | |
113 | |
114 | # ifndef EV_USE_KQUEUE |
114 | # ifndef EV_USE_KQUEUE |
115 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
115 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
116 | # define EV_USE_KQUEUE 1 |
116 | # define EV_USE_KQUEUE EV_FEATURE_BACKENDS |
117 | # else |
117 | # else |
118 | # define EV_USE_KQUEUE 0 |
118 | # define EV_USE_KQUEUE 0 |
119 | # endif |
119 | # endif |
120 | # endif |
120 | # endif |
121 | |
121 | |
122 | # ifndef EV_USE_PORT |
122 | # ifndef EV_USE_PORT |
123 | # if HAVE_PORT_H && HAVE_PORT_CREATE |
123 | # if HAVE_PORT_H && HAVE_PORT_CREATE |
124 | # define EV_USE_PORT 1 |
124 | # define EV_USE_PORT EV_FEATURE_BACKENDS |
125 | # else |
125 | # else |
126 | # define EV_USE_PORT 0 |
126 | # define EV_USE_PORT 0 |
127 | # endif |
127 | # endif |
128 | # endif |
128 | # endif |
129 | |
129 | |
130 | # ifndef EV_USE_INOTIFY |
130 | # ifndef EV_USE_INOTIFY |
131 | # if HAVE_INOTIFY_INIT && HAVE_SYS_INOTIFY_H |
131 | # if HAVE_INOTIFY_INIT && HAVE_SYS_INOTIFY_H |
132 | # define EV_USE_INOTIFY 1 |
132 | # define EV_USE_INOTIFY EV_FEATURE_OS |
133 | # else |
133 | # else |
134 | # define EV_USE_INOTIFY 0 |
134 | # define EV_USE_INOTIFY 0 |
135 | # endif |
135 | # endif |
136 | # endif |
136 | # endif |
137 | |
137 | |
138 | # ifndef EV_USE_SIGNALFD |
138 | # ifndef EV_USE_SIGNALFD |
139 | # if HAVE_SIGNALFD && HAVE_SYS_SIGNALFD_H |
139 | # if HAVE_SIGNALFD && HAVE_SYS_SIGNALFD_H |
140 | # define EV_USE_SIGNALFD 1 |
140 | # define EV_USE_SIGNALFD EV_FEATURE_OS |
141 | # else |
141 | # else |
142 | # define EV_USE_SIGNALFD 0 |
142 | # define EV_USE_SIGNALFD 0 |
143 | # endif |
143 | # endif |
144 | # endif |
144 | # endif |
145 | |
145 | |
146 | # ifndef EV_USE_EVENTFD |
146 | # ifndef EV_USE_EVENTFD |
147 | # if HAVE_EVENTFD |
147 | # if HAVE_EVENTFD |
148 | # define EV_USE_EVENTFD 1 |
148 | # define EV_USE_EVENTFD EV_FEATURE_OS |
149 | # else |
149 | # else |
150 | # define EV_USE_EVENTFD 0 |
150 | # define EV_USE_EVENTFD 0 |
151 | # endif |
151 | # endif |
152 | # endif |
152 | # endif |
153 | |
153 | |
… | |
… | |
184 | # define WIN32_LEAN_AND_MEAN |
184 | # define WIN32_LEAN_AND_MEAN |
185 | # include <windows.h> |
185 | # include <windows.h> |
186 | # ifndef EV_SELECT_IS_WINSOCKET |
186 | # ifndef EV_SELECT_IS_WINSOCKET |
187 | # define EV_SELECT_IS_WINSOCKET 1 |
187 | # define EV_SELECT_IS_WINSOCKET 1 |
188 | # endif |
188 | # endif |
|
|
189 | # undef EV_AVOID_STDIO |
189 | #endif |
190 | #endif |
190 | |
191 | |
191 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
192 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
192 | |
193 | |
193 | /* try to deduce the maximum number of signals on this platform */ |
194 | /* try to deduce the maximum number of signals on this platform */ |
… | |
… | |
206 | #elif defined (MAXSIG) |
207 | #elif defined (MAXSIG) |
207 | # define EV_NSIG (MAXSIG+1) |
208 | # define EV_NSIG (MAXSIG+1) |
208 | #elif defined (MAX_SIG) |
209 | #elif defined (MAX_SIG) |
209 | # define EV_NSIG (MAX_SIG+1) |
210 | # define EV_NSIG (MAX_SIG+1) |
210 | #elif defined (SIGARRAYSIZE) |
211 | #elif defined (SIGARRAYSIZE) |
211 | # define EV_NSIG SIGARRAYSIZE /* Assume ary[SIGARRAYSIZE] */ |
212 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
212 | #elif defined (_sys_nsig) |
213 | #elif defined (_sys_nsig) |
213 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
214 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
214 | #else |
215 | #else |
215 | # error "unable to find value for NSIG, please report" |
216 | # error "unable to find value for NSIG, please report" |
216 | /* to make it compile regardless, just remove the above line */ |
217 | /* to make it compile regardless, just remove the above line, */ |
|
|
218 | /* but consider reporting it, too! :) */ |
217 | # define EV_NSIG 65 |
219 | # define EV_NSIG 65 |
218 | #endif |
220 | #endif |
219 | |
221 | |
220 | #ifndef EV_USE_CLOCK_SYSCALL |
222 | #ifndef EV_USE_CLOCK_SYSCALL |
221 | # if __linux && __GLIBC__ >= 2 |
223 | # if __linux && __GLIBC__ >= 2 |
222 | # define EV_USE_CLOCK_SYSCALL 1 |
224 | # define EV_USE_CLOCK_SYSCALL EV_FEATURE_OS |
223 | # else |
225 | # else |
224 | # define EV_USE_CLOCK_SYSCALL 0 |
226 | # define EV_USE_CLOCK_SYSCALL 0 |
225 | # endif |
227 | # endif |
226 | #endif |
228 | #endif |
227 | |
229 | |
228 | #ifndef EV_USE_MONOTONIC |
230 | #ifndef EV_USE_MONOTONIC |
229 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
231 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
230 | # define EV_USE_MONOTONIC 1 |
232 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
231 | # else |
233 | # else |
232 | # define EV_USE_MONOTONIC 0 |
234 | # define EV_USE_MONOTONIC 0 |
233 | # endif |
235 | # endif |
234 | #endif |
236 | #endif |
235 | |
237 | |
… | |
… | |
237 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
239 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
238 | #endif |
240 | #endif |
239 | |
241 | |
240 | #ifndef EV_USE_NANOSLEEP |
242 | #ifndef EV_USE_NANOSLEEP |
241 | # if _POSIX_C_SOURCE >= 199309L |
243 | # if _POSIX_C_SOURCE >= 199309L |
242 | # define EV_USE_NANOSLEEP 1 |
244 | # define EV_USE_NANOSLEEP EV_FEATURE_OS |
243 | # else |
245 | # else |
244 | # define EV_USE_NANOSLEEP 0 |
246 | # define EV_USE_NANOSLEEP 0 |
245 | # endif |
247 | # endif |
246 | #endif |
248 | #endif |
247 | |
249 | |
248 | #ifndef EV_USE_SELECT |
250 | #ifndef EV_USE_SELECT |
249 | # define EV_USE_SELECT 1 |
251 | # define EV_USE_SELECT EV_FEATURE_BACKENDS |
250 | #endif |
252 | #endif |
251 | |
253 | |
252 | #ifndef EV_USE_POLL |
254 | #ifndef EV_USE_POLL |
253 | # ifdef _WIN32 |
255 | # ifdef _WIN32 |
254 | # define EV_USE_POLL 0 |
256 | # define EV_USE_POLL 0 |
255 | # else |
257 | # else |
256 | # define EV_USE_POLL 1 |
258 | # define EV_USE_POLL EV_FEATURE_BACKENDS |
257 | # endif |
259 | # endif |
258 | #endif |
260 | #endif |
259 | |
261 | |
260 | #ifndef EV_USE_EPOLL |
262 | #ifndef EV_USE_EPOLL |
261 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
263 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
262 | # define EV_USE_EPOLL 1 |
264 | # define EV_USE_EPOLL EV_FEATURE_BACKENDS |
263 | # else |
265 | # else |
264 | # define EV_USE_EPOLL 0 |
266 | # define EV_USE_EPOLL 0 |
265 | # endif |
267 | # endif |
266 | #endif |
268 | #endif |
267 | |
269 | |
… | |
… | |
273 | # define EV_USE_PORT 0 |
275 | # define EV_USE_PORT 0 |
274 | #endif |
276 | #endif |
275 | |
277 | |
276 | #ifndef EV_USE_INOTIFY |
278 | #ifndef EV_USE_INOTIFY |
277 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
279 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
278 | # define EV_USE_INOTIFY 1 |
280 | # define EV_USE_INOTIFY EV_FEATURE_OS |
279 | # else |
281 | # else |
280 | # define EV_USE_INOTIFY 0 |
282 | # define EV_USE_INOTIFY 0 |
281 | # endif |
283 | # endif |
282 | #endif |
284 | #endif |
283 | |
285 | |
284 | #ifndef EV_PID_HASHSIZE |
286 | #ifndef EV_PID_HASHSIZE |
285 | # if EV_MINIMAL |
287 | # define EV_PID_HASHSIZE EV_FEATURE_DATA ? 16 : 1 |
286 | # define EV_PID_HASHSIZE 1 |
|
|
287 | # else |
|
|
288 | # define EV_PID_HASHSIZE 16 |
|
|
289 | # endif |
|
|
290 | #endif |
288 | #endif |
291 | |
289 | |
292 | #ifndef EV_INOTIFY_HASHSIZE |
290 | #ifndef EV_INOTIFY_HASHSIZE |
293 | # if EV_MINIMAL |
291 | # define EV_INOTIFY_HASHSIZE EV_FEATURE_DATA ? 16 : 1 |
294 | # define EV_INOTIFY_HASHSIZE 1 |
|
|
295 | # else |
|
|
296 | # define EV_INOTIFY_HASHSIZE 16 |
|
|
297 | # endif |
|
|
298 | #endif |
292 | #endif |
299 | |
293 | |
300 | #ifndef EV_USE_EVENTFD |
294 | #ifndef EV_USE_EVENTFD |
301 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
295 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
302 | # define EV_USE_EVENTFD 1 |
296 | # define EV_USE_EVENTFD EV_FEATURE_OS |
303 | # else |
297 | # else |
304 | # define EV_USE_EVENTFD 0 |
298 | # define EV_USE_EVENTFD 0 |
305 | # endif |
299 | # endif |
306 | #endif |
300 | #endif |
307 | |
301 | |
308 | #ifndef EV_USE_SIGNALFD |
302 | #ifndef EV_USE_SIGNALFD |
309 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
303 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
310 | # define EV_USE_SIGNALFD 1 |
304 | # define EV_USE_SIGNALFD EV_FEATURE_OS |
311 | # else |
305 | # else |
312 | # define EV_USE_SIGNALFD 0 |
306 | # define EV_USE_SIGNALFD 0 |
313 | # endif |
307 | # endif |
314 | #endif |
308 | #endif |
315 | |
309 | |
… | |
… | |
318 | # define EV_USE_4HEAP 1 |
312 | # define EV_USE_4HEAP 1 |
319 | # define EV_HEAP_CACHE_AT 1 |
313 | # define EV_HEAP_CACHE_AT 1 |
320 | #endif |
314 | #endif |
321 | |
315 | |
322 | #ifndef EV_VERIFY |
316 | #ifndef EV_VERIFY |
323 | # define EV_VERIFY !EV_MINIMAL |
317 | # define EV_VERIFY (EV_FEATURE_API ? 1 : 0) |
324 | #endif |
318 | #endif |
325 | |
319 | |
326 | #ifndef EV_USE_4HEAP |
320 | #ifndef EV_USE_4HEAP |
327 | # define EV_USE_4HEAP !EV_MINIMAL |
321 | # define EV_USE_4HEAP EV_FEATURE_DATA |
328 | #endif |
322 | #endif |
329 | |
323 | |
330 | #ifndef EV_HEAP_CACHE_AT |
324 | #ifndef EV_HEAP_CACHE_AT |
331 | # define EV_HEAP_CACHE_AT !EV_MINIMAL |
325 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
332 | #endif |
326 | #endif |
333 | |
327 | |
334 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
328 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
335 | /* which makes programs even slower. might work on other unices, too. */ |
329 | /* which makes programs even slower. might work on other unices, too. */ |
336 | #if EV_USE_CLOCK_SYSCALL |
330 | #if EV_USE_CLOCK_SYSCALL |
… | |
… | |
441 | |
435 | |
442 | |
436 | |
443 | /**/ |
437 | /**/ |
444 | |
438 | |
445 | #if EV_VERIFY >= 3 |
439 | #if EV_VERIFY >= 3 |
446 | # define EV_FREQUENT_CHECK ev_loop_verify (EV_A) |
440 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
447 | #else |
441 | #else |
448 | # define EV_FREQUENT_CHECK do { } while (0) |
442 | # define EV_FREQUENT_CHECK do { } while (0) |
449 | #endif |
443 | #endif |
450 | |
444 | |
451 | /* |
445 | /* |
… | |
… | |
474 | |
468 | |
475 | #define expect_false(expr) expect ((expr) != 0, 0) |
469 | #define expect_false(expr) expect ((expr) != 0, 0) |
476 | #define expect_true(expr) expect ((expr) != 0, 1) |
470 | #define expect_true(expr) expect ((expr) != 0, 1) |
477 | #define inline_size static inline |
471 | #define inline_size static inline |
478 | |
472 | |
479 | #if EV_MINIMAL |
473 | #if EV_FEATURE_CODE |
|
|
474 | # define inline_speed static inline |
|
|
475 | #else |
480 | # define inline_speed static noinline |
476 | # define inline_speed static noinline |
481 | #else |
|
|
482 | # define inline_speed static inline |
|
|
483 | #endif |
477 | #endif |
484 | |
478 | |
485 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
479 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
486 | |
480 | |
487 | #if EV_MINPRI == EV_MAXPRI |
481 | #if EV_MINPRI == EV_MAXPRI |
… | |
… | |
524 | # include "ev_win32.c" |
518 | # include "ev_win32.c" |
525 | #endif |
519 | #endif |
526 | |
520 | |
527 | /*****************************************************************************/ |
521 | /*****************************************************************************/ |
528 | |
522 | |
|
|
523 | #if EV_AVOID_STDIO |
|
|
524 | static void noinline |
|
|
525 | ev_printerr (const char *msg) |
|
|
526 | { |
|
|
527 | write (STDERR_FILENO, msg, strlen (msg)); |
|
|
528 | } |
|
|
529 | #endif |
|
|
530 | |
529 | static void (*syserr_cb)(const char *msg); |
531 | static void (*syserr_cb)(const char *msg); |
530 | |
532 | |
531 | void |
533 | void |
532 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
534 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
533 | { |
535 | { |
… | |
… | |
543 | if (syserr_cb) |
545 | if (syserr_cb) |
544 | syserr_cb (msg); |
546 | syserr_cb (msg); |
545 | else |
547 | else |
546 | { |
548 | { |
547 | #if EV_AVOID_STDIO |
549 | #if EV_AVOID_STDIO |
548 | write (STDERR_FILENO, msg, strlen (msg)); |
|
|
549 | write (STDERR_FILENO, ": ", 2); |
|
|
550 | msg = strerror (errno); |
550 | const char *err = strerror (errno); |
551 | write (STDERR_FILENO, msg, strlen (msg)); |
551 | |
552 | write (STDERR_FILENO, "\n", 1); |
552 | ev_printerr (msg); |
|
|
553 | ev_printerr (": "); |
|
|
554 | ev_printerr (err); |
|
|
555 | ev_printerr ("\n"); |
553 | #else |
556 | #else |
554 | perror (msg); |
557 | perror (msg); |
555 | #endif |
558 | #endif |
556 | abort (); |
559 | abort (); |
557 | } |
560 | } |
558 | } |
561 | } |
559 | |
562 | |
560 | static void * |
563 | static void * |
561 | ev_realloc_emul (void *ptr, long size) |
564 | ev_realloc_emul (void *ptr, long size) |
562 | { |
565 | { |
|
|
566 | #if __GLIBC__ |
|
|
567 | return realloc (ptr, size); |
|
|
568 | #else |
563 | /* some systems, notably openbsd and darwin, fail to properly |
569 | /* some systems, notably openbsd and darwin, fail to properly |
564 | * implement realloc (x, 0) (as required by both ansi c-98 and |
570 | * implement realloc (x, 0) (as required by both ansi c-89 and |
565 | * the single unix specification, so work around them here. |
571 | * the single unix specification, so work around them here. |
566 | */ |
572 | */ |
567 | |
573 | |
568 | if (size) |
574 | if (size) |
569 | return realloc (ptr, size); |
575 | return realloc (ptr, size); |
570 | |
576 | |
571 | free (ptr); |
577 | free (ptr); |
572 | return 0; |
578 | return 0; |
|
|
579 | #endif |
573 | } |
580 | } |
574 | |
581 | |
575 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
582 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
576 | |
583 | |
577 | void |
584 | void |
… | |
… | |
586 | ptr = alloc (ptr, size); |
593 | ptr = alloc (ptr, size); |
587 | |
594 | |
588 | if (!ptr && size) |
595 | if (!ptr && size) |
589 | { |
596 | { |
590 | #if EV_AVOID_STDIO |
597 | #if EV_AVOID_STDIO |
591 | write (STDERR_FILENO, "libev: memory allocation failed, aborting.", |
598 | ev_printerr ("libev: memory allocation failed, aborting.\n"); |
592 | sizeof ("libev: memory allocation failed, aborting.") - 1); |
|
|
593 | #else |
599 | #else |
594 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
600 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
595 | #endif |
601 | #endif |
596 | abort (); |
602 | abort (); |
597 | } |
603 | } |
… | |
… | |
682 | |
688 | |
683 | static int ev_default_loop_ptr; |
689 | static int ev_default_loop_ptr; |
684 | |
690 | |
685 | #endif |
691 | #endif |
686 | |
692 | |
687 | #if EV_MINIMAL < 2 |
693 | #if EV_FEATURE_API |
688 | # define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) |
694 | # define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) |
689 | # define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A) |
695 | # define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A) |
690 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
696 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
691 | #else |
697 | #else |
692 | # define EV_RELEASE_CB (void)0 |
698 | # define EV_RELEASE_CB (void)0 |
… | |
… | |
877 | } |
883 | } |
878 | |
884 | |
879 | /*****************************************************************************/ |
885 | /*****************************************************************************/ |
880 | |
886 | |
881 | inline_speed void |
887 | inline_speed void |
882 | fd_event_nc (EV_P_ int fd, int revents) |
888 | fd_event_nocheck (EV_P_ int fd, int revents) |
883 | { |
889 | { |
884 | ANFD *anfd = anfds + fd; |
890 | ANFD *anfd = anfds + fd; |
885 | ev_io *w; |
891 | ev_io *w; |
886 | |
892 | |
887 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
893 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
… | |
… | |
899 | fd_event (EV_P_ int fd, int revents) |
905 | fd_event (EV_P_ int fd, int revents) |
900 | { |
906 | { |
901 | ANFD *anfd = anfds + fd; |
907 | ANFD *anfd = anfds + fd; |
902 | |
908 | |
903 | if (expect_true (!anfd->reify)) |
909 | if (expect_true (!anfd->reify)) |
904 | fd_event_nc (EV_A_ fd, revents); |
910 | fd_event_nocheck (EV_A_ fd, revents); |
905 | } |
911 | } |
906 | |
912 | |
907 | void |
913 | void |
908 | ev_feed_fd_event (EV_P_ int fd, int revents) |
914 | ev_feed_fd_event (EV_P_ int fd, int revents) |
909 | { |
915 | { |
910 | if (fd >= 0 && fd < anfdmax) |
916 | if (fd >= 0 && fd < anfdmax) |
911 | fd_event_nc (EV_A_ fd, revents); |
917 | fd_event_nocheck (EV_A_ fd, revents); |
912 | } |
918 | } |
913 | |
919 | |
914 | /* make sure the external fd watch events are in-sync */ |
920 | /* make sure the external fd watch events are in-sync */ |
915 | /* with the kernel/libev internal state */ |
921 | /* with the kernel/libev internal state */ |
916 | inline_size void |
922 | inline_size void |
… | |
… | |
979 | ev_io_stop (EV_A_ w); |
985 | ev_io_stop (EV_A_ w); |
980 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
986 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
981 | } |
987 | } |
982 | } |
988 | } |
983 | |
989 | |
984 | /* check whether the given fd is atcually valid, for error recovery */ |
990 | /* check whether the given fd is actually valid, for error recovery */ |
985 | inline_size int |
991 | inline_size int |
986 | fd_valid (int fd) |
992 | fd_valid (int fd) |
987 | { |
993 | { |
988 | #ifdef _WIN32 |
994 | #ifdef _WIN32 |
989 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
995 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
… | |
… | |
1029 | { |
1035 | { |
1030 | anfds [fd].events = 0; |
1036 | anfds [fd].events = 0; |
1031 | anfds [fd].emask = 0; |
1037 | anfds [fd].emask = 0; |
1032 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1038 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1033 | } |
1039 | } |
|
|
1040 | } |
|
|
1041 | |
|
|
1042 | /* used to prepare libev internal fd's */ |
|
|
1043 | /* this is not fork-safe */ |
|
|
1044 | inline_speed void |
|
|
1045 | fd_intern (int fd) |
|
|
1046 | { |
|
|
1047 | #ifdef _WIN32 |
|
|
1048 | unsigned long arg = 1; |
|
|
1049 | ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg); |
|
|
1050 | #else |
|
|
1051 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1052 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1053 | #endif |
1034 | } |
1054 | } |
1035 | |
1055 | |
1036 | /*****************************************************************************/ |
1056 | /*****************************************************************************/ |
1037 | |
1057 | |
1038 | /* |
1058 | /* |
… | |
… | |
1192 | |
1212 | |
1193 | static ANSIG signals [EV_NSIG - 1]; |
1213 | static ANSIG signals [EV_NSIG - 1]; |
1194 | |
1214 | |
1195 | /*****************************************************************************/ |
1215 | /*****************************************************************************/ |
1196 | |
1216 | |
1197 | /* used to prepare libev internal fd's */ |
1217 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1198 | /* this is not fork-safe */ |
|
|
1199 | inline_speed void |
|
|
1200 | fd_intern (int fd) |
|
|
1201 | { |
|
|
1202 | #ifdef _WIN32 |
|
|
1203 | unsigned long arg = 1; |
|
|
1204 | ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg); |
|
|
1205 | #else |
|
|
1206 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1207 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1208 | #endif |
|
|
1209 | } |
|
|
1210 | |
1218 | |
1211 | static void noinline |
1219 | static void noinline |
1212 | evpipe_init (EV_P) |
1220 | evpipe_init (EV_P) |
1213 | { |
1221 | { |
1214 | if (!ev_is_active (&pipe_w)) |
1222 | if (!ev_is_active (&pipe_w)) |
1215 | { |
1223 | { |
1216 | #if EV_USE_EVENTFD |
1224 | # if EV_USE_EVENTFD |
1217 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1225 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1218 | if (evfd < 0 && errno == EINVAL) |
1226 | if (evfd < 0 && errno == EINVAL) |
1219 | evfd = eventfd (0, 0); |
1227 | evfd = eventfd (0, 0); |
1220 | |
1228 | |
1221 | if (evfd >= 0) |
1229 | if (evfd >= 0) |
… | |
… | |
1223 | evpipe [0] = -1; |
1231 | evpipe [0] = -1; |
1224 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1232 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1225 | ev_io_set (&pipe_w, evfd, EV_READ); |
1233 | ev_io_set (&pipe_w, evfd, EV_READ); |
1226 | } |
1234 | } |
1227 | else |
1235 | else |
1228 | #endif |
1236 | # endif |
1229 | { |
1237 | { |
1230 | while (pipe (evpipe)) |
1238 | while (pipe (evpipe)) |
1231 | ev_syserr ("(libev) error creating signal/async pipe"); |
1239 | ev_syserr ("(libev) error creating signal/async pipe"); |
1232 | |
1240 | |
1233 | fd_intern (evpipe [0]); |
1241 | fd_intern (evpipe [0]); |
… | |
… | |
1244 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1252 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1245 | { |
1253 | { |
1246 | if (!*flag) |
1254 | if (!*flag) |
1247 | { |
1255 | { |
1248 | int old_errno = errno; /* save errno because write might clobber it */ |
1256 | int old_errno = errno; /* save errno because write might clobber it */ |
|
|
1257 | char dummy; |
1249 | |
1258 | |
1250 | *flag = 1; |
1259 | *flag = 1; |
1251 | |
1260 | |
1252 | #if EV_USE_EVENTFD |
1261 | #if EV_USE_EVENTFD |
1253 | if (evfd >= 0) |
1262 | if (evfd >= 0) |
… | |
… | |
1255 | uint64_t counter = 1; |
1264 | uint64_t counter = 1; |
1256 | write (evfd, &counter, sizeof (uint64_t)); |
1265 | write (evfd, &counter, sizeof (uint64_t)); |
1257 | } |
1266 | } |
1258 | else |
1267 | else |
1259 | #endif |
1268 | #endif |
1260 | write (evpipe [1], &old_errno, 1); |
1269 | write (evpipe [1], &dummy, 1); |
1261 | |
1270 | |
1262 | errno = old_errno; |
1271 | errno = old_errno; |
1263 | } |
1272 | } |
1264 | } |
1273 | } |
1265 | |
1274 | |
… | |
… | |
1366 | break; |
1375 | break; |
1367 | } |
1376 | } |
1368 | } |
1377 | } |
1369 | #endif |
1378 | #endif |
1370 | |
1379 | |
|
|
1380 | #endif |
|
|
1381 | |
1371 | /*****************************************************************************/ |
1382 | /*****************************************************************************/ |
1372 | |
1383 | |
|
|
1384 | #if EV_CHILD_ENABLE |
1373 | static WL childs [EV_PID_HASHSIZE]; |
1385 | static WL childs [EV_PID_HASHSIZE]; |
1374 | |
|
|
1375 | #ifndef _WIN32 |
|
|
1376 | |
1386 | |
1377 | static ev_signal childev; |
1387 | static ev_signal childev; |
1378 | |
1388 | |
1379 | #ifndef WIFCONTINUED |
1389 | #ifndef WIFCONTINUED |
1380 | # define WIFCONTINUED(status) 0 |
1390 | # define WIFCONTINUED(status) 0 |
… | |
… | |
1385 | child_reap (EV_P_ int chain, int pid, int status) |
1395 | child_reap (EV_P_ int chain, int pid, int status) |
1386 | { |
1396 | { |
1387 | ev_child *w; |
1397 | ev_child *w; |
1388 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1398 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1389 | |
1399 | |
1390 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1400 | for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next) |
1391 | { |
1401 | { |
1392 | if ((w->pid == pid || !w->pid) |
1402 | if ((w->pid == pid || !w->pid) |
1393 | && (!traced || (w->flags & 1))) |
1403 | && (!traced || (w->flags & 1))) |
1394 | { |
1404 | { |
1395 | ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ |
1405 | ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ |
… | |
… | |
1420 | /* make sure we are called again until all children have been reaped */ |
1430 | /* make sure we are called again until all children have been reaped */ |
1421 | /* we need to do it this way so that the callback gets called before we continue */ |
1431 | /* we need to do it this way so that the callback gets called before we continue */ |
1422 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1432 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1423 | |
1433 | |
1424 | child_reap (EV_A_ pid, pid, status); |
1434 | child_reap (EV_A_ pid, pid, status); |
1425 | if (EV_PID_HASHSIZE > 1) |
1435 | if ((EV_PID_HASHSIZE) > 1) |
1426 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
1436 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
1427 | } |
1437 | } |
1428 | |
1438 | |
1429 | #endif |
1439 | #endif |
1430 | |
1440 | |
… | |
… | |
1497 | #ifdef __APPLE__ |
1507 | #ifdef __APPLE__ |
1498 | /* only select works correctly on that "unix-certified" platform */ |
1508 | /* only select works correctly on that "unix-certified" platform */ |
1499 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1509 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1500 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
1510 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
1501 | #endif |
1511 | #endif |
|
|
1512 | #ifdef __FreeBSD__ |
|
|
1513 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
|
|
1514 | #endif |
1502 | |
1515 | |
1503 | return flags; |
1516 | return flags; |
1504 | } |
1517 | } |
1505 | |
1518 | |
1506 | unsigned int |
1519 | unsigned int |
… | |
… | |
1519 | ev_backend (EV_P) |
1532 | ev_backend (EV_P) |
1520 | { |
1533 | { |
1521 | return backend; |
1534 | return backend; |
1522 | } |
1535 | } |
1523 | |
1536 | |
1524 | #if EV_MINIMAL < 2 |
1537 | #if EV_FEATURE_API |
1525 | unsigned int |
1538 | unsigned int |
1526 | ev_loop_count (EV_P) |
1539 | ev_iteration (EV_P) |
1527 | { |
1540 | { |
1528 | return loop_count; |
1541 | return loop_count; |
1529 | } |
1542 | } |
1530 | |
1543 | |
1531 | unsigned int |
1544 | unsigned int |
1532 | ev_loop_depth (EV_P) |
1545 | ev_depth (EV_P) |
1533 | { |
1546 | { |
1534 | return loop_depth; |
1547 | return loop_depth; |
1535 | } |
1548 | } |
1536 | |
1549 | |
1537 | void |
1550 | void |
… | |
… | |
1609 | |
1622 | |
1610 | ev_rt_now = ev_time (); |
1623 | ev_rt_now = ev_time (); |
1611 | mn_now = get_clock (); |
1624 | mn_now = get_clock (); |
1612 | now_floor = mn_now; |
1625 | now_floor = mn_now; |
1613 | rtmn_diff = ev_rt_now - mn_now; |
1626 | rtmn_diff = ev_rt_now - mn_now; |
1614 | #if EV_MINIMAL < 2 |
1627 | #if EV_FEATURE_API |
1615 | invoke_cb = ev_invoke_pending; |
1628 | invoke_cb = ev_invoke_pending; |
1616 | #endif |
1629 | #endif |
1617 | |
1630 | |
1618 | io_blocktime = 0.; |
1631 | io_blocktime = 0.; |
1619 | timeout_blocktime = 0.; |
1632 | timeout_blocktime = 0.; |
… | |
… | |
1649 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1662 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1650 | #endif |
1663 | #endif |
1651 | |
1664 | |
1652 | ev_prepare_init (&pending_w, pendingcb); |
1665 | ev_prepare_init (&pending_w, pendingcb); |
1653 | |
1666 | |
|
|
1667 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1654 | ev_init (&pipe_w, pipecb); |
1668 | ev_init (&pipe_w, pipecb); |
1655 | ev_set_priority (&pipe_w, EV_MAXPRI); |
1669 | ev_set_priority (&pipe_w, EV_MAXPRI); |
|
|
1670 | #endif |
1656 | } |
1671 | } |
1657 | } |
1672 | } |
1658 | |
1673 | |
1659 | /* free up a loop structure */ |
1674 | /* free up a loop structure */ |
1660 | static void noinline |
1675 | static void noinline |
… | |
… | |
1778 | { |
1793 | { |
1779 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1794 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1780 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1795 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1781 | } |
1796 | } |
1782 | |
1797 | |
|
|
1798 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1783 | evpipe_init (EV_A); |
1799 | evpipe_init (EV_A); |
1784 | /* now iterate over everything, in case we missed something */ |
1800 | /* now iterate over everything, in case we missed something */ |
1785 | pipecb (EV_A_ &pipe_w, EV_READ); |
1801 | pipecb (EV_A_ &pipe_w, EV_READ); |
|
|
1802 | #endif |
1786 | } |
1803 | } |
1787 | |
1804 | |
1788 | postfork = 0; |
1805 | postfork = 0; |
1789 | } |
1806 | } |
1790 | |
1807 | |
… | |
… | |
1852 | verify_watcher (EV_A_ ws [cnt]); |
1869 | verify_watcher (EV_A_ ws [cnt]); |
1853 | } |
1870 | } |
1854 | } |
1871 | } |
1855 | #endif |
1872 | #endif |
1856 | |
1873 | |
1857 | #if EV_MINIMAL < 2 |
1874 | #if EV_FEATURE_API |
1858 | void |
1875 | void |
1859 | ev_loop_verify (EV_P) |
1876 | ev_verify (EV_P) |
1860 | { |
1877 | { |
1861 | #if EV_VERIFY |
1878 | #if EV_VERIFY |
1862 | int i; |
1879 | int i; |
1863 | WL w; |
1880 | WL w; |
1864 | |
1881 | |
… | |
… | |
1903 | #if EV_ASYNC_ENABLE |
1920 | #if EV_ASYNC_ENABLE |
1904 | assert (asyncmax >= asynccnt); |
1921 | assert (asyncmax >= asynccnt); |
1905 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1922 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1906 | #endif |
1923 | #endif |
1907 | |
1924 | |
|
|
1925 | #if EV_PREPARE_ENABLE |
1908 | assert (preparemax >= preparecnt); |
1926 | assert (preparemax >= preparecnt); |
1909 | array_verify (EV_A_ (W *)prepares, preparecnt); |
1927 | array_verify (EV_A_ (W *)prepares, preparecnt); |
|
|
1928 | #endif |
1910 | |
1929 | |
|
|
1930 | #if EV_CHECK_ENABLE |
1911 | assert (checkmax >= checkcnt); |
1931 | assert (checkmax >= checkcnt); |
1912 | array_verify (EV_A_ (W *)checks, checkcnt); |
1932 | array_verify (EV_A_ (W *)checks, checkcnt); |
|
|
1933 | #endif |
1913 | |
1934 | |
1914 | # if 0 |
1935 | # if 0 |
|
|
1936 | #if EV_CHILD_ENABLE |
1915 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1937 | for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next) |
1916 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
1938 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
|
|
1939 | #endif |
1917 | # endif |
1940 | # endif |
1918 | #endif |
1941 | #endif |
1919 | } |
1942 | } |
1920 | #endif |
1943 | #endif |
1921 | |
1944 | |
… | |
… | |
1937 | |
1960 | |
1938 | loop_init (EV_A_ flags); |
1961 | loop_init (EV_A_ flags); |
1939 | |
1962 | |
1940 | if (ev_backend (EV_A)) |
1963 | if (ev_backend (EV_A)) |
1941 | { |
1964 | { |
1942 | #ifndef _WIN32 |
1965 | #if EV_CHILD_ENABLE |
1943 | ev_signal_init (&childev, childcb, SIGCHLD); |
1966 | ev_signal_init (&childev, childcb, SIGCHLD); |
1944 | ev_set_priority (&childev, EV_MAXPRI); |
1967 | ev_set_priority (&childev, EV_MAXPRI); |
1945 | ev_signal_start (EV_A_ &childev); |
1968 | ev_signal_start (EV_A_ &childev); |
1946 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1969 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1947 | #endif |
1970 | #endif |
… | |
… | |
1960 | EV_P = ev_default_loop_ptr; |
1983 | EV_P = ev_default_loop_ptr; |
1961 | #endif |
1984 | #endif |
1962 | |
1985 | |
1963 | ev_default_loop_ptr = 0; |
1986 | ev_default_loop_ptr = 0; |
1964 | |
1987 | |
1965 | #ifndef _WIN32 |
1988 | #if EV_CHILD_ENABLE |
1966 | ev_ref (EV_A); /* child watcher */ |
1989 | ev_ref (EV_A); /* child watcher */ |
1967 | ev_signal_stop (EV_A_ &childev); |
1990 | ev_signal_stop (EV_A_ &childev); |
1968 | #endif |
1991 | #endif |
1969 | |
1992 | |
1970 | loop_destroy (EV_A); |
1993 | loop_destroy (EV_A); |
… | |
… | |
2076 | EV_FREQUENT_CHECK; |
2099 | EV_FREQUENT_CHECK; |
2077 | feed_reverse (EV_A_ (W)w); |
2100 | feed_reverse (EV_A_ (W)w); |
2078 | } |
2101 | } |
2079 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2102 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2080 | |
2103 | |
2081 | feed_reverse_done (EV_A_ EV_TIMEOUT); |
2104 | feed_reverse_done (EV_A_ EV_TIMER); |
2082 | } |
2105 | } |
2083 | } |
2106 | } |
2084 | |
2107 | |
2085 | #if EV_PERIODIC_ENABLE |
2108 | #if EV_PERIODIC_ENABLE |
2086 | /* make periodics pending */ |
2109 | /* make periodics pending */ |
… | |
… | |
2247 | } |
2270 | } |
2248 | |
2271 | |
2249 | void |
2272 | void |
2250 | ev_loop (EV_P_ int flags) |
2273 | ev_loop (EV_P_ int flags) |
2251 | { |
2274 | { |
2252 | #if EV_MINIMAL < 2 |
2275 | #if EV_FEATURE_API |
2253 | ++loop_depth; |
2276 | ++loop_depth; |
2254 | #endif |
2277 | #endif |
2255 | |
2278 | |
2256 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2279 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2257 | |
2280 | |
… | |
… | |
2260 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2283 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2261 | |
2284 | |
2262 | do |
2285 | do |
2263 | { |
2286 | { |
2264 | #if EV_VERIFY >= 2 |
2287 | #if EV_VERIFY >= 2 |
2265 | ev_loop_verify (EV_A); |
2288 | ev_verify (EV_A); |
2266 | #endif |
2289 | #endif |
2267 | |
2290 | |
2268 | #ifndef _WIN32 |
2291 | #ifndef _WIN32 |
2269 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2292 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2270 | if (expect_false (getpid () != curpid)) |
2293 | if (expect_false (getpid () != curpid)) |
… | |
… | |
2282 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2305 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2283 | EV_INVOKE_PENDING; |
2306 | EV_INVOKE_PENDING; |
2284 | } |
2307 | } |
2285 | #endif |
2308 | #endif |
2286 | |
2309 | |
|
|
2310 | #if EV_PREPARE_ENABLE |
2287 | /* queue prepare watchers (and execute them) */ |
2311 | /* queue prepare watchers (and execute them) */ |
2288 | if (expect_false (preparecnt)) |
2312 | if (expect_false (preparecnt)) |
2289 | { |
2313 | { |
2290 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2314 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2291 | EV_INVOKE_PENDING; |
2315 | EV_INVOKE_PENDING; |
2292 | } |
2316 | } |
|
|
2317 | #endif |
2293 | |
2318 | |
2294 | if (expect_false (loop_done)) |
2319 | if (expect_false (loop_done)) |
2295 | break; |
2320 | break; |
2296 | |
2321 | |
2297 | /* we might have forked, so reify kernel state if necessary */ |
2322 | /* we might have forked, so reify kernel state if necessary */ |
… | |
… | |
2348 | waittime -= sleeptime; |
2373 | waittime -= sleeptime; |
2349 | } |
2374 | } |
2350 | } |
2375 | } |
2351 | } |
2376 | } |
2352 | |
2377 | |
2353 | #if EV_MINIMAL < 2 |
2378 | #if EV_FEATURE_API |
2354 | ++loop_count; |
2379 | ++loop_count; |
2355 | #endif |
2380 | #endif |
2356 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2381 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2357 | backend_poll (EV_A_ waittime); |
2382 | backend_poll (EV_A_ waittime); |
2358 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
2383 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
… | |
… | |
2370 | #if EV_IDLE_ENABLE |
2395 | #if EV_IDLE_ENABLE |
2371 | /* queue idle watchers unless other events are pending */ |
2396 | /* queue idle watchers unless other events are pending */ |
2372 | idle_reify (EV_A); |
2397 | idle_reify (EV_A); |
2373 | #endif |
2398 | #endif |
2374 | |
2399 | |
|
|
2400 | #if EV_CHECK_ENABLE |
2375 | /* queue check watchers, to be executed first */ |
2401 | /* queue check watchers, to be executed first */ |
2376 | if (expect_false (checkcnt)) |
2402 | if (expect_false (checkcnt)) |
2377 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
2403 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
|
|
2404 | #endif |
2378 | |
2405 | |
2379 | EV_INVOKE_PENDING; |
2406 | EV_INVOKE_PENDING; |
2380 | } |
2407 | } |
2381 | while (expect_true ( |
2408 | while (expect_true ( |
2382 | activecnt |
2409 | activecnt |
… | |
… | |
2385 | )); |
2412 | )); |
2386 | |
2413 | |
2387 | if (loop_done == EVUNLOOP_ONE) |
2414 | if (loop_done == EVUNLOOP_ONE) |
2388 | loop_done = EVUNLOOP_CANCEL; |
2415 | loop_done = EVUNLOOP_CANCEL; |
2389 | |
2416 | |
2390 | #if EV_MINIMAL < 2 |
2417 | #if EV_FEATURE_API |
2391 | --loop_depth; |
2418 | --loop_depth; |
2392 | #endif |
2419 | #endif |
2393 | } |
2420 | } |
2394 | |
2421 | |
2395 | void |
2422 | void |
… | |
… | |
2712 | |
2739 | |
2713 | #ifndef SA_RESTART |
2740 | #ifndef SA_RESTART |
2714 | # define SA_RESTART 0 |
2741 | # define SA_RESTART 0 |
2715 | #endif |
2742 | #endif |
2716 | |
2743 | |
|
|
2744 | #if EV_SIGNAL_ENABLE |
|
|
2745 | |
2717 | void noinline |
2746 | void noinline |
2718 | ev_signal_start (EV_P_ ev_signal *w) |
2747 | ev_signal_start (EV_P_ ev_signal *w) |
2719 | { |
2748 | { |
2720 | if (expect_false (ev_is_active (w))) |
2749 | if (expect_false (ev_is_active (w))) |
2721 | return; |
2750 | return; |
… | |
… | |
2827 | } |
2856 | } |
2828 | |
2857 | |
2829 | EV_FREQUENT_CHECK; |
2858 | EV_FREQUENT_CHECK; |
2830 | } |
2859 | } |
2831 | |
2860 | |
|
|
2861 | #endif |
|
|
2862 | |
|
|
2863 | #if EV_CHILD_ENABLE |
|
|
2864 | |
2832 | void |
2865 | void |
2833 | ev_child_start (EV_P_ ev_child *w) |
2866 | ev_child_start (EV_P_ ev_child *w) |
2834 | { |
2867 | { |
2835 | #if EV_MULTIPLICITY |
2868 | #if EV_MULTIPLICITY |
2836 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
2869 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
… | |
… | |
2839 | return; |
2872 | return; |
2840 | |
2873 | |
2841 | EV_FREQUENT_CHECK; |
2874 | EV_FREQUENT_CHECK; |
2842 | |
2875 | |
2843 | ev_start (EV_A_ (W)w, 1); |
2876 | ev_start (EV_A_ (W)w, 1); |
2844 | wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2877 | wlist_add (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2845 | |
2878 | |
2846 | EV_FREQUENT_CHECK; |
2879 | EV_FREQUENT_CHECK; |
2847 | } |
2880 | } |
2848 | |
2881 | |
2849 | void |
2882 | void |
… | |
… | |
2853 | if (expect_false (!ev_is_active (w))) |
2886 | if (expect_false (!ev_is_active (w))) |
2854 | return; |
2887 | return; |
2855 | |
2888 | |
2856 | EV_FREQUENT_CHECK; |
2889 | EV_FREQUENT_CHECK; |
2857 | |
2890 | |
2858 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2891 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2859 | ev_stop (EV_A_ (W)w); |
2892 | ev_stop (EV_A_ (W)w); |
2860 | |
2893 | |
2861 | EV_FREQUENT_CHECK; |
2894 | EV_FREQUENT_CHECK; |
2862 | } |
2895 | } |
|
|
2896 | |
|
|
2897 | #endif |
2863 | |
2898 | |
2864 | #if EV_STAT_ENABLE |
2899 | #if EV_STAT_ENABLE |
2865 | |
2900 | |
2866 | # ifdef _WIN32 |
2901 | # ifdef _WIN32 |
2867 | # undef lstat |
2902 | # undef lstat |
… | |
… | |
2934 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2969 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2935 | } |
2970 | } |
2936 | } |
2971 | } |
2937 | |
2972 | |
2938 | if (w->wd >= 0) |
2973 | if (w->wd >= 0) |
2939 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2974 | wlist_add (&fs_hash [w->wd & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
2940 | |
2975 | |
2941 | /* now re-arm timer, if required */ |
2976 | /* now re-arm timer, if required */ |
2942 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2977 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2943 | ev_timer_again (EV_A_ &w->timer); |
2978 | ev_timer_again (EV_A_ &w->timer); |
2944 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
2979 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
… | |
… | |
2952 | |
2987 | |
2953 | if (wd < 0) |
2988 | if (wd < 0) |
2954 | return; |
2989 | return; |
2955 | |
2990 | |
2956 | w->wd = -2; |
2991 | w->wd = -2; |
2957 | slot = wd & (EV_INOTIFY_HASHSIZE - 1); |
2992 | slot = wd & ((EV_INOTIFY_HASHSIZE) - 1); |
2958 | wlist_del (&fs_hash [slot].head, (WL)w); |
2993 | wlist_del (&fs_hash [slot].head, (WL)w); |
2959 | |
2994 | |
2960 | /* remove this watcher, if others are watching it, they will rearm */ |
2995 | /* remove this watcher, if others are watching it, they will rearm */ |
2961 | inotify_rm_watch (fs_fd, wd); |
2996 | inotify_rm_watch (fs_fd, wd); |
2962 | } |
2997 | } |
… | |
… | |
2964 | static void noinline |
2999 | static void noinline |
2965 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
3000 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
2966 | { |
3001 | { |
2967 | if (slot < 0) |
3002 | if (slot < 0) |
2968 | /* overflow, need to check for all hash slots */ |
3003 | /* overflow, need to check for all hash slots */ |
2969 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3004 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
2970 | infy_wd (EV_A_ slot, wd, ev); |
3005 | infy_wd (EV_A_ slot, wd, ev); |
2971 | else |
3006 | else |
2972 | { |
3007 | { |
2973 | WL w_; |
3008 | WL w_; |
2974 | |
3009 | |
2975 | for (w_ = fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head; w_; ) |
3010 | for (w_ = fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head; w_; ) |
2976 | { |
3011 | { |
2977 | ev_stat *w = (ev_stat *)w_; |
3012 | ev_stat *w = (ev_stat *)w_; |
2978 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
3013 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
2979 | |
3014 | |
2980 | if (w->wd == wd || wd == -1) |
3015 | if (w->wd == wd || wd == -1) |
2981 | { |
3016 | { |
2982 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
3017 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
2983 | { |
3018 | { |
2984 | wlist_del (&fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
3019 | wlist_del (&fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
2985 | w->wd = -1; |
3020 | w->wd = -1; |
2986 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3021 | infy_add (EV_A_ w); /* re-add, no matter what */ |
2987 | } |
3022 | } |
2988 | |
3023 | |
2989 | stat_timer_cb (EV_A_ &w->timer, 0); |
3024 | stat_timer_cb (EV_A_ &w->timer, 0); |
… | |
… | |
3103 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3138 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3104 | ev_io_start (EV_A_ &fs_w); |
3139 | ev_io_start (EV_A_ &fs_w); |
3105 | ev_unref (EV_A); |
3140 | ev_unref (EV_A); |
3106 | } |
3141 | } |
3107 | |
3142 | |
3108 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3143 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
3109 | { |
3144 | { |
3110 | WL w_ = fs_hash [slot].head; |
3145 | WL w_ = fs_hash [slot].head; |
3111 | fs_hash [slot].head = 0; |
3146 | fs_hash [slot].head = 0; |
3112 | |
3147 | |
3113 | while (w_) |
3148 | while (w_) |
… | |
… | |
3288 | |
3323 | |
3289 | EV_FREQUENT_CHECK; |
3324 | EV_FREQUENT_CHECK; |
3290 | } |
3325 | } |
3291 | #endif |
3326 | #endif |
3292 | |
3327 | |
|
|
3328 | #if EV_PREPARE_ENABLE |
3293 | void |
3329 | void |
3294 | ev_prepare_start (EV_P_ ev_prepare *w) |
3330 | ev_prepare_start (EV_P_ ev_prepare *w) |
3295 | { |
3331 | { |
3296 | if (expect_false (ev_is_active (w))) |
3332 | if (expect_false (ev_is_active (w))) |
3297 | return; |
3333 | return; |
… | |
… | |
3323 | |
3359 | |
3324 | ev_stop (EV_A_ (W)w); |
3360 | ev_stop (EV_A_ (W)w); |
3325 | |
3361 | |
3326 | EV_FREQUENT_CHECK; |
3362 | EV_FREQUENT_CHECK; |
3327 | } |
3363 | } |
|
|
3364 | #endif |
3328 | |
3365 | |
|
|
3366 | #if EV_CHECK_ENABLE |
3329 | void |
3367 | void |
3330 | ev_check_start (EV_P_ ev_check *w) |
3368 | ev_check_start (EV_P_ ev_check *w) |
3331 | { |
3369 | { |
3332 | if (expect_false (ev_is_active (w))) |
3370 | if (expect_false (ev_is_active (w))) |
3333 | return; |
3371 | return; |
… | |
… | |
3359 | |
3397 | |
3360 | ev_stop (EV_A_ (W)w); |
3398 | ev_stop (EV_A_ (W)w); |
3361 | |
3399 | |
3362 | EV_FREQUENT_CHECK; |
3400 | EV_FREQUENT_CHECK; |
3363 | } |
3401 | } |
|
|
3402 | #endif |
3364 | |
3403 | |
3365 | #if EV_EMBED_ENABLE |
3404 | #if EV_EMBED_ENABLE |
3366 | void noinline |
3405 | void noinline |
3367 | ev_embed_sweep (EV_P_ ev_embed *w) |
3406 | ev_embed_sweep (EV_P_ ev_embed *w) |
3368 | { |
3407 | { |
… | |
… | |
3600 | { |
3639 | { |
3601 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3640 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3602 | |
3641 | |
3603 | if (expect_false (!once)) |
3642 | if (expect_false (!once)) |
3604 | { |
3643 | { |
3605 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
3644 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
3606 | return; |
3645 | return; |
3607 | } |
3646 | } |
3608 | |
3647 | |
3609 | once->cb = cb; |
3648 | once->cb = cb; |
3610 | once->arg = arg; |
3649 | once->arg = arg; |
… | |
… | |
3697 | if (types & EV_ASYNC) |
3736 | if (types & EV_ASYNC) |
3698 | for (i = asynccnt; i--; ) |
3737 | for (i = asynccnt; i--; ) |
3699 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3738 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3700 | #endif |
3739 | #endif |
3701 | |
3740 | |
|
|
3741 | #if EV_PREPARE_ENABLE |
3702 | if (types & EV_PREPARE) |
3742 | if (types & EV_PREPARE) |
3703 | for (i = preparecnt; i--; ) |
3743 | for (i = preparecnt; i--; ) |
3704 | #if EV_EMBED_ENABLE |
3744 | # if EV_EMBED_ENABLE |
3705 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3745 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3706 | #endif |
3746 | # endif |
3707 | cb (EV_A_ EV_PREPARE, prepares [i]); |
3747 | cb (EV_A_ EV_PREPARE, prepares [i]); |
|
|
3748 | #endif |
3708 | |
3749 | |
|
|
3750 | #if EV_CHECK_ENABLE |
3709 | if (types & EV_CHECK) |
3751 | if (types & EV_CHECK) |
3710 | for (i = checkcnt; i--; ) |
3752 | for (i = checkcnt; i--; ) |
3711 | cb (EV_A_ EV_CHECK, checks [i]); |
3753 | cb (EV_A_ EV_CHECK, checks [i]); |
|
|
3754 | #endif |
3712 | |
3755 | |
|
|
3756 | #if EV_SIGNAL_ENABLE |
3713 | if (types & EV_SIGNAL) |
3757 | if (types & EV_SIGNAL) |
3714 | for (i = 0; i < EV_NSIG - 1; ++i) |
3758 | for (i = 0; i < EV_NSIG - 1; ++i) |
3715 | for (wl = signals [i].head; wl; ) |
3759 | for (wl = signals [i].head; wl; ) |
3716 | { |
3760 | { |
3717 | wn = wl->next; |
3761 | wn = wl->next; |
3718 | cb (EV_A_ EV_SIGNAL, wl); |
3762 | cb (EV_A_ EV_SIGNAL, wl); |
3719 | wl = wn; |
3763 | wl = wn; |
3720 | } |
3764 | } |
|
|
3765 | #endif |
3721 | |
3766 | |
|
|
3767 | #if EV_CHILD_ENABLE |
3722 | if (types & EV_CHILD) |
3768 | if (types & EV_CHILD) |
3723 | for (i = EV_PID_HASHSIZE; i--; ) |
3769 | for (i = (EV_PID_HASHSIZE); i--; ) |
3724 | for (wl = childs [i]; wl; ) |
3770 | for (wl = childs [i]; wl; ) |
3725 | { |
3771 | { |
3726 | wn = wl->next; |
3772 | wn = wl->next; |
3727 | cb (EV_A_ EV_CHILD, wl); |
3773 | cb (EV_A_ EV_CHILD, wl); |
3728 | wl = wn; |
3774 | wl = wn; |
3729 | } |
3775 | } |
|
|
3776 | #endif |
3730 | /* EV_STAT 0x00001000 /* stat data changed */ |
3777 | /* EV_STAT 0x00001000 /* stat data changed */ |
3731 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3778 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3732 | } |
3779 | } |
3733 | #endif |
3780 | #endif |
3734 | |
3781 | |