… | |
… | |
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 |
|
|
95 | # else |
|
|
96 | # undef EV_USE_SELECT |
|
|
97 | # define EV_USE_SELECT 0 |
88 | # endif |
98 | # endif |
89 | |
99 | |
|
|
100 | # if HAVE_POLL && HAVE_POLL_H |
90 | # ifndef EV_USE_SELECT |
101 | # ifndef EV_USE_POLL |
91 | # if HAVE_SELECT && HAVE_SYS_SELECT_H |
102 | # define EV_USE_POLL EV_FEATURE_BACKENDS |
92 | # define EV_USE_SELECT 1 |
|
|
93 | # else |
|
|
94 | # define EV_USE_SELECT 0 |
|
|
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 |
103 | # endif |
|
|
104 | # endif |
107 | # endif |
105 | |
108 | |
106 | # ifndef EV_USE_EPOLL |
|
|
107 | # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H |
109 | # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H |
108 | # define EV_USE_EPOLL 1 |
110 | # ifndef EV_USE_EPOLL |
109 | # else |
111 | # define EV_USE_EPOLL EV_FEATURE_BACKENDS |
110 | # define EV_USE_EPOLL 0 |
|
|
111 | # endif |
112 | # endif |
|
|
113 | # else |
|
|
114 | # undef EV_USE_EPOLL |
|
|
115 | # define EV_USE_EPOLL 0 |
112 | # endif |
116 | # endif |
113 | |
117 | |
114 | # ifndef EV_USE_KQUEUE |
|
|
115 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
118 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
116 | # define EV_USE_KQUEUE 1 |
119 | # ifndef EV_USE_KQUEUE |
117 | # else |
120 | # define EV_USE_KQUEUE EV_FEATURE_BACKENDS |
118 | # define EV_USE_KQUEUE 0 |
|
|
119 | # endif |
121 | # endif |
|
|
122 | # else |
|
|
123 | # undef EV_USE_KQUEUE |
|
|
124 | # define EV_USE_KQUEUE 0 |
120 | # endif |
125 | # endif |
121 | |
126 | |
122 | # ifndef EV_USE_PORT |
|
|
123 | # if HAVE_PORT_H && HAVE_PORT_CREATE |
127 | # if HAVE_PORT_H && HAVE_PORT_CREATE |
124 | # define EV_USE_PORT 1 |
128 | # ifndef EV_USE_PORT |
125 | # else |
129 | # define EV_USE_PORT EV_FEATURE_BACKENDS |
126 | # define EV_USE_PORT 0 |
|
|
127 | # endif |
130 | # endif |
|
|
131 | # else |
|
|
132 | # undef EV_USE_PORT |
|
|
133 | # define EV_USE_PORT 0 |
128 | # endif |
134 | # endif |
129 | |
135 | |
130 | # ifndef EV_USE_INOTIFY |
|
|
131 | # if HAVE_INOTIFY_INIT && HAVE_SYS_INOTIFY_H |
136 | # if HAVE_INOTIFY_INIT && HAVE_SYS_INOTIFY_H |
132 | # define EV_USE_INOTIFY 1 |
137 | # ifndef EV_USE_INOTIFY |
133 | # else |
|
|
134 | # define EV_USE_INOTIFY 0 |
138 | # define EV_USE_INOTIFY EV_FEATURE_OS |
135 | # endif |
139 | # endif |
|
|
140 | # else |
|
|
141 | # undef EV_USE_INOTIFY |
|
|
142 | # define EV_USE_INOTIFY 0 |
136 | # endif |
143 | # endif |
137 | |
144 | |
138 | # ifndef EV_USE_SIGNALFD |
|
|
139 | # if HAVE_SIGNALFD && HAVE_SYS_SIGNALFD_H |
145 | # if HAVE_SIGNALFD && HAVE_SYS_SIGNALFD_H |
140 | # define EV_USE_SIGNALFD 1 |
146 | # ifndef EV_USE_SIGNALFD |
141 | # else |
|
|
142 | # define EV_USE_SIGNALFD 0 |
147 | # define EV_USE_SIGNALFD EV_FEATURE_OS |
143 | # endif |
148 | # endif |
|
|
149 | # else |
|
|
150 | # undef EV_USE_SIGNALFD |
|
|
151 | # define EV_USE_SIGNALFD 0 |
144 | # endif |
152 | # endif |
145 | |
153 | |
|
|
154 | # if HAVE_EVENTFD |
146 | # ifndef EV_USE_EVENTFD |
155 | # ifndef EV_USE_EVENTFD |
147 | # if HAVE_EVENTFD |
|
|
148 | # define EV_USE_EVENTFD 1 |
156 | # define EV_USE_EVENTFD EV_FEATURE_OS |
149 | # else |
|
|
150 | # define EV_USE_EVENTFD 0 |
|
|
151 | # endif |
157 | # endif |
|
|
158 | # else |
|
|
159 | # undef EV_USE_EVENTFD |
|
|
160 | # define EV_USE_EVENTFD 0 |
152 | # endif |
161 | # endif |
153 | |
162 | |
154 | #endif |
163 | #endif |
155 | |
164 | |
156 | #include <math.h> |
165 | #include <math.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 |
189 | # undef EV_AVOID_STDIO |
198 | # undef EV_AVOID_STDIO |
190 | #endif |
199 | #endif |
|
|
200 | |
|
|
201 | /* OS X, in its infinite idiocy, actually HARDCODES |
|
|
202 | * a limit of 1024 into their select. Where people have brains, |
|
|
203 | * OS X engineers apparently have a vacuum. Or maybe they were |
|
|
204 | * ordered to have a vacuum, or they do anything for money. |
|
|
205 | * This might help. Or not. |
|
|
206 | */ |
|
|
207 | #define _DARWIN_UNLIMITED_SELECT 1 |
191 | |
208 | |
192 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
209 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
193 | |
210 | |
194 | /* try to deduce the maximum number of signals on this platform */ |
211 | /* try to deduce the maximum number of signals on this platform */ |
195 | #if defined (EV_NSIG) |
212 | #if defined (EV_NSIG) |
… | |
… | |
207 | #elif defined (MAXSIG) |
224 | #elif defined (MAXSIG) |
208 | # define EV_NSIG (MAXSIG+1) |
225 | # define EV_NSIG (MAXSIG+1) |
209 | #elif defined (MAX_SIG) |
226 | #elif defined (MAX_SIG) |
210 | # define EV_NSIG (MAX_SIG+1) |
227 | # define EV_NSIG (MAX_SIG+1) |
211 | #elif defined (SIGARRAYSIZE) |
228 | #elif defined (SIGARRAYSIZE) |
212 | # define EV_NSIG SIGARRAYSIZE /* Assume ary[SIGARRAYSIZE] */ |
229 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
213 | #elif defined (_sys_nsig) |
230 | #elif defined (_sys_nsig) |
214 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
231 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
215 | #else |
232 | #else |
216 | # error "unable to find value for NSIG, please report" |
233 | # error "unable to find value for NSIG, please report" |
217 | /* to make it compile regardless, just remove the above line */ |
234 | /* to make it compile regardless, just remove the above line, */ |
|
|
235 | /* but consider reporting it, too! :) */ |
218 | # define EV_NSIG 65 |
236 | # define EV_NSIG 65 |
219 | #endif |
237 | #endif |
220 | |
238 | |
221 | #ifndef EV_USE_CLOCK_SYSCALL |
239 | #ifndef EV_USE_CLOCK_SYSCALL |
222 | # if __linux && __GLIBC__ >= 2 |
240 | # if __linux && __GLIBC__ >= 2 |
223 | # define EV_USE_CLOCK_SYSCALL 1 |
241 | # define EV_USE_CLOCK_SYSCALL EV_FEATURE_OS |
224 | # else |
242 | # else |
225 | # define EV_USE_CLOCK_SYSCALL 0 |
243 | # define EV_USE_CLOCK_SYSCALL 0 |
226 | # endif |
244 | # endif |
227 | #endif |
245 | #endif |
228 | |
246 | |
229 | #ifndef EV_USE_MONOTONIC |
247 | #ifndef EV_USE_MONOTONIC |
230 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
248 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
231 | # define EV_USE_MONOTONIC 1 |
249 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
232 | # else |
250 | # else |
233 | # define EV_USE_MONOTONIC 0 |
251 | # define EV_USE_MONOTONIC 0 |
234 | # endif |
252 | # endif |
235 | #endif |
253 | #endif |
236 | |
254 | |
… | |
… | |
238 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
256 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
239 | #endif |
257 | #endif |
240 | |
258 | |
241 | #ifndef EV_USE_NANOSLEEP |
259 | #ifndef EV_USE_NANOSLEEP |
242 | # if _POSIX_C_SOURCE >= 199309L |
260 | # if _POSIX_C_SOURCE >= 199309L |
243 | # define EV_USE_NANOSLEEP 1 |
261 | # define EV_USE_NANOSLEEP EV_FEATURE_OS |
244 | # else |
262 | # else |
245 | # define EV_USE_NANOSLEEP 0 |
263 | # define EV_USE_NANOSLEEP 0 |
246 | # endif |
264 | # endif |
247 | #endif |
265 | #endif |
248 | |
266 | |
249 | #ifndef EV_USE_SELECT |
267 | #ifndef EV_USE_SELECT |
250 | # define EV_USE_SELECT 1 |
268 | # define EV_USE_SELECT EV_FEATURE_BACKENDS |
251 | #endif |
269 | #endif |
252 | |
270 | |
253 | #ifndef EV_USE_POLL |
271 | #ifndef EV_USE_POLL |
254 | # ifdef _WIN32 |
272 | # ifdef _WIN32 |
255 | # define EV_USE_POLL 0 |
273 | # define EV_USE_POLL 0 |
256 | # else |
274 | # else |
257 | # define EV_USE_POLL 1 |
275 | # define EV_USE_POLL EV_FEATURE_BACKENDS |
258 | # endif |
276 | # endif |
259 | #endif |
277 | #endif |
260 | |
278 | |
261 | #ifndef EV_USE_EPOLL |
279 | #ifndef EV_USE_EPOLL |
262 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
280 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
263 | # define EV_USE_EPOLL 1 |
281 | # define EV_USE_EPOLL EV_FEATURE_BACKENDS |
264 | # else |
282 | # else |
265 | # define EV_USE_EPOLL 0 |
283 | # define EV_USE_EPOLL 0 |
266 | # endif |
284 | # endif |
267 | #endif |
285 | #endif |
268 | |
286 | |
… | |
… | |
274 | # define EV_USE_PORT 0 |
292 | # define EV_USE_PORT 0 |
275 | #endif |
293 | #endif |
276 | |
294 | |
277 | #ifndef EV_USE_INOTIFY |
295 | #ifndef EV_USE_INOTIFY |
278 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
296 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
279 | # define EV_USE_INOTIFY 1 |
297 | # define EV_USE_INOTIFY EV_FEATURE_OS |
280 | # else |
298 | # else |
281 | # define EV_USE_INOTIFY 0 |
299 | # define EV_USE_INOTIFY 0 |
282 | # endif |
300 | # endif |
283 | #endif |
301 | #endif |
284 | |
302 | |
285 | #ifndef EV_PID_HASHSIZE |
303 | #ifndef EV_PID_HASHSIZE |
286 | # if EV_MINIMAL |
304 | # define EV_PID_HASHSIZE EV_FEATURE_DATA ? 16 : 1 |
287 | # define EV_PID_HASHSIZE 1 |
|
|
288 | # else |
|
|
289 | # define EV_PID_HASHSIZE 16 |
|
|
290 | # endif |
|
|
291 | #endif |
305 | #endif |
292 | |
306 | |
293 | #ifndef EV_INOTIFY_HASHSIZE |
307 | #ifndef EV_INOTIFY_HASHSIZE |
294 | # if EV_MINIMAL |
308 | # define EV_INOTIFY_HASHSIZE EV_FEATURE_DATA ? 16 : 1 |
295 | # define EV_INOTIFY_HASHSIZE 1 |
|
|
296 | # else |
|
|
297 | # define EV_INOTIFY_HASHSIZE 16 |
|
|
298 | # endif |
|
|
299 | #endif |
309 | #endif |
300 | |
310 | |
301 | #ifndef EV_USE_EVENTFD |
311 | #ifndef EV_USE_EVENTFD |
302 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
312 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
303 | # define EV_USE_EVENTFD 1 |
313 | # define EV_USE_EVENTFD EV_FEATURE_OS |
304 | # else |
314 | # else |
305 | # define EV_USE_EVENTFD 0 |
315 | # define EV_USE_EVENTFD 0 |
306 | # endif |
316 | # endif |
307 | #endif |
317 | #endif |
308 | |
318 | |
309 | #ifndef EV_USE_SIGNALFD |
319 | #ifndef EV_USE_SIGNALFD |
310 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
320 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
311 | # define EV_USE_SIGNALFD 1 |
321 | # define EV_USE_SIGNALFD EV_FEATURE_OS |
312 | # else |
322 | # else |
313 | # define EV_USE_SIGNALFD 0 |
323 | # define EV_USE_SIGNALFD 0 |
314 | # endif |
324 | # endif |
315 | #endif |
325 | #endif |
316 | |
326 | |
… | |
… | |
319 | # define EV_USE_4HEAP 1 |
329 | # define EV_USE_4HEAP 1 |
320 | # define EV_HEAP_CACHE_AT 1 |
330 | # define EV_HEAP_CACHE_AT 1 |
321 | #endif |
331 | #endif |
322 | |
332 | |
323 | #ifndef EV_VERIFY |
333 | #ifndef EV_VERIFY |
324 | # define EV_VERIFY !EV_MINIMAL |
334 | # define EV_VERIFY (EV_FEATURE_API ? 1 : 0) |
325 | #endif |
335 | #endif |
326 | |
336 | |
327 | #ifndef EV_USE_4HEAP |
337 | #ifndef EV_USE_4HEAP |
328 | # define EV_USE_4HEAP !EV_MINIMAL |
338 | # define EV_USE_4HEAP EV_FEATURE_DATA |
329 | #endif |
339 | #endif |
330 | |
340 | |
331 | #ifndef EV_HEAP_CACHE_AT |
341 | #ifndef EV_HEAP_CACHE_AT |
332 | # define EV_HEAP_CACHE_AT !EV_MINIMAL |
342 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
333 | #endif |
343 | #endif |
334 | |
344 | |
335 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
345 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
336 | /* which makes programs even slower. might work on other unices, too. */ |
346 | /* which makes programs even slower. might work on other unices, too. */ |
337 | #if EV_USE_CLOCK_SYSCALL |
347 | #if EV_USE_CLOCK_SYSCALL |
… | |
… | |
442 | |
452 | |
443 | |
453 | |
444 | /**/ |
454 | /**/ |
445 | |
455 | |
446 | #if EV_VERIFY >= 3 |
456 | #if EV_VERIFY >= 3 |
447 | # define EV_FREQUENT_CHECK ev_loop_verify (EV_A) |
457 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
448 | #else |
458 | #else |
449 | # define EV_FREQUENT_CHECK do { } while (0) |
459 | # define EV_FREQUENT_CHECK do { } while (0) |
450 | #endif |
460 | #endif |
451 | |
461 | |
452 | /* |
462 | /* |
… | |
… | |
475 | |
485 | |
476 | #define expect_false(expr) expect ((expr) != 0, 0) |
486 | #define expect_false(expr) expect ((expr) != 0, 0) |
477 | #define expect_true(expr) expect ((expr) != 0, 1) |
487 | #define expect_true(expr) expect ((expr) != 0, 1) |
478 | #define inline_size static inline |
488 | #define inline_size static inline |
479 | |
489 | |
480 | #if EV_MINIMAL |
490 | #if EV_FEATURE_CODE |
|
|
491 | # define inline_speed static inline |
|
|
492 | #else |
481 | # define inline_speed static noinline |
493 | # define inline_speed static noinline |
482 | #else |
|
|
483 | # define inline_speed static inline |
|
|
484 | #endif |
494 | #endif |
485 | |
495 | |
486 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
496 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
487 | |
497 | |
488 | #if EV_MINPRI == EV_MAXPRI |
498 | #if EV_MINPRI == EV_MAXPRI |
… | |
… | |
568 | } |
578 | } |
569 | |
579 | |
570 | static void * |
580 | static void * |
571 | ev_realloc_emul (void *ptr, long size) |
581 | ev_realloc_emul (void *ptr, long size) |
572 | { |
582 | { |
|
|
583 | #if __GLIBC__ |
|
|
584 | return realloc (ptr, size); |
|
|
585 | #else |
573 | /* some systems, notably openbsd and darwin, fail to properly |
586 | /* some systems, notably openbsd and darwin, fail to properly |
574 | * implement realloc (x, 0) (as required by both ansi c-98 and |
587 | * implement realloc (x, 0) (as required by both ansi c-89 and |
575 | * the single unix specification, so work around them here. |
588 | * the single unix specification, so work around them here. |
576 | */ |
589 | */ |
577 | |
590 | |
578 | if (size) |
591 | if (size) |
579 | return realloc (ptr, size); |
592 | return realloc (ptr, size); |
580 | |
593 | |
581 | free (ptr); |
594 | free (ptr); |
582 | return 0; |
595 | return 0; |
|
|
596 | #endif |
583 | } |
597 | } |
584 | |
598 | |
585 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
599 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
586 | |
600 | |
587 | void |
601 | void |
… | |
… | |
691 | |
705 | |
692 | static int ev_default_loop_ptr; |
706 | static int ev_default_loop_ptr; |
693 | |
707 | |
694 | #endif |
708 | #endif |
695 | |
709 | |
696 | #if EV_MINIMAL < 2 |
710 | #if EV_FEATURE_API |
697 | # define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) |
711 | # define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) |
698 | # define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A) |
712 | # define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A) |
699 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
713 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
700 | #else |
714 | #else |
701 | # define EV_RELEASE_CB (void)0 |
715 | # define EV_RELEASE_CB (void)0 |
… | |
… | |
886 | } |
900 | } |
887 | |
901 | |
888 | /*****************************************************************************/ |
902 | /*****************************************************************************/ |
889 | |
903 | |
890 | inline_speed void |
904 | inline_speed void |
891 | fd_event_nc (EV_P_ int fd, int revents) |
905 | fd_event_nocheck (EV_P_ int fd, int revents) |
892 | { |
906 | { |
893 | ANFD *anfd = anfds + fd; |
907 | ANFD *anfd = anfds + fd; |
894 | ev_io *w; |
908 | ev_io *w; |
895 | |
909 | |
896 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
910 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
… | |
… | |
908 | fd_event (EV_P_ int fd, int revents) |
922 | fd_event (EV_P_ int fd, int revents) |
909 | { |
923 | { |
910 | ANFD *anfd = anfds + fd; |
924 | ANFD *anfd = anfds + fd; |
911 | |
925 | |
912 | if (expect_true (!anfd->reify)) |
926 | if (expect_true (!anfd->reify)) |
913 | fd_event_nc (EV_A_ fd, revents); |
927 | fd_event_nocheck (EV_A_ fd, revents); |
914 | } |
928 | } |
915 | |
929 | |
916 | void |
930 | void |
917 | ev_feed_fd_event (EV_P_ int fd, int revents) |
931 | ev_feed_fd_event (EV_P_ int fd, int revents) |
918 | { |
932 | { |
919 | if (fd >= 0 && fd < anfdmax) |
933 | if (fd >= 0 && fd < anfdmax) |
920 | fd_event_nc (EV_A_ fd, revents); |
934 | fd_event_nocheck (EV_A_ fd, revents); |
921 | } |
935 | } |
922 | |
936 | |
923 | /* make sure the external fd watch events are in-sync */ |
937 | /* make sure the external fd watch events are in-sync */ |
924 | /* with the kernel/libev internal state */ |
938 | /* with the kernel/libev internal state */ |
925 | inline_size void |
939 | inline_size void |
… | |
… | |
988 | ev_io_stop (EV_A_ w); |
1002 | ev_io_stop (EV_A_ w); |
989 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
1003 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
990 | } |
1004 | } |
991 | } |
1005 | } |
992 | |
1006 | |
993 | /* check whether the given fd is atcually valid, for error recovery */ |
1007 | /* check whether the given fd is actually valid, for error recovery */ |
994 | inline_size int |
1008 | inline_size int |
995 | fd_valid (int fd) |
1009 | fd_valid (int fd) |
996 | { |
1010 | { |
997 | #ifdef _WIN32 |
1011 | #ifdef _WIN32 |
998 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
1012 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
… | |
… | |
1038 | { |
1052 | { |
1039 | anfds [fd].events = 0; |
1053 | anfds [fd].events = 0; |
1040 | anfds [fd].emask = 0; |
1054 | anfds [fd].emask = 0; |
1041 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1055 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1042 | } |
1056 | } |
|
|
1057 | } |
|
|
1058 | |
|
|
1059 | /* used to prepare libev internal fd's */ |
|
|
1060 | /* this is not fork-safe */ |
|
|
1061 | inline_speed void |
|
|
1062 | fd_intern (int fd) |
|
|
1063 | { |
|
|
1064 | #ifdef _WIN32 |
|
|
1065 | unsigned long arg = 1; |
|
|
1066 | ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg); |
|
|
1067 | #else |
|
|
1068 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1069 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1070 | #endif |
1043 | } |
1071 | } |
1044 | |
1072 | |
1045 | /*****************************************************************************/ |
1073 | /*****************************************************************************/ |
1046 | |
1074 | |
1047 | /* |
1075 | /* |
… | |
… | |
1201 | |
1229 | |
1202 | static ANSIG signals [EV_NSIG - 1]; |
1230 | static ANSIG signals [EV_NSIG - 1]; |
1203 | |
1231 | |
1204 | /*****************************************************************************/ |
1232 | /*****************************************************************************/ |
1205 | |
1233 | |
1206 | /* used to prepare libev internal fd's */ |
1234 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1207 | /* this is not fork-safe */ |
|
|
1208 | inline_speed void |
|
|
1209 | fd_intern (int fd) |
|
|
1210 | { |
|
|
1211 | #ifdef _WIN32 |
|
|
1212 | unsigned long arg = 1; |
|
|
1213 | ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg); |
|
|
1214 | #else |
|
|
1215 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1216 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1217 | #endif |
|
|
1218 | } |
|
|
1219 | |
1235 | |
1220 | static void noinline |
1236 | static void noinline |
1221 | evpipe_init (EV_P) |
1237 | evpipe_init (EV_P) |
1222 | { |
1238 | { |
1223 | if (!ev_is_active (&pipe_w)) |
1239 | if (!ev_is_active (&pipe_w)) |
1224 | { |
1240 | { |
1225 | #if EV_USE_EVENTFD |
1241 | # if EV_USE_EVENTFD |
1226 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1242 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1227 | if (evfd < 0 && errno == EINVAL) |
1243 | if (evfd < 0 && errno == EINVAL) |
1228 | evfd = eventfd (0, 0); |
1244 | evfd = eventfd (0, 0); |
1229 | |
1245 | |
1230 | if (evfd >= 0) |
1246 | if (evfd >= 0) |
… | |
… | |
1232 | evpipe [0] = -1; |
1248 | evpipe [0] = -1; |
1233 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1249 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1234 | ev_io_set (&pipe_w, evfd, EV_READ); |
1250 | ev_io_set (&pipe_w, evfd, EV_READ); |
1235 | } |
1251 | } |
1236 | else |
1252 | else |
1237 | #endif |
1253 | # endif |
1238 | { |
1254 | { |
1239 | while (pipe (evpipe)) |
1255 | while (pipe (evpipe)) |
1240 | ev_syserr ("(libev) error creating signal/async pipe"); |
1256 | ev_syserr ("(libev) error creating signal/async pipe"); |
1241 | |
1257 | |
1242 | fd_intern (evpipe [0]); |
1258 | fd_intern (evpipe [0]); |
… | |
… | |
1253 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1269 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1254 | { |
1270 | { |
1255 | if (!*flag) |
1271 | if (!*flag) |
1256 | { |
1272 | { |
1257 | int old_errno = errno; /* save errno because write might clobber it */ |
1273 | int old_errno = errno; /* save errno because write might clobber it */ |
|
|
1274 | char dummy; |
1258 | |
1275 | |
1259 | *flag = 1; |
1276 | *flag = 1; |
1260 | |
1277 | |
1261 | #if EV_USE_EVENTFD |
1278 | #if EV_USE_EVENTFD |
1262 | if (evfd >= 0) |
1279 | if (evfd >= 0) |
… | |
… | |
1264 | uint64_t counter = 1; |
1281 | uint64_t counter = 1; |
1265 | write (evfd, &counter, sizeof (uint64_t)); |
1282 | write (evfd, &counter, sizeof (uint64_t)); |
1266 | } |
1283 | } |
1267 | else |
1284 | else |
1268 | #endif |
1285 | #endif |
1269 | write (evpipe [1], &old_errno, 1); |
1286 | write (evpipe [1], &dummy, 1); |
1270 | |
1287 | |
1271 | errno = old_errno; |
1288 | errno = old_errno; |
1272 | } |
1289 | } |
1273 | } |
1290 | } |
1274 | |
1291 | |
… | |
… | |
1375 | break; |
1392 | break; |
1376 | } |
1393 | } |
1377 | } |
1394 | } |
1378 | #endif |
1395 | #endif |
1379 | |
1396 | |
|
|
1397 | #endif |
|
|
1398 | |
1380 | /*****************************************************************************/ |
1399 | /*****************************************************************************/ |
1381 | |
1400 | |
|
|
1401 | #if EV_CHILD_ENABLE |
1382 | static WL childs [EV_PID_HASHSIZE]; |
1402 | static WL childs [EV_PID_HASHSIZE]; |
1383 | |
|
|
1384 | #ifndef _WIN32 |
|
|
1385 | |
1403 | |
1386 | static ev_signal childev; |
1404 | static ev_signal childev; |
1387 | |
1405 | |
1388 | #ifndef WIFCONTINUED |
1406 | #ifndef WIFCONTINUED |
1389 | # define WIFCONTINUED(status) 0 |
1407 | # define WIFCONTINUED(status) 0 |
… | |
… | |
1394 | child_reap (EV_P_ int chain, int pid, int status) |
1412 | child_reap (EV_P_ int chain, int pid, int status) |
1395 | { |
1413 | { |
1396 | ev_child *w; |
1414 | ev_child *w; |
1397 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1415 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1398 | |
1416 | |
1399 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1417 | for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next) |
1400 | { |
1418 | { |
1401 | if ((w->pid == pid || !w->pid) |
1419 | if ((w->pid == pid || !w->pid) |
1402 | && (!traced || (w->flags & 1))) |
1420 | && (!traced || (w->flags & 1))) |
1403 | { |
1421 | { |
1404 | ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ |
1422 | ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ |
… | |
… | |
1429 | /* make sure we are called again until all children have been reaped */ |
1447 | /* make sure we are called again until all children have been reaped */ |
1430 | /* we need to do it this way so that the callback gets called before we continue */ |
1448 | /* we need to do it this way so that the callback gets called before we continue */ |
1431 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1449 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1432 | |
1450 | |
1433 | child_reap (EV_A_ pid, pid, status); |
1451 | child_reap (EV_A_ pid, pid, status); |
1434 | if (EV_PID_HASHSIZE > 1) |
1452 | if ((EV_PID_HASHSIZE) > 1) |
1435 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
1453 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
1436 | } |
1454 | } |
1437 | |
1455 | |
1438 | #endif |
1456 | #endif |
1439 | |
1457 | |
… | |
… | |
1506 | #ifdef __APPLE__ |
1524 | #ifdef __APPLE__ |
1507 | /* only select works correctly on that "unix-certified" platform */ |
1525 | /* only select works correctly on that "unix-certified" platform */ |
1508 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1526 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1509 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
1527 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
1510 | #endif |
1528 | #endif |
|
|
1529 | #ifdef __FreeBSD__ |
|
|
1530 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
|
|
1531 | #endif |
1511 | |
1532 | |
1512 | return flags; |
1533 | return flags; |
1513 | } |
1534 | } |
1514 | |
1535 | |
1515 | unsigned int |
1536 | unsigned int |
… | |
… | |
1528 | ev_backend (EV_P) |
1549 | ev_backend (EV_P) |
1529 | { |
1550 | { |
1530 | return backend; |
1551 | return backend; |
1531 | } |
1552 | } |
1532 | |
1553 | |
1533 | #if EV_MINIMAL < 2 |
1554 | #if EV_FEATURE_API |
1534 | unsigned int |
1555 | unsigned int |
1535 | ev_loop_count (EV_P) |
1556 | ev_iteration (EV_P) |
1536 | { |
1557 | { |
1537 | return loop_count; |
1558 | return loop_count; |
1538 | } |
1559 | } |
1539 | |
1560 | |
1540 | unsigned int |
1561 | unsigned int |
1541 | ev_loop_depth (EV_P) |
1562 | ev_depth (EV_P) |
1542 | { |
1563 | { |
1543 | return loop_depth; |
1564 | return loop_depth; |
1544 | } |
1565 | } |
1545 | |
1566 | |
1546 | void |
1567 | void |
… | |
… | |
1618 | |
1639 | |
1619 | ev_rt_now = ev_time (); |
1640 | ev_rt_now = ev_time (); |
1620 | mn_now = get_clock (); |
1641 | mn_now = get_clock (); |
1621 | now_floor = mn_now; |
1642 | now_floor = mn_now; |
1622 | rtmn_diff = ev_rt_now - mn_now; |
1643 | rtmn_diff = ev_rt_now - mn_now; |
1623 | #if EV_MINIMAL < 2 |
1644 | #if EV_FEATURE_API |
1624 | invoke_cb = ev_invoke_pending; |
1645 | invoke_cb = ev_invoke_pending; |
1625 | #endif |
1646 | #endif |
1626 | |
1647 | |
1627 | io_blocktime = 0.; |
1648 | io_blocktime = 0.; |
1628 | timeout_blocktime = 0.; |
1649 | timeout_blocktime = 0.; |
… | |
… | |
1658 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1679 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1659 | #endif |
1680 | #endif |
1660 | |
1681 | |
1661 | ev_prepare_init (&pending_w, pendingcb); |
1682 | ev_prepare_init (&pending_w, pendingcb); |
1662 | |
1683 | |
|
|
1684 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1663 | ev_init (&pipe_w, pipecb); |
1685 | ev_init (&pipe_w, pipecb); |
1664 | ev_set_priority (&pipe_w, EV_MAXPRI); |
1686 | ev_set_priority (&pipe_w, EV_MAXPRI); |
|
|
1687 | #endif |
1665 | } |
1688 | } |
1666 | } |
1689 | } |
1667 | |
1690 | |
1668 | /* free up a loop structure */ |
1691 | /* free up a loop structure */ |
1669 | static void noinline |
1692 | static void noinline |
… | |
… | |
1787 | { |
1810 | { |
1788 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1811 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1789 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1812 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1790 | } |
1813 | } |
1791 | |
1814 | |
|
|
1815 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1792 | evpipe_init (EV_A); |
1816 | evpipe_init (EV_A); |
1793 | /* now iterate over everything, in case we missed something */ |
1817 | /* now iterate over everything, in case we missed something */ |
1794 | pipecb (EV_A_ &pipe_w, EV_READ); |
1818 | pipecb (EV_A_ &pipe_w, EV_READ); |
|
|
1819 | #endif |
1795 | } |
1820 | } |
1796 | |
1821 | |
1797 | postfork = 0; |
1822 | postfork = 0; |
1798 | } |
1823 | } |
1799 | |
1824 | |
… | |
… | |
1861 | verify_watcher (EV_A_ ws [cnt]); |
1886 | verify_watcher (EV_A_ ws [cnt]); |
1862 | } |
1887 | } |
1863 | } |
1888 | } |
1864 | #endif |
1889 | #endif |
1865 | |
1890 | |
1866 | #if EV_MINIMAL < 2 |
1891 | #if EV_FEATURE_API |
1867 | void |
1892 | void |
1868 | ev_loop_verify (EV_P) |
1893 | ev_verify (EV_P) |
1869 | { |
1894 | { |
1870 | #if EV_VERIFY |
1895 | #if EV_VERIFY |
1871 | int i; |
1896 | int i; |
1872 | WL w; |
1897 | WL w; |
1873 | |
1898 | |
… | |
… | |
1912 | #if EV_ASYNC_ENABLE |
1937 | #if EV_ASYNC_ENABLE |
1913 | assert (asyncmax >= asynccnt); |
1938 | assert (asyncmax >= asynccnt); |
1914 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1939 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1915 | #endif |
1940 | #endif |
1916 | |
1941 | |
|
|
1942 | #if EV_PREPARE_ENABLE |
1917 | assert (preparemax >= preparecnt); |
1943 | assert (preparemax >= preparecnt); |
1918 | array_verify (EV_A_ (W *)prepares, preparecnt); |
1944 | array_verify (EV_A_ (W *)prepares, preparecnt); |
|
|
1945 | #endif |
1919 | |
1946 | |
|
|
1947 | #if EV_CHECK_ENABLE |
1920 | assert (checkmax >= checkcnt); |
1948 | assert (checkmax >= checkcnt); |
1921 | array_verify (EV_A_ (W *)checks, checkcnt); |
1949 | array_verify (EV_A_ (W *)checks, checkcnt); |
|
|
1950 | #endif |
1922 | |
1951 | |
1923 | # if 0 |
1952 | # if 0 |
|
|
1953 | #if EV_CHILD_ENABLE |
1924 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1954 | for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next) |
1925 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
1955 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
|
|
1956 | #endif |
1926 | # endif |
1957 | # endif |
1927 | #endif |
1958 | #endif |
1928 | } |
1959 | } |
1929 | #endif |
1960 | #endif |
1930 | |
1961 | |
… | |
… | |
1946 | |
1977 | |
1947 | loop_init (EV_A_ flags); |
1978 | loop_init (EV_A_ flags); |
1948 | |
1979 | |
1949 | if (ev_backend (EV_A)) |
1980 | if (ev_backend (EV_A)) |
1950 | { |
1981 | { |
1951 | #ifndef _WIN32 |
1982 | #if EV_CHILD_ENABLE |
1952 | ev_signal_init (&childev, childcb, SIGCHLD); |
1983 | ev_signal_init (&childev, childcb, SIGCHLD); |
1953 | ev_set_priority (&childev, EV_MAXPRI); |
1984 | ev_set_priority (&childev, EV_MAXPRI); |
1954 | ev_signal_start (EV_A_ &childev); |
1985 | ev_signal_start (EV_A_ &childev); |
1955 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1986 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1956 | #endif |
1987 | #endif |
… | |
… | |
1969 | EV_P = ev_default_loop_ptr; |
2000 | EV_P = ev_default_loop_ptr; |
1970 | #endif |
2001 | #endif |
1971 | |
2002 | |
1972 | ev_default_loop_ptr = 0; |
2003 | ev_default_loop_ptr = 0; |
1973 | |
2004 | |
1974 | #ifndef _WIN32 |
2005 | #if EV_CHILD_ENABLE |
1975 | ev_ref (EV_A); /* child watcher */ |
2006 | ev_ref (EV_A); /* child watcher */ |
1976 | ev_signal_stop (EV_A_ &childev); |
2007 | ev_signal_stop (EV_A_ &childev); |
1977 | #endif |
2008 | #endif |
1978 | |
2009 | |
1979 | loop_destroy (EV_A); |
2010 | loop_destroy (EV_A); |
… | |
… | |
2085 | EV_FREQUENT_CHECK; |
2116 | EV_FREQUENT_CHECK; |
2086 | feed_reverse (EV_A_ (W)w); |
2117 | feed_reverse (EV_A_ (W)w); |
2087 | } |
2118 | } |
2088 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2119 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2089 | |
2120 | |
2090 | feed_reverse_done (EV_A_ EV_TIMEOUT); |
2121 | feed_reverse_done (EV_A_ EV_TIMER); |
2091 | } |
2122 | } |
2092 | } |
2123 | } |
2093 | |
2124 | |
2094 | #if EV_PERIODIC_ENABLE |
2125 | #if EV_PERIODIC_ENABLE |
2095 | /* make periodics pending */ |
2126 | /* make periodics pending */ |
… | |
… | |
2256 | } |
2287 | } |
2257 | |
2288 | |
2258 | void |
2289 | void |
2259 | ev_loop (EV_P_ int flags) |
2290 | ev_loop (EV_P_ int flags) |
2260 | { |
2291 | { |
2261 | #if EV_MINIMAL < 2 |
2292 | #if EV_FEATURE_API |
2262 | ++loop_depth; |
2293 | ++loop_depth; |
2263 | #endif |
2294 | #endif |
2264 | |
2295 | |
2265 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2296 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2266 | |
2297 | |
… | |
… | |
2269 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2300 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2270 | |
2301 | |
2271 | do |
2302 | do |
2272 | { |
2303 | { |
2273 | #if EV_VERIFY >= 2 |
2304 | #if EV_VERIFY >= 2 |
2274 | ev_loop_verify (EV_A); |
2305 | ev_verify (EV_A); |
2275 | #endif |
2306 | #endif |
2276 | |
2307 | |
2277 | #ifndef _WIN32 |
2308 | #ifndef _WIN32 |
2278 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2309 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2279 | if (expect_false (getpid () != curpid)) |
2310 | if (expect_false (getpid () != curpid)) |
… | |
… | |
2291 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2322 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2292 | EV_INVOKE_PENDING; |
2323 | EV_INVOKE_PENDING; |
2293 | } |
2324 | } |
2294 | #endif |
2325 | #endif |
2295 | |
2326 | |
|
|
2327 | #if EV_PREPARE_ENABLE |
2296 | /* queue prepare watchers (and execute them) */ |
2328 | /* queue prepare watchers (and execute them) */ |
2297 | if (expect_false (preparecnt)) |
2329 | if (expect_false (preparecnt)) |
2298 | { |
2330 | { |
2299 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2331 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2300 | EV_INVOKE_PENDING; |
2332 | EV_INVOKE_PENDING; |
2301 | } |
2333 | } |
|
|
2334 | #endif |
2302 | |
2335 | |
2303 | if (expect_false (loop_done)) |
2336 | if (expect_false (loop_done)) |
2304 | break; |
2337 | break; |
2305 | |
2338 | |
2306 | /* we might have forked, so reify kernel state if necessary */ |
2339 | /* we might have forked, so reify kernel state if necessary */ |
… | |
… | |
2357 | waittime -= sleeptime; |
2390 | waittime -= sleeptime; |
2358 | } |
2391 | } |
2359 | } |
2392 | } |
2360 | } |
2393 | } |
2361 | |
2394 | |
2362 | #if EV_MINIMAL < 2 |
2395 | #if EV_FEATURE_API |
2363 | ++loop_count; |
2396 | ++loop_count; |
2364 | #endif |
2397 | #endif |
2365 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2398 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2366 | backend_poll (EV_A_ waittime); |
2399 | backend_poll (EV_A_ waittime); |
2367 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
2400 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
… | |
… | |
2379 | #if EV_IDLE_ENABLE |
2412 | #if EV_IDLE_ENABLE |
2380 | /* queue idle watchers unless other events are pending */ |
2413 | /* queue idle watchers unless other events are pending */ |
2381 | idle_reify (EV_A); |
2414 | idle_reify (EV_A); |
2382 | #endif |
2415 | #endif |
2383 | |
2416 | |
|
|
2417 | #if EV_CHECK_ENABLE |
2384 | /* queue check watchers, to be executed first */ |
2418 | /* queue check watchers, to be executed first */ |
2385 | if (expect_false (checkcnt)) |
2419 | if (expect_false (checkcnt)) |
2386 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
2420 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
|
|
2421 | #endif |
2387 | |
2422 | |
2388 | EV_INVOKE_PENDING; |
2423 | EV_INVOKE_PENDING; |
2389 | } |
2424 | } |
2390 | while (expect_true ( |
2425 | while (expect_true ( |
2391 | activecnt |
2426 | activecnt |
… | |
… | |
2394 | )); |
2429 | )); |
2395 | |
2430 | |
2396 | if (loop_done == EVUNLOOP_ONE) |
2431 | if (loop_done == EVUNLOOP_ONE) |
2397 | loop_done = EVUNLOOP_CANCEL; |
2432 | loop_done = EVUNLOOP_CANCEL; |
2398 | |
2433 | |
2399 | #if EV_MINIMAL < 2 |
2434 | #if EV_FEATURE_API |
2400 | --loop_depth; |
2435 | --loop_depth; |
2401 | #endif |
2436 | #endif |
2402 | } |
2437 | } |
2403 | |
2438 | |
2404 | void |
2439 | void |
… | |
… | |
2721 | |
2756 | |
2722 | #ifndef SA_RESTART |
2757 | #ifndef SA_RESTART |
2723 | # define SA_RESTART 0 |
2758 | # define SA_RESTART 0 |
2724 | #endif |
2759 | #endif |
2725 | |
2760 | |
|
|
2761 | #if EV_SIGNAL_ENABLE |
|
|
2762 | |
2726 | void noinline |
2763 | void noinline |
2727 | ev_signal_start (EV_P_ ev_signal *w) |
2764 | ev_signal_start (EV_P_ ev_signal *w) |
2728 | { |
2765 | { |
2729 | if (expect_false (ev_is_active (w))) |
2766 | if (expect_false (ev_is_active (w))) |
2730 | return; |
2767 | return; |
… | |
… | |
2836 | } |
2873 | } |
2837 | |
2874 | |
2838 | EV_FREQUENT_CHECK; |
2875 | EV_FREQUENT_CHECK; |
2839 | } |
2876 | } |
2840 | |
2877 | |
|
|
2878 | #endif |
|
|
2879 | |
|
|
2880 | #if EV_CHILD_ENABLE |
|
|
2881 | |
2841 | void |
2882 | void |
2842 | ev_child_start (EV_P_ ev_child *w) |
2883 | ev_child_start (EV_P_ ev_child *w) |
2843 | { |
2884 | { |
2844 | #if EV_MULTIPLICITY |
2885 | #if EV_MULTIPLICITY |
2845 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
2886 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
… | |
… | |
2848 | return; |
2889 | return; |
2849 | |
2890 | |
2850 | EV_FREQUENT_CHECK; |
2891 | EV_FREQUENT_CHECK; |
2851 | |
2892 | |
2852 | ev_start (EV_A_ (W)w, 1); |
2893 | ev_start (EV_A_ (W)w, 1); |
2853 | wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2894 | wlist_add (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2854 | |
2895 | |
2855 | EV_FREQUENT_CHECK; |
2896 | EV_FREQUENT_CHECK; |
2856 | } |
2897 | } |
2857 | |
2898 | |
2858 | void |
2899 | void |
… | |
… | |
2862 | if (expect_false (!ev_is_active (w))) |
2903 | if (expect_false (!ev_is_active (w))) |
2863 | return; |
2904 | return; |
2864 | |
2905 | |
2865 | EV_FREQUENT_CHECK; |
2906 | EV_FREQUENT_CHECK; |
2866 | |
2907 | |
2867 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2908 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2868 | ev_stop (EV_A_ (W)w); |
2909 | ev_stop (EV_A_ (W)w); |
2869 | |
2910 | |
2870 | EV_FREQUENT_CHECK; |
2911 | EV_FREQUENT_CHECK; |
2871 | } |
2912 | } |
|
|
2913 | |
|
|
2914 | #endif |
2872 | |
2915 | |
2873 | #if EV_STAT_ENABLE |
2916 | #if EV_STAT_ENABLE |
2874 | |
2917 | |
2875 | # ifdef _WIN32 |
2918 | # ifdef _WIN32 |
2876 | # undef lstat |
2919 | # undef lstat |
… | |
… | |
2943 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2986 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2944 | } |
2987 | } |
2945 | } |
2988 | } |
2946 | |
2989 | |
2947 | if (w->wd >= 0) |
2990 | if (w->wd >= 0) |
2948 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2991 | wlist_add (&fs_hash [w->wd & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
2949 | |
2992 | |
2950 | /* now re-arm timer, if required */ |
2993 | /* now re-arm timer, if required */ |
2951 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2994 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2952 | ev_timer_again (EV_A_ &w->timer); |
2995 | ev_timer_again (EV_A_ &w->timer); |
2953 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
2996 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
… | |
… | |
2961 | |
3004 | |
2962 | if (wd < 0) |
3005 | if (wd < 0) |
2963 | return; |
3006 | return; |
2964 | |
3007 | |
2965 | w->wd = -2; |
3008 | w->wd = -2; |
2966 | slot = wd & (EV_INOTIFY_HASHSIZE - 1); |
3009 | slot = wd & ((EV_INOTIFY_HASHSIZE) - 1); |
2967 | wlist_del (&fs_hash [slot].head, (WL)w); |
3010 | wlist_del (&fs_hash [slot].head, (WL)w); |
2968 | |
3011 | |
2969 | /* remove this watcher, if others are watching it, they will rearm */ |
3012 | /* remove this watcher, if others are watching it, they will rearm */ |
2970 | inotify_rm_watch (fs_fd, wd); |
3013 | inotify_rm_watch (fs_fd, wd); |
2971 | } |
3014 | } |
… | |
… | |
2973 | static void noinline |
3016 | static void noinline |
2974 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
3017 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
2975 | { |
3018 | { |
2976 | if (slot < 0) |
3019 | if (slot < 0) |
2977 | /* overflow, need to check for all hash slots */ |
3020 | /* overflow, need to check for all hash slots */ |
2978 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3021 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
2979 | infy_wd (EV_A_ slot, wd, ev); |
3022 | infy_wd (EV_A_ slot, wd, ev); |
2980 | else |
3023 | else |
2981 | { |
3024 | { |
2982 | WL w_; |
3025 | WL w_; |
2983 | |
3026 | |
2984 | for (w_ = fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head; w_; ) |
3027 | for (w_ = fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head; w_; ) |
2985 | { |
3028 | { |
2986 | ev_stat *w = (ev_stat *)w_; |
3029 | ev_stat *w = (ev_stat *)w_; |
2987 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
3030 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
2988 | |
3031 | |
2989 | if (w->wd == wd || wd == -1) |
3032 | if (w->wd == wd || wd == -1) |
2990 | { |
3033 | { |
2991 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
3034 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
2992 | { |
3035 | { |
2993 | wlist_del (&fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
3036 | wlist_del (&fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
2994 | w->wd = -1; |
3037 | w->wd = -1; |
2995 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3038 | infy_add (EV_A_ w); /* re-add, no matter what */ |
2996 | } |
3039 | } |
2997 | |
3040 | |
2998 | stat_timer_cb (EV_A_ &w->timer, 0); |
3041 | stat_timer_cb (EV_A_ &w->timer, 0); |
… | |
… | |
3112 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3155 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3113 | ev_io_start (EV_A_ &fs_w); |
3156 | ev_io_start (EV_A_ &fs_w); |
3114 | ev_unref (EV_A); |
3157 | ev_unref (EV_A); |
3115 | } |
3158 | } |
3116 | |
3159 | |
3117 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3160 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
3118 | { |
3161 | { |
3119 | WL w_ = fs_hash [slot].head; |
3162 | WL w_ = fs_hash [slot].head; |
3120 | fs_hash [slot].head = 0; |
3163 | fs_hash [slot].head = 0; |
3121 | |
3164 | |
3122 | while (w_) |
3165 | while (w_) |
… | |
… | |
3297 | |
3340 | |
3298 | EV_FREQUENT_CHECK; |
3341 | EV_FREQUENT_CHECK; |
3299 | } |
3342 | } |
3300 | #endif |
3343 | #endif |
3301 | |
3344 | |
|
|
3345 | #if EV_PREPARE_ENABLE |
3302 | void |
3346 | void |
3303 | ev_prepare_start (EV_P_ ev_prepare *w) |
3347 | ev_prepare_start (EV_P_ ev_prepare *w) |
3304 | { |
3348 | { |
3305 | if (expect_false (ev_is_active (w))) |
3349 | if (expect_false (ev_is_active (w))) |
3306 | return; |
3350 | return; |
… | |
… | |
3332 | |
3376 | |
3333 | ev_stop (EV_A_ (W)w); |
3377 | ev_stop (EV_A_ (W)w); |
3334 | |
3378 | |
3335 | EV_FREQUENT_CHECK; |
3379 | EV_FREQUENT_CHECK; |
3336 | } |
3380 | } |
|
|
3381 | #endif |
3337 | |
3382 | |
|
|
3383 | #if EV_CHECK_ENABLE |
3338 | void |
3384 | void |
3339 | ev_check_start (EV_P_ ev_check *w) |
3385 | ev_check_start (EV_P_ ev_check *w) |
3340 | { |
3386 | { |
3341 | if (expect_false (ev_is_active (w))) |
3387 | if (expect_false (ev_is_active (w))) |
3342 | return; |
3388 | return; |
… | |
… | |
3368 | |
3414 | |
3369 | ev_stop (EV_A_ (W)w); |
3415 | ev_stop (EV_A_ (W)w); |
3370 | |
3416 | |
3371 | EV_FREQUENT_CHECK; |
3417 | EV_FREQUENT_CHECK; |
3372 | } |
3418 | } |
|
|
3419 | #endif |
3373 | |
3420 | |
3374 | #if EV_EMBED_ENABLE |
3421 | #if EV_EMBED_ENABLE |
3375 | void noinline |
3422 | void noinline |
3376 | ev_embed_sweep (EV_P_ ev_embed *w) |
3423 | ev_embed_sweep (EV_P_ ev_embed *w) |
3377 | { |
3424 | { |
… | |
… | |
3609 | { |
3656 | { |
3610 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3657 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3611 | |
3658 | |
3612 | if (expect_false (!once)) |
3659 | if (expect_false (!once)) |
3613 | { |
3660 | { |
3614 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
3661 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
3615 | return; |
3662 | return; |
3616 | } |
3663 | } |
3617 | |
3664 | |
3618 | once->cb = cb; |
3665 | once->cb = cb; |
3619 | once->arg = arg; |
3666 | once->arg = arg; |
… | |
… | |
3706 | if (types & EV_ASYNC) |
3753 | if (types & EV_ASYNC) |
3707 | for (i = asynccnt; i--; ) |
3754 | for (i = asynccnt; i--; ) |
3708 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3755 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3709 | #endif |
3756 | #endif |
3710 | |
3757 | |
|
|
3758 | #if EV_PREPARE_ENABLE |
3711 | if (types & EV_PREPARE) |
3759 | if (types & EV_PREPARE) |
3712 | for (i = preparecnt; i--; ) |
3760 | for (i = preparecnt; i--; ) |
3713 | #if EV_EMBED_ENABLE |
3761 | # if EV_EMBED_ENABLE |
3714 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3762 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3715 | #endif |
3763 | # endif |
3716 | cb (EV_A_ EV_PREPARE, prepares [i]); |
3764 | cb (EV_A_ EV_PREPARE, prepares [i]); |
|
|
3765 | #endif |
3717 | |
3766 | |
|
|
3767 | #if EV_CHECK_ENABLE |
3718 | if (types & EV_CHECK) |
3768 | if (types & EV_CHECK) |
3719 | for (i = checkcnt; i--; ) |
3769 | for (i = checkcnt; i--; ) |
3720 | cb (EV_A_ EV_CHECK, checks [i]); |
3770 | cb (EV_A_ EV_CHECK, checks [i]); |
|
|
3771 | #endif |
3721 | |
3772 | |
|
|
3773 | #if EV_SIGNAL_ENABLE |
3722 | if (types & EV_SIGNAL) |
3774 | if (types & EV_SIGNAL) |
3723 | for (i = 0; i < EV_NSIG - 1; ++i) |
3775 | for (i = 0; i < EV_NSIG - 1; ++i) |
3724 | for (wl = signals [i].head; wl; ) |
3776 | for (wl = signals [i].head; wl; ) |
3725 | { |
3777 | { |
3726 | wn = wl->next; |
3778 | wn = wl->next; |
3727 | cb (EV_A_ EV_SIGNAL, wl); |
3779 | cb (EV_A_ EV_SIGNAL, wl); |
3728 | wl = wn; |
3780 | wl = wn; |
3729 | } |
3781 | } |
|
|
3782 | #endif |
3730 | |
3783 | |
|
|
3784 | #if EV_CHILD_ENABLE |
3731 | if (types & EV_CHILD) |
3785 | if (types & EV_CHILD) |
3732 | for (i = EV_PID_HASHSIZE; i--; ) |
3786 | for (i = (EV_PID_HASHSIZE); i--; ) |
3733 | for (wl = childs [i]; wl; ) |
3787 | for (wl = childs [i]; wl; ) |
3734 | { |
3788 | { |
3735 | wn = wl->next; |
3789 | wn = wl->next; |
3736 | cb (EV_A_ EV_CHILD, wl); |
3790 | cb (EV_A_ EV_CHILD, wl); |
3737 | wl = wn; |
3791 | wl = wn; |
3738 | } |
3792 | } |
|
|
3793 | #endif |
3739 | /* EV_STAT 0x00001000 /* stat data changed */ |
3794 | /* EV_STAT 0x00001000 /* stat data changed */ |
3740 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3795 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3741 | } |
3796 | } |
3742 | #endif |
3797 | #endif |
3743 | |
3798 | |