… | |
… | |
77 | # ifndef EV_USE_REALTIME |
77 | # ifndef EV_USE_REALTIME |
78 | # define EV_USE_REALTIME 0 |
78 | # define EV_USE_REALTIME 0 |
79 | # endif |
79 | # endif |
80 | # endif |
80 | # endif |
81 | |
81 | |
|
|
82 | # if HAVE_NANOSLEEP |
82 | # ifndef EV_USE_NANOSLEEP |
83 | # ifndef EV_USE_NANOSLEEP |
83 | # if HAVE_NANOSLEEP |
|
|
84 | # define EV_USE_NANOSLEEP 1 |
84 | # define EV_USE_NANOSLEEP EV_FEATURE_OS |
|
|
85 | # endif |
85 | # else |
86 | # else |
|
|
87 | # undef EV_USE_NANOSLEEP |
86 | # define EV_USE_NANOSLEEP 0 |
88 | # define EV_USE_NANOSLEEP 0 |
|
|
89 | # endif |
|
|
90 | |
|
|
91 | # if HAVE_SELECT && HAVE_SYS_SELECT_H |
|
|
92 | # ifndef EV_USE_SELECT |
|
|
93 | # define EV_USE_SELECT EV_FEATURE_BACKENDS |
87 | # endif |
94 | # endif |
88 | # endif |
|
|
89 | |
|
|
90 | # ifndef EV_USE_SELECT |
|
|
91 | # if HAVE_SELECT && HAVE_SYS_SELECT_H |
|
|
92 | # define EV_USE_SELECT 1 |
|
|
93 | # else |
95 | # else |
|
|
96 | # undef EV_USE_SELECT |
94 | # define EV_USE_SELECT 0 |
97 | # define EV_USE_SELECT 0 |
|
|
98 | # endif |
|
|
99 | |
|
|
100 | # if HAVE_POLL && HAVE_POLL_H |
|
|
101 | # ifndef EV_USE_POLL |
|
|
102 | # define EV_USE_POLL EV_FEATURE_BACKENDS |
95 | # endif |
103 | # endif |
96 | # endif |
|
|
97 | |
|
|
98 | # ifndef EV_USE_POLL |
|
|
99 | # if HAVE_POLL && HAVE_POLL_H |
|
|
100 | # define EV_USE_POLL 1 |
|
|
101 | # else |
104 | # else |
|
|
105 | # undef EV_USE_POLL |
102 | # define EV_USE_POLL 0 |
106 | # define EV_USE_POLL 0 |
|
|
107 | # endif |
|
|
108 | |
|
|
109 | # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H |
|
|
110 | # ifndef EV_USE_EPOLL |
|
|
111 | # define EV_USE_EPOLL EV_FEATURE_BACKENDS |
103 | # endif |
112 | # endif |
|
|
113 | # else |
|
|
114 | # undef EV_USE_EPOLL |
|
|
115 | # define EV_USE_EPOLL 0 |
104 | # endif |
116 | # endif |
105 | |
117 | |
|
|
118 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
106 | # ifndef EV_USE_EPOLL |
119 | # ifndef EV_USE_KQUEUE |
107 | # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H |
120 | # define EV_USE_KQUEUE EV_FEATURE_BACKENDS |
108 | # define EV_USE_EPOLL 1 |
|
|
109 | # else |
|
|
110 | # define EV_USE_EPOLL 0 |
|
|
111 | # endif |
121 | # endif |
|
|
122 | # else |
|
|
123 | # undef EV_USE_KQUEUE |
|
|
124 | # define EV_USE_KQUEUE 0 |
112 | # endif |
125 | # endif |
113 | |
126 | |
114 | # ifndef EV_USE_KQUEUE |
127 | # if HAVE_PORT_H && HAVE_PORT_CREATE |
115 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
128 | # ifndef EV_USE_PORT |
116 | # define EV_USE_KQUEUE 1 |
129 | # define EV_USE_PORT EV_FEATURE_BACKENDS |
117 | # else |
|
|
118 | # define EV_USE_KQUEUE 0 |
|
|
119 | # endif |
130 | # endif |
120 | # endif |
|
|
121 | |
|
|
122 | # ifndef EV_USE_PORT |
|
|
123 | # if HAVE_PORT_H && HAVE_PORT_CREATE |
|
|
124 | # define EV_USE_PORT 1 |
|
|
125 | # else |
131 | # else |
|
|
132 | # undef EV_USE_PORT |
126 | # define EV_USE_PORT 0 |
133 | # define EV_USE_PORT 0 |
|
|
134 | # endif |
|
|
135 | |
|
|
136 | # if HAVE_INOTIFY_INIT && HAVE_SYS_INOTIFY_H |
|
|
137 | # ifndef EV_USE_INOTIFY |
|
|
138 | # define EV_USE_INOTIFY EV_FEATURE_OS |
127 | # endif |
139 | # endif |
128 | # endif |
|
|
129 | |
|
|
130 | # ifndef EV_USE_INOTIFY |
|
|
131 | # if HAVE_INOTIFY_INIT && HAVE_SYS_INOTIFY_H |
|
|
132 | # define EV_USE_INOTIFY 1 |
|
|
133 | # else |
140 | # else |
|
|
141 | # undef EV_USE_INOTIFY |
134 | # define EV_USE_INOTIFY 0 |
142 | # define EV_USE_INOTIFY 0 |
|
|
143 | # endif |
|
|
144 | |
|
|
145 | # if HAVE_SIGNALFD && HAVE_SYS_SIGNALFD_H |
|
|
146 | # ifndef EV_USE_SIGNALFD |
|
|
147 | # define EV_USE_SIGNALFD EV_FEATURE_OS |
135 | # endif |
148 | # endif |
136 | # endif |
|
|
137 | |
|
|
138 | # ifndef EV_USE_SIGNALFD |
|
|
139 | # if HAVE_SIGNALFD && HAVE_SYS_SIGNALFD_H |
|
|
140 | # define EV_USE_SIGNALFD 1 |
|
|
141 | # else |
149 | # else |
|
|
150 | # undef EV_USE_SIGNALFD |
142 | # define EV_USE_SIGNALFD 0 |
151 | # define EV_USE_SIGNALFD 0 |
|
|
152 | # endif |
|
|
153 | |
|
|
154 | # if HAVE_EVENTFD |
|
|
155 | # ifndef EV_USE_EVENTFD |
|
|
156 | # define EV_USE_EVENTFD EV_FEATURE_OS |
143 | # endif |
157 | # endif |
144 | # endif |
|
|
145 | |
|
|
146 | # ifndef EV_USE_EVENTFD |
|
|
147 | # if HAVE_EVENTFD |
|
|
148 | # define EV_USE_EVENTFD 1 |
|
|
149 | # else |
158 | # else |
|
|
159 | # undef EV_USE_EVENTFD |
150 | # define EV_USE_EVENTFD 0 |
160 | # define EV_USE_EVENTFD 0 |
151 | # endif |
|
|
152 | # endif |
161 | # endif |
153 | |
162 | |
154 | #endif |
163 | #endif |
155 | |
164 | |
156 | #include <math.h> |
165 | #include <math.h> |
… | |
… | |
184 | # define WIN32_LEAN_AND_MEAN |
193 | # define WIN32_LEAN_AND_MEAN |
185 | # include <windows.h> |
194 | # include <windows.h> |
186 | # ifndef EV_SELECT_IS_WINSOCKET |
195 | # ifndef EV_SELECT_IS_WINSOCKET |
187 | # define EV_SELECT_IS_WINSOCKET 1 |
196 | # define EV_SELECT_IS_WINSOCKET 1 |
188 | # endif |
197 | # endif |
|
|
198 | # undef EV_AVOID_STDIO |
189 | #endif |
199 | #endif |
190 | |
200 | |
191 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
201 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
192 | |
202 | |
193 | /* try to deduce the maximum number of signals on this platform */ |
203 | /* try to deduce the maximum number of signals on this platform */ |
… | |
… | |
206 | #elif defined (MAXSIG) |
216 | #elif defined (MAXSIG) |
207 | # define EV_NSIG (MAXSIG+1) |
217 | # define EV_NSIG (MAXSIG+1) |
208 | #elif defined (MAX_SIG) |
218 | #elif defined (MAX_SIG) |
209 | # define EV_NSIG (MAX_SIG+1) |
219 | # define EV_NSIG (MAX_SIG+1) |
210 | #elif defined (SIGARRAYSIZE) |
220 | #elif defined (SIGARRAYSIZE) |
211 | # define EV_NSIG SIGARRAYSIZE /* Assume ary[SIGARRAYSIZE] */ |
221 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
212 | #elif defined (_sys_nsig) |
222 | #elif defined (_sys_nsig) |
213 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
223 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
214 | #else |
224 | #else |
215 | # error "unable to find value for NSIG, please report" |
225 | # error "unable to find value for NSIG, please report" |
216 | /* to make it compile regardless, just remove the above line */ |
226 | /* to make it compile regardless, just remove the above line, */ |
|
|
227 | /* but consider reporting it, too! :) */ |
217 | # define EV_NSIG 65 |
228 | # define EV_NSIG 65 |
218 | #endif |
229 | #endif |
219 | |
230 | |
220 | #ifndef EV_USE_CLOCK_SYSCALL |
231 | #ifndef EV_USE_CLOCK_SYSCALL |
221 | # if __linux && __GLIBC__ >= 2 |
232 | # if __linux && __GLIBC__ >= 2 |
222 | # define EV_USE_CLOCK_SYSCALL 1 |
233 | # define EV_USE_CLOCK_SYSCALL EV_FEATURE_OS |
223 | # else |
234 | # else |
224 | # define EV_USE_CLOCK_SYSCALL 0 |
235 | # define EV_USE_CLOCK_SYSCALL 0 |
225 | # endif |
236 | # endif |
226 | #endif |
237 | #endif |
227 | |
238 | |
228 | #ifndef EV_USE_MONOTONIC |
239 | #ifndef EV_USE_MONOTONIC |
229 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
240 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
230 | # define EV_USE_MONOTONIC 1 |
241 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
231 | # else |
242 | # else |
232 | # define EV_USE_MONOTONIC 0 |
243 | # define EV_USE_MONOTONIC 0 |
233 | # endif |
244 | # endif |
234 | #endif |
245 | #endif |
235 | |
246 | |
… | |
… | |
237 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
248 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
238 | #endif |
249 | #endif |
239 | |
250 | |
240 | #ifndef EV_USE_NANOSLEEP |
251 | #ifndef EV_USE_NANOSLEEP |
241 | # if _POSIX_C_SOURCE >= 199309L |
252 | # if _POSIX_C_SOURCE >= 199309L |
242 | # define EV_USE_NANOSLEEP 1 |
253 | # define EV_USE_NANOSLEEP EV_FEATURE_OS |
243 | # else |
254 | # else |
244 | # define EV_USE_NANOSLEEP 0 |
255 | # define EV_USE_NANOSLEEP 0 |
245 | # endif |
256 | # endif |
246 | #endif |
257 | #endif |
247 | |
258 | |
248 | #ifndef EV_USE_SELECT |
259 | #ifndef EV_USE_SELECT |
249 | # define EV_USE_SELECT 1 |
260 | # define EV_USE_SELECT EV_FEATURE_BACKENDS |
250 | #endif |
261 | #endif |
251 | |
262 | |
252 | #ifndef EV_USE_POLL |
263 | #ifndef EV_USE_POLL |
253 | # ifdef _WIN32 |
264 | # ifdef _WIN32 |
254 | # define EV_USE_POLL 0 |
265 | # define EV_USE_POLL 0 |
255 | # else |
266 | # else |
256 | # define EV_USE_POLL 1 |
267 | # define EV_USE_POLL EV_FEATURE_BACKENDS |
257 | # endif |
268 | # endif |
258 | #endif |
269 | #endif |
259 | |
270 | |
260 | #ifndef EV_USE_EPOLL |
271 | #ifndef EV_USE_EPOLL |
261 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
272 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
262 | # define EV_USE_EPOLL 1 |
273 | # define EV_USE_EPOLL EV_FEATURE_BACKENDS |
263 | # else |
274 | # else |
264 | # define EV_USE_EPOLL 0 |
275 | # define EV_USE_EPOLL 0 |
265 | # endif |
276 | # endif |
266 | #endif |
277 | #endif |
267 | |
278 | |
… | |
… | |
273 | # define EV_USE_PORT 0 |
284 | # define EV_USE_PORT 0 |
274 | #endif |
285 | #endif |
275 | |
286 | |
276 | #ifndef EV_USE_INOTIFY |
287 | #ifndef EV_USE_INOTIFY |
277 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
288 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
278 | # define EV_USE_INOTIFY 1 |
289 | # define EV_USE_INOTIFY EV_FEATURE_OS |
279 | # else |
290 | # else |
280 | # define EV_USE_INOTIFY 0 |
291 | # define EV_USE_INOTIFY 0 |
281 | # endif |
292 | # endif |
282 | #endif |
293 | #endif |
283 | |
294 | |
284 | #ifndef EV_PID_HASHSIZE |
295 | #ifndef EV_PID_HASHSIZE |
285 | # if EV_MINIMAL |
296 | # 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 |
297 | #endif |
291 | |
298 | |
292 | #ifndef EV_INOTIFY_HASHSIZE |
299 | #ifndef EV_INOTIFY_HASHSIZE |
293 | # if EV_MINIMAL |
300 | # 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 |
301 | #endif |
299 | |
302 | |
300 | #ifndef EV_USE_EVENTFD |
303 | #ifndef EV_USE_EVENTFD |
301 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
304 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
302 | # define EV_USE_EVENTFD 1 |
305 | # define EV_USE_EVENTFD EV_FEATURE_OS |
303 | # else |
306 | # else |
304 | # define EV_USE_EVENTFD 0 |
307 | # define EV_USE_EVENTFD 0 |
305 | # endif |
308 | # endif |
306 | #endif |
309 | #endif |
307 | |
310 | |
308 | #ifndef EV_USE_SIGNALFD |
311 | #ifndef EV_USE_SIGNALFD |
309 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
312 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
310 | # define EV_USE_SIGNALFD 1 |
313 | # define EV_USE_SIGNALFD EV_FEATURE_OS |
311 | # else |
314 | # else |
312 | # define EV_USE_SIGNALFD 0 |
315 | # define EV_USE_SIGNALFD 0 |
313 | # endif |
316 | # endif |
314 | #endif |
317 | #endif |
315 | |
318 | |
… | |
… | |
318 | # define EV_USE_4HEAP 1 |
321 | # define EV_USE_4HEAP 1 |
319 | # define EV_HEAP_CACHE_AT 1 |
322 | # define EV_HEAP_CACHE_AT 1 |
320 | #endif |
323 | #endif |
321 | |
324 | |
322 | #ifndef EV_VERIFY |
325 | #ifndef EV_VERIFY |
323 | # define EV_VERIFY !EV_MINIMAL |
326 | # define EV_VERIFY (EV_FEATURE_API ? 1 : 0) |
324 | #endif |
327 | #endif |
325 | |
328 | |
326 | #ifndef EV_USE_4HEAP |
329 | #ifndef EV_USE_4HEAP |
327 | # define EV_USE_4HEAP !EV_MINIMAL |
330 | # define EV_USE_4HEAP EV_FEATURE_DATA |
328 | #endif |
331 | #endif |
329 | |
332 | |
330 | #ifndef EV_HEAP_CACHE_AT |
333 | #ifndef EV_HEAP_CACHE_AT |
331 | # define EV_HEAP_CACHE_AT !EV_MINIMAL |
334 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
332 | #endif |
335 | #endif |
333 | |
336 | |
334 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
337 | /* 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. */ |
338 | /* which makes programs even slower. might work on other unices, too. */ |
336 | #if EV_USE_CLOCK_SYSCALL |
339 | #if EV_USE_CLOCK_SYSCALL |
… | |
… | |
441 | |
444 | |
442 | |
445 | |
443 | /**/ |
446 | /**/ |
444 | |
447 | |
445 | #if EV_VERIFY >= 3 |
448 | #if EV_VERIFY >= 3 |
446 | # define EV_FREQUENT_CHECK ev_loop_verify (EV_A) |
449 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
447 | #else |
450 | #else |
448 | # define EV_FREQUENT_CHECK do { } while (0) |
451 | # define EV_FREQUENT_CHECK do { } while (0) |
449 | #endif |
452 | #endif |
450 | |
453 | |
451 | /* |
454 | /* |
… | |
… | |
474 | |
477 | |
475 | #define expect_false(expr) expect ((expr) != 0, 0) |
478 | #define expect_false(expr) expect ((expr) != 0, 0) |
476 | #define expect_true(expr) expect ((expr) != 0, 1) |
479 | #define expect_true(expr) expect ((expr) != 0, 1) |
477 | #define inline_size static inline |
480 | #define inline_size static inline |
478 | |
481 | |
479 | #if EV_MINIMAL |
482 | #if EV_FEATURE_CODE |
|
|
483 | # define inline_speed static inline |
|
|
484 | #else |
480 | # define inline_speed static noinline |
485 | # define inline_speed static noinline |
481 | #else |
|
|
482 | # define inline_speed static inline |
|
|
483 | #endif |
486 | #endif |
484 | |
487 | |
485 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
488 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
486 | |
489 | |
487 | #if EV_MINPRI == EV_MAXPRI |
490 | #if EV_MINPRI == EV_MAXPRI |
… | |
… | |
524 | # include "ev_win32.c" |
527 | # include "ev_win32.c" |
525 | #endif |
528 | #endif |
526 | |
529 | |
527 | /*****************************************************************************/ |
530 | /*****************************************************************************/ |
528 | |
531 | |
|
|
532 | #if EV_AVOID_STDIO |
|
|
533 | static void noinline |
|
|
534 | ev_printerr (const char *msg) |
|
|
535 | { |
|
|
536 | write (STDERR_FILENO, msg, strlen (msg)); |
|
|
537 | } |
|
|
538 | #endif |
|
|
539 | |
529 | static void (*syserr_cb)(const char *msg); |
540 | static void (*syserr_cb)(const char *msg); |
530 | |
541 | |
531 | void |
542 | void |
532 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
543 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
533 | { |
544 | { |
… | |
… | |
543 | if (syserr_cb) |
554 | if (syserr_cb) |
544 | syserr_cb (msg); |
555 | syserr_cb (msg); |
545 | else |
556 | else |
546 | { |
557 | { |
547 | #if EV_AVOID_STDIO |
558 | #if EV_AVOID_STDIO |
548 | write (STDERR_FILENO, msg, strlen (msg)); |
|
|
549 | write (STDERR_FILENO, ": ", 2); |
|
|
550 | msg = strerror (errno); |
559 | const char *err = strerror (errno); |
551 | write (STDERR_FILENO, msg, strlen (msg)); |
560 | |
552 | write (STDERR_FILENO, "\n", 1); |
561 | ev_printerr (msg); |
|
|
562 | ev_printerr (": "); |
|
|
563 | ev_printerr (err); |
|
|
564 | ev_printerr ("\n"); |
553 | #else |
565 | #else |
554 | perror (msg); |
566 | perror (msg); |
555 | #endif |
567 | #endif |
556 | abort (); |
568 | abort (); |
557 | } |
569 | } |
558 | } |
570 | } |
559 | |
571 | |
560 | static void * |
572 | static void * |
561 | ev_realloc_emul (void *ptr, long size) |
573 | ev_realloc_emul (void *ptr, long size) |
562 | { |
574 | { |
|
|
575 | #if __GLIBC__ |
|
|
576 | return realloc (ptr, size); |
|
|
577 | #else |
563 | /* some systems, notably openbsd and darwin, fail to properly |
578 | /* some systems, notably openbsd and darwin, fail to properly |
564 | * implement realloc (x, 0) (as required by both ansi c-98 and |
579 | * implement realloc (x, 0) (as required by both ansi c-89 and |
565 | * the single unix specification, so work around them here. |
580 | * the single unix specification, so work around them here. |
566 | */ |
581 | */ |
567 | |
582 | |
568 | if (size) |
583 | if (size) |
569 | return realloc (ptr, size); |
584 | return realloc (ptr, size); |
570 | |
585 | |
571 | free (ptr); |
586 | free (ptr); |
572 | return 0; |
587 | return 0; |
|
|
588 | #endif |
573 | } |
589 | } |
574 | |
590 | |
575 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
591 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
576 | |
592 | |
577 | void |
593 | void |
… | |
… | |
586 | ptr = alloc (ptr, size); |
602 | ptr = alloc (ptr, size); |
587 | |
603 | |
588 | if (!ptr && size) |
604 | if (!ptr && size) |
589 | { |
605 | { |
590 | #if EV_AVOID_STDIO |
606 | #if EV_AVOID_STDIO |
591 | write (STDERR_FILENO, "libev: memory allocation failed, aborting.", |
607 | ev_printerr ("libev: memory allocation failed, aborting.\n"); |
592 | sizeof ("libev: memory allocation failed, aborting.") - 1); |
|
|
593 | #else |
608 | #else |
594 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
609 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
595 | #endif |
610 | #endif |
596 | abort (); |
611 | abort (); |
597 | } |
612 | } |
… | |
… | |
682 | |
697 | |
683 | static int ev_default_loop_ptr; |
698 | static int ev_default_loop_ptr; |
684 | |
699 | |
685 | #endif |
700 | #endif |
686 | |
701 | |
687 | #if EV_MINIMAL < 2 |
702 | #if EV_FEATURE_API |
688 | # define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) |
703 | # 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) |
704 | # define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A) |
690 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
705 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
691 | #else |
706 | #else |
692 | # define EV_RELEASE_CB (void)0 |
707 | # define EV_RELEASE_CB (void)0 |
… | |
… | |
877 | } |
892 | } |
878 | |
893 | |
879 | /*****************************************************************************/ |
894 | /*****************************************************************************/ |
880 | |
895 | |
881 | inline_speed void |
896 | inline_speed void |
882 | fd_event_nc (EV_P_ int fd, int revents) |
897 | fd_event_nocheck (EV_P_ int fd, int revents) |
883 | { |
898 | { |
884 | ANFD *anfd = anfds + fd; |
899 | ANFD *anfd = anfds + fd; |
885 | ev_io *w; |
900 | ev_io *w; |
886 | |
901 | |
887 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
902 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
… | |
… | |
899 | fd_event (EV_P_ int fd, int revents) |
914 | fd_event (EV_P_ int fd, int revents) |
900 | { |
915 | { |
901 | ANFD *anfd = anfds + fd; |
916 | ANFD *anfd = anfds + fd; |
902 | |
917 | |
903 | if (expect_true (!anfd->reify)) |
918 | if (expect_true (!anfd->reify)) |
904 | fd_event_nc (EV_A_ fd, revents); |
919 | fd_event_nocheck (EV_A_ fd, revents); |
905 | } |
920 | } |
906 | |
921 | |
907 | void |
922 | void |
908 | ev_feed_fd_event (EV_P_ int fd, int revents) |
923 | ev_feed_fd_event (EV_P_ int fd, int revents) |
909 | { |
924 | { |
910 | if (fd >= 0 && fd < anfdmax) |
925 | if (fd >= 0 && fd < anfdmax) |
911 | fd_event_nc (EV_A_ fd, revents); |
926 | fd_event_nocheck (EV_A_ fd, revents); |
912 | } |
927 | } |
913 | |
928 | |
914 | /* make sure the external fd watch events are in-sync */ |
929 | /* make sure the external fd watch events are in-sync */ |
915 | /* with the kernel/libev internal state */ |
930 | /* with the kernel/libev internal state */ |
916 | inline_size void |
931 | inline_size void |
… | |
… | |
979 | ev_io_stop (EV_A_ w); |
994 | ev_io_stop (EV_A_ w); |
980 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
995 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
981 | } |
996 | } |
982 | } |
997 | } |
983 | |
998 | |
984 | /* check whether the given fd is atcually valid, for error recovery */ |
999 | /* check whether the given fd is actually valid, for error recovery */ |
985 | inline_size int |
1000 | inline_size int |
986 | fd_valid (int fd) |
1001 | fd_valid (int fd) |
987 | { |
1002 | { |
988 | #ifdef _WIN32 |
1003 | #ifdef _WIN32 |
989 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
1004 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
… | |
… | |
1029 | { |
1044 | { |
1030 | anfds [fd].events = 0; |
1045 | anfds [fd].events = 0; |
1031 | anfds [fd].emask = 0; |
1046 | anfds [fd].emask = 0; |
1032 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1047 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1033 | } |
1048 | } |
|
|
1049 | } |
|
|
1050 | |
|
|
1051 | /* used to prepare libev internal fd's */ |
|
|
1052 | /* this is not fork-safe */ |
|
|
1053 | inline_speed void |
|
|
1054 | fd_intern (int fd) |
|
|
1055 | { |
|
|
1056 | #ifdef _WIN32 |
|
|
1057 | unsigned long arg = 1; |
|
|
1058 | ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg); |
|
|
1059 | #else |
|
|
1060 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1061 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1062 | #endif |
1034 | } |
1063 | } |
1035 | |
1064 | |
1036 | /*****************************************************************************/ |
1065 | /*****************************************************************************/ |
1037 | |
1066 | |
1038 | /* |
1067 | /* |
… | |
… | |
1192 | |
1221 | |
1193 | static ANSIG signals [EV_NSIG - 1]; |
1222 | static ANSIG signals [EV_NSIG - 1]; |
1194 | |
1223 | |
1195 | /*****************************************************************************/ |
1224 | /*****************************************************************************/ |
1196 | |
1225 | |
1197 | /* used to prepare libev internal fd's */ |
1226 | #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 | |
1227 | |
1211 | static void noinline |
1228 | static void noinline |
1212 | evpipe_init (EV_P) |
1229 | evpipe_init (EV_P) |
1213 | { |
1230 | { |
1214 | if (!ev_is_active (&pipe_w)) |
1231 | if (!ev_is_active (&pipe_w)) |
1215 | { |
1232 | { |
1216 | #if EV_USE_EVENTFD |
1233 | # if EV_USE_EVENTFD |
1217 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1234 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1218 | if (evfd < 0 && errno == EINVAL) |
1235 | if (evfd < 0 && errno == EINVAL) |
1219 | evfd = eventfd (0, 0); |
1236 | evfd = eventfd (0, 0); |
1220 | |
1237 | |
1221 | if (evfd >= 0) |
1238 | if (evfd >= 0) |
… | |
… | |
1223 | evpipe [0] = -1; |
1240 | evpipe [0] = -1; |
1224 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1241 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1225 | ev_io_set (&pipe_w, evfd, EV_READ); |
1242 | ev_io_set (&pipe_w, evfd, EV_READ); |
1226 | } |
1243 | } |
1227 | else |
1244 | else |
1228 | #endif |
1245 | # endif |
1229 | { |
1246 | { |
1230 | while (pipe (evpipe)) |
1247 | while (pipe (evpipe)) |
1231 | ev_syserr ("(libev) error creating signal/async pipe"); |
1248 | ev_syserr ("(libev) error creating signal/async pipe"); |
1232 | |
1249 | |
1233 | fd_intern (evpipe [0]); |
1250 | fd_intern (evpipe [0]); |
… | |
… | |
1244 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1261 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1245 | { |
1262 | { |
1246 | if (!*flag) |
1263 | if (!*flag) |
1247 | { |
1264 | { |
1248 | int old_errno = errno; /* save errno because write might clobber it */ |
1265 | int old_errno = errno; /* save errno because write might clobber it */ |
|
|
1266 | char dummy; |
1249 | |
1267 | |
1250 | *flag = 1; |
1268 | *flag = 1; |
1251 | |
1269 | |
1252 | #if EV_USE_EVENTFD |
1270 | #if EV_USE_EVENTFD |
1253 | if (evfd >= 0) |
1271 | if (evfd >= 0) |
… | |
… | |
1255 | uint64_t counter = 1; |
1273 | uint64_t counter = 1; |
1256 | write (evfd, &counter, sizeof (uint64_t)); |
1274 | write (evfd, &counter, sizeof (uint64_t)); |
1257 | } |
1275 | } |
1258 | else |
1276 | else |
1259 | #endif |
1277 | #endif |
1260 | write (evpipe [1], &old_errno, 1); |
1278 | write (evpipe [1], &dummy, 1); |
1261 | |
1279 | |
1262 | errno = old_errno; |
1280 | errno = old_errno; |
1263 | } |
1281 | } |
1264 | } |
1282 | } |
1265 | |
1283 | |
… | |
… | |
1366 | break; |
1384 | break; |
1367 | } |
1385 | } |
1368 | } |
1386 | } |
1369 | #endif |
1387 | #endif |
1370 | |
1388 | |
|
|
1389 | #endif |
|
|
1390 | |
1371 | /*****************************************************************************/ |
1391 | /*****************************************************************************/ |
1372 | |
1392 | |
|
|
1393 | #if EV_CHILD_ENABLE |
1373 | static WL childs [EV_PID_HASHSIZE]; |
1394 | static WL childs [EV_PID_HASHSIZE]; |
1374 | |
|
|
1375 | #ifndef _WIN32 |
|
|
1376 | |
1395 | |
1377 | static ev_signal childev; |
1396 | static ev_signal childev; |
1378 | |
1397 | |
1379 | #ifndef WIFCONTINUED |
1398 | #ifndef WIFCONTINUED |
1380 | # define WIFCONTINUED(status) 0 |
1399 | # define WIFCONTINUED(status) 0 |
… | |
… | |
1385 | child_reap (EV_P_ int chain, int pid, int status) |
1404 | child_reap (EV_P_ int chain, int pid, int status) |
1386 | { |
1405 | { |
1387 | ev_child *w; |
1406 | ev_child *w; |
1388 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1407 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1389 | |
1408 | |
1390 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1409 | for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next) |
1391 | { |
1410 | { |
1392 | if ((w->pid == pid || !w->pid) |
1411 | if ((w->pid == pid || !w->pid) |
1393 | && (!traced || (w->flags & 1))) |
1412 | && (!traced || (w->flags & 1))) |
1394 | { |
1413 | { |
1395 | ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ |
1414 | 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 */ |
1439 | /* 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 */ |
1440 | /* 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); |
1441 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1423 | |
1442 | |
1424 | child_reap (EV_A_ pid, pid, status); |
1443 | child_reap (EV_A_ pid, pid, status); |
1425 | if (EV_PID_HASHSIZE > 1) |
1444 | if ((EV_PID_HASHSIZE) > 1) |
1426 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
1445 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
1427 | } |
1446 | } |
1428 | |
1447 | |
1429 | #endif |
1448 | #endif |
1430 | |
1449 | |
… | |
… | |
1497 | #ifdef __APPLE__ |
1516 | #ifdef __APPLE__ |
1498 | /* only select works correctly on that "unix-certified" platform */ |
1517 | /* only select works correctly on that "unix-certified" platform */ |
1499 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1518 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1500 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
1519 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
1501 | #endif |
1520 | #endif |
|
|
1521 | #ifdef __FreeBSD__ |
|
|
1522 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
|
|
1523 | #endif |
1502 | |
1524 | |
1503 | return flags; |
1525 | return flags; |
1504 | } |
1526 | } |
1505 | |
1527 | |
1506 | unsigned int |
1528 | unsigned int |
… | |
… | |
1519 | ev_backend (EV_P) |
1541 | ev_backend (EV_P) |
1520 | { |
1542 | { |
1521 | return backend; |
1543 | return backend; |
1522 | } |
1544 | } |
1523 | |
1545 | |
1524 | #if EV_MINIMAL < 2 |
1546 | #if EV_FEATURE_API |
1525 | unsigned int |
1547 | unsigned int |
1526 | ev_loop_count (EV_P) |
1548 | ev_iteration (EV_P) |
1527 | { |
1549 | { |
1528 | return loop_count; |
1550 | return loop_count; |
1529 | } |
1551 | } |
1530 | |
1552 | |
1531 | unsigned int |
1553 | unsigned int |
1532 | ev_loop_depth (EV_P) |
1554 | ev_depth (EV_P) |
1533 | { |
1555 | { |
1534 | return loop_depth; |
1556 | return loop_depth; |
1535 | } |
1557 | } |
1536 | |
1558 | |
1537 | void |
1559 | void |
… | |
… | |
1609 | |
1631 | |
1610 | ev_rt_now = ev_time (); |
1632 | ev_rt_now = ev_time (); |
1611 | mn_now = get_clock (); |
1633 | mn_now = get_clock (); |
1612 | now_floor = mn_now; |
1634 | now_floor = mn_now; |
1613 | rtmn_diff = ev_rt_now - mn_now; |
1635 | rtmn_diff = ev_rt_now - mn_now; |
1614 | #if EV_MINIMAL < 2 |
1636 | #if EV_FEATURE_API |
1615 | invoke_cb = ev_invoke_pending; |
1637 | invoke_cb = ev_invoke_pending; |
1616 | #endif |
1638 | #endif |
1617 | |
1639 | |
1618 | io_blocktime = 0.; |
1640 | io_blocktime = 0.; |
1619 | timeout_blocktime = 0.; |
1641 | timeout_blocktime = 0.; |
… | |
… | |
1649 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1671 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1650 | #endif |
1672 | #endif |
1651 | |
1673 | |
1652 | ev_prepare_init (&pending_w, pendingcb); |
1674 | ev_prepare_init (&pending_w, pendingcb); |
1653 | |
1675 | |
|
|
1676 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1654 | ev_init (&pipe_w, pipecb); |
1677 | ev_init (&pipe_w, pipecb); |
1655 | ev_set_priority (&pipe_w, EV_MAXPRI); |
1678 | ev_set_priority (&pipe_w, EV_MAXPRI); |
|
|
1679 | #endif |
1656 | } |
1680 | } |
1657 | } |
1681 | } |
1658 | |
1682 | |
1659 | /* free up a loop structure */ |
1683 | /* free up a loop structure */ |
1660 | static void noinline |
1684 | static void noinline |
… | |
… | |
1778 | { |
1802 | { |
1779 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1803 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1780 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1804 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1781 | } |
1805 | } |
1782 | |
1806 | |
|
|
1807 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1783 | evpipe_init (EV_A); |
1808 | evpipe_init (EV_A); |
1784 | /* now iterate over everything, in case we missed something */ |
1809 | /* now iterate over everything, in case we missed something */ |
1785 | pipecb (EV_A_ &pipe_w, EV_READ); |
1810 | pipecb (EV_A_ &pipe_w, EV_READ); |
|
|
1811 | #endif |
1786 | } |
1812 | } |
1787 | |
1813 | |
1788 | postfork = 0; |
1814 | postfork = 0; |
1789 | } |
1815 | } |
1790 | |
1816 | |
… | |
… | |
1852 | verify_watcher (EV_A_ ws [cnt]); |
1878 | verify_watcher (EV_A_ ws [cnt]); |
1853 | } |
1879 | } |
1854 | } |
1880 | } |
1855 | #endif |
1881 | #endif |
1856 | |
1882 | |
1857 | #if EV_MINIMAL < 2 |
1883 | #if EV_FEATURE_API |
1858 | void |
1884 | void |
1859 | ev_loop_verify (EV_P) |
1885 | ev_verify (EV_P) |
1860 | { |
1886 | { |
1861 | #if EV_VERIFY |
1887 | #if EV_VERIFY |
1862 | int i; |
1888 | int i; |
1863 | WL w; |
1889 | WL w; |
1864 | |
1890 | |
… | |
… | |
1903 | #if EV_ASYNC_ENABLE |
1929 | #if EV_ASYNC_ENABLE |
1904 | assert (asyncmax >= asynccnt); |
1930 | assert (asyncmax >= asynccnt); |
1905 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1931 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1906 | #endif |
1932 | #endif |
1907 | |
1933 | |
|
|
1934 | #if EV_PREPARE_ENABLE |
1908 | assert (preparemax >= preparecnt); |
1935 | assert (preparemax >= preparecnt); |
1909 | array_verify (EV_A_ (W *)prepares, preparecnt); |
1936 | array_verify (EV_A_ (W *)prepares, preparecnt); |
|
|
1937 | #endif |
1910 | |
1938 | |
|
|
1939 | #if EV_CHECK_ENABLE |
1911 | assert (checkmax >= checkcnt); |
1940 | assert (checkmax >= checkcnt); |
1912 | array_verify (EV_A_ (W *)checks, checkcnt); |
1941 | array_verify (EV_A_ (W *)checks, checkcnt); |
|
|
1942 | #endif |
1913 | |
1943 | |
1914 | # if 0 |
1944 | # if 0 |
|
|
1945 | #if EV_CHILD_ENABLE |
1915 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1946 | 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) |
1947 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
|
|
1948 | #endif |
1917 | # endif |
1949 | # endif |
1918 | #endif |
1950 | #endif |
1919 | } |
1951 | } |
1920 | #endif |
1952 | #endif |
1921 | |
1953 | |
… | |
… | |
1937 | |
1969 | |
1938 | loop_init (EV_A_ flags); |
1970 | loop_init (EV_A_ flags); |
1939 | |
1971 | |
1940 | if (ev_backend (EV_A)) |
1972 | if (ev_backend (EV_A)) |
1941 | { |
1973 | { |
1942 | #ifndef _WIN32 |
1974 | #if EV_CHILD_ENABLE |
1943 | ev_signal_init (&childev, childcb, SIGCHLD); |
1975 | ev_signal_init (&childev, childcb, SIGCHLD); |
1944 | ev_set_priority (&childev, EV_MAXPRI); |
1976 | ev_set_priority (&childev, EV_MAXPRI); |
1945 | ev_signal_start (EV_A_ &childev); |
1977 | ev_signal_start (EV_A_ &childev); |
1946 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1978 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1947 | #endif |
1979 | #endif |
… | |
… | |
1960 | EV_P = ev_default_loop_ptr; |
1992 | EV_P = ev_default_loop_ptr; |
1961 | #endif |
1993 | #endif |
1962 | |
1994 | |
1963 | ev_default_loop_ptr = 0; |
1995 | ev_default_loop_ptr = 0; |
1964 | |
1996 | |
1965 | #ifndef _WIN32 |
1997 | #if EV_CHILD_ENABLE |
1966 | ev_ref (EV_A); /* child watcher */ |
1998 | ev_ref (EV_A); /* child watcher */ |
1967 | ev_signal_stop (EV_A_ &childev); |
1999 | ev_signal_stop (EV_A_ &childev); |
1968 | #endif |
2000 | #endif |
1969 | |
2001 | |
1970 | loop_destroy (EV_A); |
2002 | loop_destroy (EV_A); |
… | |
… | |
2076 | EV_FREQUENT_CHECK; |
2108 | EV_FREQUENT_CHECK; |
2077 | feed_reverse (EV_A_ (W)w); |
2109 | feed_reverse (EV_A_ (W)w); |
2078 | } |
2110 | } |
2079 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2111 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2080 | |
2112 | |
2081 | feed_reverse_done (EV_A_ EV_TIMEOUT); |
2113 | feed_reverse_done (EV_A_ EV_TIMER); |
2082 | } |
2114 | } |
2083 | } |
2115 | } |
2084 | |
2116 | |
2085 | #if EV_PERIODIC_ENABLE |
2117 | #if EV_PERIODIC_ENABLE |
2086 | /* make periodics pending */ |
2118 | /* make periodics pending */ |
… | |
… | |
2247 | } |
2279 | } |
2248 | |
2280 | |
2249 | void |
2281 | void |
2250 | ev_loop (EV_P_ int flags) |
2282 | ev_loop (EV_P_ int flags) |
2251 | { |
2283 | { |
2252 | #if EV_MINIMAL < 2 |
2284 | #if EV_FEATURE_API |
2253 | ++loop_depth; |
2285 | ++loop_depth; |
2254 | #endif |
2286 | #endif |
2255 | |
2287 | |
2256 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2288 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2257 | |
2289 | |
… | |
… | |
2260 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2292 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2261 | |
2293 | |
2262 | do |
2294 | do |
2263 | { |
2295 | { |
2264 | #if EV_VERIFY >= 2 |
2296 | #if EV_VERIFY >= 2 |
2265 | ev_loop_verify (EV_A); |
2297 | ev_verify (EV_A); |
2266 | #endif |
2298 | #endif |
2267 | |
2299 | |
2268 | #ifndef _WIN32 |
2300 | #ifndef _WIN32 |
2269 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2301 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2270 | if (expect_false (getpid () != curpid)) |
2302 | if (expect_false (getpid () != curpid)) |
… | |
… | |
2282 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2314 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2283 | EV_INVOKE_PENDING; |
2315 | EV_INVOKE_PENDING; |
2284 | } |
2316 | } |
2285 | #endif |
2317 | #endif |
2286 | |
2318 | |
|
|
2319 | #if EV_PREPARE_ENABLE |
2287 | /* queue prepare watchers (and execute them) */ |
2320 | /* queue prepare watchers (and execute them) */ |
2288 | if (expect_false (preparecnt)) |
2321 | if (expect_false (preparecnt)) |
2289 | { |
2322 | { |
2290 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2323 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2291 | EV_INVOKE_PENDING; |
2324 | EV_INVOKE_PENDING; |
2292 | } |
2325 | } |
|
|
2326 | #endif |
2293 | |
2327 | |
2294 | if (expect_false (loop_done)) |
2328 | if (expect_false (loop_done)) |
2295 | break; |
2329 | break; |
2296 | |
2330 | |
2297 | /* we might have forked, so reify kernel state if necessary */ |
2331 | /* we might have forked, so reify kernel state if necessary */ |
… | |
… | |
2348 | waittime -= sleeptime; |
2382 | waittime -= sleeptime; |
2349 | } |
2383 | } |
2350 | } |
2384 | } |
2351 | } |
2385 | } |
2352 | |
2386 | |
2353 | #if EV_MINIMAL < 2 |
2387 | #if EV_FEATURE_API |
2354 | ++loop_count; |
2388 | ++loop_count; |
2355 | #endif |
2389 | #endif |
2356 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2390 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2357 | backend_poll (EV_A_ waittime); |
2391 | backend_poll (EV_A_ waittime); |
2358 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
2392 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
… | |
… | |
2370 | #if EV_IDLE_ENABLE |
2404 | #if EV_IDLE_ENABLE |
2371 | /* queue idle watchers unless other events are pending */ |
2405 | /* queue idle watchers unless other events are pending */ |
2372 | idle_reify (EV_A); |
2406 | idle_reify (EV_A); |
2373 | #endif |
2407 | #endif |
2374 | |
2408 | |
|
|
2409 | #if EV_CHECK_ENABLE |
2375 | /* queue check watchers, to be executed first */ |
2410 | /* queue check watchers, to be executed first */ |
2376 | if (expect_false (checkcnt)) |
2411 | if (expect_false (checkcnt)) |
2377 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
2412 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
|
|
2413 | #endif |
2378 | |
2414 | |
2379 | EV_INVOKE_PENDING; |
2415 | EV_INVOKE_PENDING; |
2380 | } |
2416 | } |
2381 | while (expect_true ( |
2417 | while (expect_true ( |
2382 | activecnt |
2418 | activecnt |
… | |
… | |
2385 | )); |
2421 | )); |
2386 | |
2422 | |
2387 | if (loop_done == EVUNLOOP_ONE) |
2423 | if (loop_done == EVUNLOOP_ONE) |
2388 | loop_done = EVUNLOOP_CANCEL; |
2424 | loop_done = EVUNLOOP_CANCEL; |
2389 | |
2425 | |
2390 | #if EV_MINIMAL < 2 |
2426 | #if EV_FEATURE_API |
2391 | --loop_depth; |
2427 | --loop_depth; |
2392 | #endif |
2428 | #endif |
2393 | } |
2429 | } |
2394 | |
2430 | |
2395 | void |
2431 | void |
… | |
… | |
2712 | |
2748 | |
2713 | #ifndef SA_RESTART |
2749 | #ifndef SA_RESTART |
2714 | # define SA_RESTART 0 |
2750 | # define SA_RESTART 0 |
2715 | #endif |
2751 | #endif |
2716 | |
2752 | |
|
|
2753 | #if EV_SIGNAL_ENABLE |
|
|
2754 | |
2717 | void noinline |
2755 | void noinline |
2718 | ev_signal_start (EV_P_ ev_signal *w) |
2756 | ev_signal_start (EV_P_ ev_signal *w) |
2719 | { |
2757 | { |
2720 | if (expect_false (ev_is_active (w))) |
2758 | if (expect_false (ev_is_active (w))) |
2721 | return; |
2759 | return; |
… | |
… | |
2827 | } |
2865 | } |
2828 | |
2866 | |
2829 | EV_FREQUENT_CHECK; |
2867 | EV_FREQUENT_CHECK; |
2830 | } |
2868 | } |
2831 | |
2869 | |
|
|
2870 | #endif |
|
|
2871 | |
|
|
2872 | #if EV_CHILD_ENABLE |
|
|
2873 | |
2832 | void |
2874 | void |
2833 | ev_child_start (EV_P_ ev_child *w) |
2875 | ev_child_start (EV_P_ ev_child *w) |
2834 | { |
2876 | { |
2835 | #if EV_MULTIPLICITY |
2877 | #if EV_MULTIPLICITY |
2836 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
2878 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
… | |
… | |
2839 | return; |
2881 | return; |
2840 | |
2882 | |
2841 | EV_FREQUENT_CHECK; |
2883 | EV_FREQUENT_CHECK; |
2842 | |
2884 | |
2843 | ev_start (EV_A_ (W)w, 1); |
2885 | ev_start (EV_A_ (W)w, 1); |
2844 | wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2886 | wlist_add (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2845 | |
2887 | |
2846 | EV_FREQUENT_CHECK; |
2888 | EV_FREQUENT_CHECK; |
2847 | } |
2889 | } |
2848 | |
2890 | |
2849 | void |
2891 | void |
… | |
… | |
2853 | if (expect_false (!ev_is_active (w))) |
2895 | if (expect_false (!ev_is_active (w))) |
2854 | return; |
2896 | return; |
2855 | |
2897 | |
2856 | EV_FREQUENT_CHECK; |
2898 | EV_FREQUENT_CHECK; |
2857 | |
2899 | |
2858 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2900 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2859 | ev_stop (EV_A_ (W)w); |
2901 | ev_stop (EV_A_ (W)w); |
2860 | |
2902 | |
2861 | EV_FREQUENT_CHECK; |
2903 | EV_FREQUENT_CHECK; |
2862 | } |
2904 | } |
|
|
2905 | |
|
|
2906 | #endif |
2863 | |
2907 | |
2864 | #if EV_STAT_ENABLE |
2908 | #if EV_STAT_ENABLE |
2865 | |
2909 | |
2866 | # ifdef _WIN32 |
2910 | # ifdef _WIN32 |
2867 | # undef lstat |
2911 | # undef lstat |
… | |
… | |
2934 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2978 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2935 | } |
2979 | } |
2936 | } |
2980 | } |
2937 | |
2981 | |
2938 | if (w->wd >= 0) |
2982 | if (w->wd >= 0) |
2939 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2983 | wlist_add (&fs_hash [w->wd & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
2940 | |
2984 | |
2941 | /* now re-arm timer, if required */ |
2985 | /* now re-arm timer, if required */ |
2942 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2986 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2943 | ev_timer_again (EV_A_ &w->timer); |
2987 | ev_timer_again (EV_A_ &w->timer); |
2944 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
2988 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
… | |
… | |
2952 | |
2996 | |
2953 | if (wd < 0) |
2997 | if (wd < 0) |
2954 | return; |
2998 | return; |
2955 | |
2999 | |
2956 | w->wd = -2; |
3000 | w->wd = -2; |
2957 | slot = wd & (EV_INOTIFY_HASHSIZE - 1); |
3001 | slot = wd & ((EV_INOTIFY_HASHSIZE) - 1); |
2958 | wlist_del (&fs_hash [slot].head, (WL)w); |
3002 | wlist_del (&fs_hash [slot].head, (WL)w); |
2959 | |
3003 | |
2960 | /* remove this watcher, if others are watching it, they will rearm */ |
3004 | /* remove this watcher, if others are watching it, they will rearm */ |
2961 | inotify_rm_watch (fs_fd, wd); |
3005 | inotify_rm_watch (fs_fd, wd); |
2962 | } |
3006 | } |
… | |
… | |
2964 | static void noinline |
3008 | static void noinline |
2965 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
3009 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
2966 | { |
3010 | { |
2967 | if (slot < 0) |
3011 | if (slot < 0) |
2968 | /* overflow, need to check for all hash slots */ |
3012 | /* overflow, need to check for all hash slots */ |
2969 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3013 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
2970 | infy_wd (EV_A_ slot, wd, ev); |
3014 | infy_wd (EV_A_ slot, wd, ev); |
2971 | else |
3015 | else |
2972 | { |
3016 | { |
2973 | WL w_; |
3017 | WL w_; |
2974 | |
3018 | |
2975 | for (w_ = fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head; w_; ) |
3019 | for (w_ = fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head; w_; ) |
2976 | { |
3020 | { |
2977 | ev_stat *w = (ev_stat *)w_; |
3021 | ev_stat *w = (ev_stat *)w_; |
2978 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
3022 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
2979 | |
3023 | |
2980 | if (w->wd == wd || wd == -1) |
3024 | if (w->wd == wd || wd == -1) |
2981 | { |
3025 | { |
2982 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
3026 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
2983 | { |
3027 | { |
2984 | wlist_del (&fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
3028 | wlist_del (&fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
2985 | w->wd = -1; |
3029 | w->wd = -1; |
2986 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3030 | infy_add (EV_A_ w); /* re-add, no matter what */ |
2987 | } |
3031 | } |
2988 | |
3032 | |
2989 | stat_timer_cb (EV_A_ &w->timer, 0); |
3033 | stat_timer_cb (EV_A_ &w->timer, 0); |
… | |
… | |
3103 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3147 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3104 | ev_io_start (EV_A_ &fs_w); |
3148 | ev_io_start (EV_A_ &fs_w); |
3105 | ev_unref (EV_A); |
3149 | ev_unref (EV_A); |
3106 | } |
3150 | } |
3107 | |
3151 | |
3108 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3152 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
3109 | { |
3153 | { |
3110 | WL w_ = fs_hash [slot].head; |
3154 | WL w_ = fs_hash [slot].head; |
3111 | fs_hash [slot].head = 0; |
3155 | fs_hash [slot].head = 0; |
3112 | |
3156 | |
3113 | while (w_) |
3157 | while (w_) |
… | |
… | |
3288 | |
3332 | |
3289 | EV_FREQUENT_CHECK; |
3333 | EV_FREQUENT_CHECK; |
3290 | } |
3334 | } |
3291 | #endif |
3335 | #endif |
3292 | |
3336 | |
|
|
3337 | #if EV_PREPARE_ENABLE |
3293 | void |
3338 | void |
3294 | ev_prepare_start (EV_P_ ev_prepare *w) |
3339 | ev_prepare_start (EV_P_ ev_prepare *w) |
3295 | { |
3340 | { |
3296 | if (expect_false (ev_is_active (w))) |
3341 | if (expect_false (ev_is_active (w))) |
3297 | return; |
3342 | return; |
… | |
… | |
3323 | |
3368 | |
3324 | ev_stop (EV_A_ (W)w); |
3369 | ev_stop (EV_A_ (W)w); |
3325 | |
3370 | |
3326 | EV_FREQUENT_CHECK; |
3371 | EV_FREQUENT_CHECK; |
3327 | } |
3372 | } |
|
|
3373 | #endif |
3328 | |
3374 | |
|
|
3375 | #if EV_CHECK_ENABLE |
3329 | void |
3376 | void |
3330 | ev_check_start (EV_P_ ev_check *w) |
3377 | ev_check_start (EV_P_ ev_check *w) |
3331 | { |
3378 | { |
3332 | if (expect_false (ev_is_active (w))) |
3379 | if (expect_false (ev_is_active (w))) |
3333 | return; |
3380 | return; |
… | |
… | |
3359 | |
3406 | |
3360 | ev_stop (EV_A_ (W)w); |
3407 | ev_stop (EV_A_ (W)w); |
3361 | |
3408 | |
3362 | EV_FREQUENT_CHECK; |
3409 | EV_FREQUENT_CHECK; |
3363 | } |
3410 | } |
|
|
3411 | #endif |
3364 | |
3412 | |
3365 | #if EV_EMBED_ENABLE |
3413 | #if EV_EMBED_ENABLE |
3366 | void noinline |
3414 | void noinline |
3367 | ev_embed_sweep (EV_P_ ev_embed *w) |
3415 | ev_embed_sweep (EV_P_ ev_embed *w) |
3368 | { |
3416 | { |
… | |
… | |
3600 | { |
3648 | { |
3601 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3649 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3602 | |
3650 | |
3603 | if (expect_false (!once)) |
3651 | if (expect_false (!once)) |
3604 | { |
3652 | { |
3605 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
3653 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
3606 | return; |
3654 | return; |
3607 | } |
3655 | } |
3608 | |
3656 | |
3609 | once->cb = cb; |
3657 | once->cb = cb; |
3610 | once->arg = arg; |
3658 | once->arg = arg; |
… | |
… | |
3697 | if (types & EV_ASYNC) |
3745 | if (types & EV_ASYNC) |
3698 | for (i = asynccnt; i--; ) |
3746 | for (i = asynccnt; i--; ) |
3699 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3747 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3700 | #endif |
3748 | #endif |
3701 | |
3749 | |
|
|
3750 | #if EV_PREPARE_ENABLE |
3702 | if (types & EV_PREPARE) |
3751 | if (types & EV_PREPARE) |
3703 | for (i = preparecnt; i--; ) |
3752 | for (i = preparecnt; i--; ) |
3704 | #if EV_EMBED_ENABLE |
3753 | # if EV_EMBED_ENABLE |
3705 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3754 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3706 | #endif |
3755 | # endif |
3707 | cb (EV_A_ EV_PREPARE, prepares [i]); |
3756 | cb (EV_A_ EV_PREPARE, prepares [i]); |
|
|
3757 | #endif |
3708 | |
3758 | |
|
|
3759 | #if EV_CHECK_ENABLE |
3709 | if (types & EV_CHECK) |
3760 | if (types & EV_CHECK) |
3710 | for (i = checkcnt; i--; ) |
3761 | for (i = checkcnt; i--; ) |
3711 | cb (EV_A_ EV_CHECK, checks [i]); |
3762 | cb (EV_A_ EV_CHECK, checks [i]); |
|
|
3763 | #endif |
3712 | |
3764 | |
|
|
3765 | #if EV_SIGNAL_ENABLE |
3713 | if (types & EV_SIGNAL) |
3766 | if (types & EV_SIGNAL) |
3714 | for (i = 0; i < EV_NSIG - 1; ++i) |
3767 | for (i = 0; i < EV_NSIG - 1; ++i) |
3715 | for (wl = signals [i].head; wl; ) |
3768 | for (wl = signals [i].head; wl; ) |
3716 | { |
3769 | { |
3717 | wn = wl->next; |
3770 | wn = wl->next; |
3718 | cb (EV_A_ EV_SIGNAL, wl); |
3771 | cb (EV_A_ EV_SIGNAL, wl); |
3719 | wl = wn; |
3772 | wl = wn; |
3720 | } |
3773 | } |
|
|
3774 | #endif |
3721 | |
3775 | |
|
|
3776 | #if EV_CHILD_ENABLE |
3722 | if (types & EV_CHILD) |
3777 | if (types & EV_CHILD) |
3723 | for (i = EV_PID_HASHSIZE; i--; ) |
3778 | for (i = (EV_PID_HASHSIZE); i--; ) |
3724 | for (wl = childs [i]; wl; ) |
3779 | for (wl = childs [i]; wl; ) |
3725 | { |
3780 | { |
3726 | wn = wl->next; |
3781 | wn = wl->next; |
3727 | cb (EV_A_ EV_CHILD, wl); |
3782 | cb (EV_A_ EV_CHILD, wl); |
3728 | wl = wn; |
3783 | wl = wn; |
3729 | } |
3784 | } |
|
|
3785 | #endif |
3730 | /* EV_STAT 0x00001000 /* stat data changed */ |
3786 | /* EV_STAT 0x00001000 /* stat data changed */ |
3731 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3787 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3732 | } |
3788 | } |
3733 | #endif |
3789 | #endif |
3734 | |
3790 | |