… | |
… | |
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 |
… | |
… | |
438 | # ifdef __cplusplus |
448 | # ifdef __cplusplus |
439 | } |
449 | } |
440 | # endif |
450 | # endif |
441 | #endif |
451 | #endif |
442 | |
452 | |
443 | |
|
|
444 | /**/ |
453 | /**/ |
445 | |
454 | |
446 | #if EV_VERIFY >= 3 |
455 | #if EV_VERIFY >= 3 |
447 | # define EV_FREQUENT_CHECK ev_loop_verify (EV_A) |
456 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
448 | #else |
457 | #else |
449 | # define EV_FREQUENT_CHECK do { } while (0) |
458 | # define EV_FREQUENT_CHECK do { } while (0) |
450 | #endif |
459 | #endif |
451 | |
460 | |
452 | /* |
461 | /* |
… | |
… | |
460 | #define TIME_EPSILON 0.0001220703125 /* 1/8192 */ |
469 | #define TIME_EPSILON 0.0001220703125 /* 1/8192 */ |
461 | |
470 | |
462 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
471 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
463 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
472 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
464 | |
473 | |
|
|
474 | #define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0) |
|
|
475 | #define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9); } while (0) |
|
|
476 | |
465 | #if __GNUC__ >= 4 |
477 | #if __GNUC__ >= 4 |
466 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
478 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
467 | # define noinline __attribute__ ((noinline)) |
479 | # define noinline __attribute__ ((noinline)) |
468 | #else |
480 | #else |
469 | # define expect(expr,value) (expr) |
481 | # define expect(expr,value) (expr) |
… | |
… | |
475 | |
487 | |
476 | #define expect_false(expr) expect ((expr) != 0, 0) |
488 | #define expect_false(expr) expect ((expr) != 0, 0) |
477 | #define expect_true(expr) expect ((expr) != 0, 1) |
489 | #define expect_true(expr) expect ((expr) != 0, 1) |
478 | #define inline_size static inline |
490 | #define inline_size static inline |
479 | |
491 | |
480 | #if EV_MINIMAL |
492 | #if EV_FEATURE_CODE |
|
|
493 | # define inline_speed static inline |
|
|
494 | #else |
481 | # define inline_speed static noinline |
495 | # define inline_speed static noinline |
482 | #else |
|
|
483 | # define inline_speed static inline |
|
|
484 | #endif |
496 | #endif |
485 | |
497 | |
486 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
498 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
487 | |
499 | |
488 | #if EV_MINPRI == EV_MAXPRI |
500 | #if EV_MINPRI == EV_MAXPRI |
… | |
… | |
501 | #define ev_active(w) ((W)(w))->active |
513 | #define ev_active(w) ((W)(w))->active |
502 | #define ev_at(w) ((WT)(w))->at |
514 | #define ev_at(w) ((WT)(w))->at |
503 | |
515 | |
504 | #if EV_USE_REALTIME |
516 | #if EV_USE_REALTIME |
505 | /* sig_atomic_t is used to avoid per-thread variables or locking but still */ |
517 | /* sig_atomic_t is used to avoid per-thread variables or locking but still */ |
506 | /* giving it a reasonably high chance of working on typical architetcures */ |
518 | /* giving it a reasonably high chance of working on typical architectures */ |
507 | static EV_ATOMIC_T have_realtime; /* did clock_gettime (CLOCK_REALTIME) work? */ |
519 | static EV_ATOMIC_T have_realtime; /* did clock_gettime (CLOCK_REALTIME) work? */ |
508 | #endif |
520 | #endif |
509 | |
521 | |
510 | #if EV_USE_MONOTONIC |
522 | #if EV_USE_MONOTONIC |
511 | static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
523 | static EV_ATOMIC_T have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
… | |
… | |
572 | { |
584 | { |
573 | #if __GLIBC__ |
585 | #if __GLIBC__ |
574 | return realloc (ptr, size); |
586 | return realloc (ptr, size); |
575 | #else |
587 | #else |
576 | /* some systems, notably openbsd and darwin, fail to properly |
588 | /* some systems, notably openbsd and darwin, fail to properly |
577 | * implement realloc (x, 0) (as required by both ansi c-98 and |
589 | * implement realloc (x, 0) (as required by both ansi c-89 and |
578 | * the single unix specification, so work around them here. |
590 | * the single unix specification, so work around them here. |
579 | */ |
591 | */ |
580 | |
592 | |
581 | if (size) |
593 | if (size) |
582 | return realloc (ptr, size); |
594 | return realloc (ptr, size); |
… | |
… | |
695 | |
707 | |
696 | static int ev_default_loop_ptr; |
708 | static int ev_default_loop_ptr; |
697 | |
709 | |
698 | #endif |
710 | #endif |
699 | |
711 | |
700 | #if EV_MINIMAL < 2 |
712 | #if EV_FEATURE_API |
701 | # define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) |
713 | # define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) |
702 | # define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A) |
714 | # define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A) |
703 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
715 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
704 | #else |
716 | #else |
705 | # define EV_RELEASE_CB (void)0 |
717 | # define EV_RELEASE_CB (void)0 |
… | |
… | |
759 | if (delay > 0.) |
771 | if (delay > 0.) |
760 | { |
772 | { |
761 | #if EV_USE_NANOSLEEP |
773 | #if EV_USE_NANOSLEEP |
762 | struct timespec ts; |
774 | struct timespec ts; |
763 | |
775 | |
764 | ts.tv_sec = (time_t)delay; |
776 | EV_TS_SET (ts, delay); |
765 | ts.tv_nsec = (long)((delay - (ev_tstamp)(ts.tv_sec)) * 1e9); |
|
|
766 | |
|
|
767 | nanosleep (&ts, 0); |
777 | nanosleep (&ts, 0); |
768 | #elif defined(_WIN32) |
778 | #elif defined(_WIN32) |
769 | Sleep ((unsigned long)(delay * 1e3)); |
779 | Sleep ((unsigned long)(delay * 1e3)); |
770 | #else |
780 | #else |
771 | struct timeval tv; |
781 | struct timeval tv; |
772 | |
782 | |
773 | tv.tv_sec = (time_t)delay; |
|
|
774 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
|
|
775 | |
|
|
776 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
783 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
777 | /* something not guaranteed by newer posix versions, but guaranteed */ |
784 | /* something not guaranteed by newer posix versions, but guaranteed */ |
778 | /* by older ones */ |
785 | /* by older ones */ |
|
|
786 | EV_TV_SET (tv, delay); |
779 | select (0, 0, 0, 0, &tv); |
787 | select (0, 0, 0, 0, &tv); |
780 | #endif |
788 | #endif |
781 | } |
789 | } |
782 | } |
790 | } |
783 | |
791 | |
784 | /*****************************************************************************/ |
792 | /*****************************************************************************/ |
785 | |
793 | |
786 | #define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ |
794 | #define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ |
787 | |
795 | |
788 | /* find a suitable new size for the given array, */ |
796 | /* find a suitable new size for the given array, */ |
789 | /* hopefully by rounding to a ncie-to-malloc size */ |
797 | /* hopefully by rounding to a nice-to-malloc size */ |
790 | inline_size int |
798 | inline_size int |
791 | array_nextsize (int elem, int cur, int cnt) |
799 | array_nextsize (int elem, int cur, int cnt) |
792 | { |
800 | { |
793 | int ncur = cur + 1; |
801 | int ncur = cur + 1; |
794 | |
802 | |
… | |
… | |
890 | } |
898 | } |
891 | |
899 | |
892 | /*****************************************************************************/ |
900 | /*****************************************************************************/ |
893 | |
901 | |
894 | inline_speed void |
902 | inline_speed void |
895 | fd_event_nc (EV_P_ int fd, int revents) |
903 | fd_event_nocheck (EV_P_ int fd, int revents) |
896 | { |
904 | { |
897 | ANFD *anfd = anfds + fd; |
905 | ANFD *anfd = anfds + fd; |
898 | ev_io *w; |
906 | ev_io *w; |
899 | |
907 | |
900 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
908 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
… | |
… | |
912 | fd_event (EV_P_ int fd, int revents) |
920 | fd_event (EV_P_ int fd, int revents) |
913 | { |
921 | { |
914 | ANFD *anfd = anfds + fd; |
922 | ANFD *anfd = anfds + fd; |
915 | |
923 | |
916 | if (expect_true (!anfd->reify)) |
924 | if (expect_true (!anfd->reify)) |
917 | fd_event_nc (EV_A_ fd, revents); |
925 | fd_event_nocheck (EV_A_ fd, revents); |
918 | } |
926 | } |
919 | |
927 | |
920 | void |
928 | void |
921 | ev_feed_fd_event (EV_P_ int fd, int revents) |
929 | ev_feed_fd_event (EV_P_ int fd, int revents) |
922 | { |
930 | { |
923 | if (fd >= 0 && fd < anfdmax) |
931 | if (fd >= 0 && fd < anfdmax) |
924 | fd_event_nc (EV_A_ fd, revents); |
932 | fd_event_nocheck (EV_A_ fd, revents); |
925 | } |
933 | } |
926 | |
934 | |
927 | /* make sure the external fd watch events are in-sync */ |
935 | /* make sure the external fd watch events are in-sync */ |
928 | /* with the kernel/libev internal state */ |
936 | /* with the kernel/libev internal state */ |
929 | inline_size void |
937 | inline_size void |
… | |
… | |
935 | { |
943 | { |
936 | int fd = fdchanges [i]; |
944 | int fd = fdchanges [i]; |
937 | ANFD *anfd = anfds + fd; |
945 | ANFD *anfd = anfds + fd; |
938 | ev_io *w; |
946 | ev_io *w; |
939 | |
947 | |
940 | unsigned char events = 0; |
948 | unsigned char o_events = anfd->events; |
|
|
949 | unsigned char o_reify = anfd->reify; |
941 | |
950 | |
942 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
951 | anfd->reify = 0; |
943 | events |= (unsigned char)w->events; |
|
|
944 | |
952 | |
945 | #if EV_SELECT_IS_WINSOCKET |
953 | #if EV_SELECT_IS_WINSOCKET |
946 | if (events) |
954 | if (o_reify & EV__IOFDSET) |
947 | { |
955 | { |
948 | unsigned long arg; |
956 | unsigned long arg; |
949 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
957 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
950 | assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
958 | assert (("libev: only socket fds supported in this configuration", ioctlsocket (anfd->handle, FIONREAD, &arg) == 0)); |
951 | } |
959 | } |
952 | #endif |
960 | #endif |
953 | |
961 | |
|
|
962 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
954 | { |
963 | { |
955 | unsigned char o_events = anfd->events; |
|
|
956 | unsigned char o_reify = anfd->reify; |
|
|
957 | |
|
|
958 | anfd->reify = 0; |
|
|
959 | anfd->events = events; |
964 | anfd->events = 0; |
960 | |
965 | |
961 | if (o_events != events || o_reify & EV__IOFDSET) |
966 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
|
|
967 | anfd->events |= (unsigned char)w->events; |
|
|
968 | |
|
|
969 | if (o_events != anfd->events) |
|
|
970 | o_reify = EV__IOFDSET; /* actually |= */ |
|
|
971 | } |
|
|
972 | |
|
|
973 | if (o_reify & EV__IOFDSET) |
962 | backend_modify (EV_A_ fd, o_events, events); |
974 | backend_modify (EV_A_ fd, o_events, anfd->events); |
963 | } |
|
|
964 | } |
975 | } |
965 | |
976 | |
966 | fdchangecnt = 0; |
977 | fdchangecnt = 0; |
967 | } |
978 | } |
968 | |
979 | |
… | |
… | |
992 | ev_io_stop (EV_A_ w); |
1003 | ev_io_stop (EV_A_ w); |
993 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
1004 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
994 | } |
1005 | } |
995 | } |
1006 | } |
996 | |
1007 | |
997 | /* check whether the given fd is atcually valid, for error recovery */ |
1008 | /* check whether the given fd is actually valid, for error recovery */ |
998 | inline_size int |
1009 | inline_size int |
999 | fd_valid (int fd) |
1010 | fd_valid (int fd) |
1000 | { |
1011 | { |
1001 | #ifdef _WIN32 |
1012 | #ifdef _WIN32 |
1002 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
1013 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
… | |
… | |
1044 | anfds [fd].emask = 0; |
1055 | anfds [fd].emask = 0; |
1045 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1056 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1046 | } |
1057 | } |
1047 | } |
1058 | } |
1048 | |
1059 | |
|
|
1060 | /* used to prepare libev internal fd's */ |
|
|
1061 | /* this is not fork-safe */ |
|
|
1062 | inline_speed void |
|
|
1063 | fd_intern (int fd) |
|
|
1064 | { |
|
|
1065 | #ifdef _WIN32 |
|
|
1066 | unsigned long arg = 1; |
|
|
1067 | ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg); |
|
|
1068 | #else |
|
|
1069 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1070 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1071 | #endif |
|
|
1072 | } |
|
|
1073 | |
1049 | /*****************************************************************************/ |
1074 | /*****************************************************************************/ |
1050 | |
1075 | |
1051 | /* |
1076 | /* |
1052 | * the heap functions want a real array index. array index 0 uis guaranteed to not |
1077 | * the heap functions want a real array index. array index 0 is guaranteed to not |
1053 | * be in-use at any time. the first heap entry is at array [HEAP0]. DHEAP gives |
1078 | * be in-use at any time. the first heap entry is at array [HEAP0]. DHEAP gives |
1054 | * the branching factor of the d-tree. |
1079 | * the branching factor of the d-tree. |
1055 | */ |
1080 | */ |
1056 | |
1081 | |
1057 | /* |
1082 | /* |
… | |
… | |
1205 | |
1230 | |
1206 | static ANSIG signals [EV_NSIG - 1]; |
1231 | static ANSIG signals [EV_NSIG - 1]; |
1207 | |
1232 | |
1208 | /*****************************************************************************/ |
1233 | /*****************************************************************************/ |
1209 | |
1234 | |
1210 | /* used to prepare libev internal fd's */ |
1235 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1211 | /* this is not fork-safe */ |
|
|
1212 | inline_speed void |
|
|
1213 | fd_intern (int fd) |
|
|
1214 | { |
|
|
1215 | #ifdef _WIN32 |
|
|
1216 | unsigned long arg = 1; |
|
|
1217 | ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg); |
|
|
1218 | #else |
|
|
1219 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1220 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1221 | #endif |
|
|
1222 | } |
|
|
1223 | |
1236 | |
1224 | static void noinline |
1237 | static void noinline |
1225 | evpipe_init (EV_P) |
1238 | evpipe_init (EV_P) |
1226 | { |
1239 | { |
1227 | if (!ev_is_active (&pipe_w)) |
1240 | if (!ev_is_active (&pipe_w)) |
1228 | { |
1241 | { |
1229 | #if EV_USE_EVENTFD |
1242 | # if EV_USE_EVENTFD |
1230 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1243 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1231 | if (evfd < 0 && errno == EINVAL) |
1244 | if (evfd < 0 && errno == EINVAL) |
1232 | evfd = eventfd (0, 0); |
1245 | evfd = eventfd (0, 0); |
1233 | |
1246 | |
1234 | if (evfd >= 0) |
1247 | if (evfd >= 0) |
… | |
… | |
1236 | evpipe [0] = -1; |
1249 | evpipe [0] = -1; |
1237 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1250 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1238 | ev_io_set (&pipe_w, evfd, EV_READ); |
1251 | ev_io_set (&pipe_w, evfd, EV_READ); |
1239 | } |
1252 | } |
1240 | else |
1253 | else |
1241 | #endif |
1254 | # endif |
1242 | { |
1255 | { |
1243 | while (pipe (evpipe)) |
1256 | while (pipe (evpipe)) |
1244 | ev_syserr ("(libev) error creating signal/async pipe"); |
1257 | ev_syserr ("(libev) error creating signal/async pipe"); |
1245 | |
1258 | |
1246 | fd_intern (evpipe [0]); |
1259 | fd_intern (evpipe [0]); |
… | |
… | |
1257 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1270 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1258 | { |
1271 | { |
1259 | if (!*flag) |
1272 | if (!*flag) |
1260 | { |
1273 | { |
1261 | int old_errno = errno; /* save errno because write might clobber it */ |
1274 | int old_errno = errno; /* save errno because write might clobber it */ |
|
|
1275 | char dummy; |
1262 | |
1276 | |
1263 | *flag = 1; |
1277 | *flag = 1; |
1264 | |
1278 | |
1265 | #if EV_USE_EVENTFD |
1279 | #if EV_USE_EVENTFD |
1266 | if (evfd >= 0) |
1280 | if (evfd >= 0) |
… | |
… | |
1268 | uint64_t counter = 1; |
1282 | uint64_t counter = 1; |
1269 | write (evfd, &counter, sizeof (uint64_t)); |
1283 | write (evfd, &counter, sizeof (uint64_t)); |
1270 | } |
1284 | } |
1271 | else |
1285 | else |
1272 | #endif |
1286 | #endif |
|
|
1287 | /* win32 people keep sending patches that change this write() to send() */ |
|
|
1288 | /* and then run away. but send() is wrong, it wants a socket handle on win32 */ |
|
|
1289 | /* so when you think this write should be a send instead, please find out */ |
|
|
1290 | /* where your send() is from - it's definitely not the microsoft send, and */ |
|
|
1291 | /* tell me. thank you. */ |
1273 | write (evpipe [1], &old_errno, 1); |
1292 | write (evpipe [1], &dummy, 1); |
1274 | |
1293 | |
1275 | errno = old_errno; |
1294 | errno = old_errno; |
1276 | } |
1295 | } |
1277 | } |
1296 | } |
1278 | |
1297 | |
… | |
… | |
1291 | } |
1310 | } |
1292 | else |
1311 | else |
1293 | #endif |
1312 | #endif |
1294 | { |
1313 | { |
1295 | char dummy; |
1314 | char dummy; |
|
|
1315 | /* see discussion in evpipe_write when you think this read should be recv in win32 */ |
1296 | read (evpipe [0], &dummy, 1); |
1316 | read (evpipe [0], &dummy, 1); |
1297 | } |
1317 | } |
1298 | |
1318 | |
1299 | if (sig_pending) |
1319 | if (sig_pending) |
1300 | { |
1320 | { |
… | |
… | |
1379 | break; |
1399 | break; |
1380 | } |
1400 | } |
1381 | } |
1401 | } |
1382 | #endif |
1402 | #endif |
1383 | |
1403 | |
|
|
1404 | #endif |
|
|
1405 | |
1384 | /*****************************************************************************/ |
1406 | /*****************************************************************************/ |
1385 | |
1407 | |
|
|
1408 | #if EV_CHILD_ENABLE |
1386 | static WL childs [EV_PID_HASHSIZE]; |
1409 | static WL childs [EV_PID_HASHSIZE]; |
1387 | |
|
|
1388 | #ifndef _WIN32 |
|
|
1389 | |
1410 | |
1390 | static ev_signal childev; |
1411 | static ev_signal childev; |
1391 | |
1412 | |
1392 | #ifndef WIFCONTINUED |
1413 | #ifndef WIFCONTINUED |
1393 | # define WIFCONTINUED(status) 0 |
1414 | # define WIFCONTINUED(status) 0 |
… | |
… | |
1398 | child_reap (EV_P_ int chain, int pid, int status) |
1419 | child_reap (EV_P_ int chain, int pid, int status) |
1399 | { |
1420 | { |
1400 | ev_child *w; |
1421 | ev_child *w; |
1401 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1422 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1402 | |
1423 | |
1403 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1424 | for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next) |
1404 | { |
1425 | { |
1405 | if ((w->pid == pid || !w->pid) |
1426 | if ((w->pid == pid || !w->pid) |
1406 | && (!traced || (w->flags & 1))) |
1427 | && (!traced || (w->flags & 1))) |
1407 | { |
1428 | { |
1408 | ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ |
1429 | ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ |
… | |
… | |
1433 | /* make sure we are called again until all children have been reaped */ |
1454 | /* make sure we are called again until all children have been reaped */ |
1434 | /* we need to do it this way so that the callback gets called before we continue */ |
1455 | /* we need to do it this way so that the callback gets called before we continue */ |
1435 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1456 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1436 | |
1457 | |
1437 | child_reap (EV_A_ pid, pid, status); |
1458 | child_reap (EV_A_ pid, pid, status); |
1438 | if (EV_PID_HASHSIZE > 1) |
1459 | if ((EV_PID_HASHSIZE) > 1) |
1439 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
1460 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
1440 | } |
1461 | } |
1441 | |
1462 | |
1442 | #endif |
1463 | #endif |
1443 | |
1464 | |
… | |
… | |
1510 | #ifdef __APPLE__ |
1531 | #ifdef __APPLE__ |
1511 | /* only select works correctly on that "unix-certified" platform */ |
1532 | /* only select works correctly on that "unix-certified" platform */ |
1512 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1533 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1513 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
1534 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
1514 | #endif |
1535 | #endif |
|
|
1536 | #ifdef __FreeBSD__ |
|
|
1537 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
|
|
1538 | #endif |
1515 | |
1539 | |
1516 | return flags; |
1540 | return flags; |
1517 | } |
1541 | } |
1518 | |
1542 | |
1519 | unsigned int |
1543 | unsigned int |
… | |
… | |
1532 | ev_backend (EV_P) |
1556 | ev_backend (EV_P) |
1533 | { |
1557 | { |
1534 | return backend; |
1558 | return backend; |
1535 | } |
1559 | } |
1536 | |
1560 | |
1537 | #if EV_MINIMAL < 2 |
1561 | #if EV_FEATURE_API |
1538 | unsigned int |
1562 | unsigned int |
1539 | ev_loop_count (EV_P) |
1563 | ev_iteration (EV_P) |
1540 | { |
1564 | { |
1541 | return loop_count; |
1565 | return loop_count; |
1542 | } |
1566 | } |
1543 | |
1567 | |
1544 | unsigned int |
1568 | unsigned int |
1545 | ev_loop_depth (EV_P) |
1569 | ev_depth (EV_P) |
1546 | { |
1570 | { |
1547 | return loop_depth; |
1571 | return loop_depth; |
1548 | } |
1572 | } |
1549 | |
1573 | |
1550 | void |
1574 | void |
… | |
… | |
1622 | |
1646 | |
1623 | ev_rt_now = ev_time (); |
1647 | ev_rt_now = ev_time (); |
1624 | mn_now = get_clock (); |
1648 | mn_now = get_clock (); |
1625 | now_floor = mn_now; |
1649 | now_floor = mn_now; |
1626 | rtmn_diff = ev_rt_now - mn_now; |
1650 | rtmn_diff = ev_rt_now - mn_now; |
1627 | #if EV_MINIMAL < 2 |
1651 | #if EV_FEATURE_API |
1628 | invoke_cb = ev_invoke_pending; |
1652 | invoke_cb = ev_invoke_pending; |
1629 | #endif |
1653 | #endif |
1630 | |
1654 | |
1631 | io_blocktime = 0.; |
1655 | io_blocktime = 0.; |
1632 | timeout_blocktime = 0.; |
1656 | timeout_blocktime = 0.; |
… | |
… | |
1662 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1686 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1663 | #endif |
1687 | #endif |
1664 | |
1688 | |
1665 | ev_prepare_init (&pending_w, pendingcb); |
1689 | ev_prepare_init (&pending_w, pendingcb); |
1666 | |
1690 | |
|
|
1691 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1667 | ev_init (&pipe_w, pipecb); |
1692 | ev_init (&pipe_w, pipecb); |
1668 | ev_set_priority (&pipe_w, EV_MAXPRI); |
1693 | ev_set_priority (&pipe_w, EV_MAXPRI); |
|
|
1694 | #endif |
1669 | } |
1695 | } |
1670 | } |
1696 | } |
1671 | |
1697 | |
1672 | /* free up a loop structure */ |
1698 | /* free up a loop structure */ |
1673 | static void noinline |
1699 | static void noinline |
… | |
… | |
1791 | { |
1817 | { |
1792 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1818 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1793 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1819 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1794 | } |
1820 | } |
1795 | |
1821 | |
|
|
1822 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1796 | evpipe_init (EV_A); |
1823 | evpipe_init (EV_A); |
1797 | /* now iterate over everything, in case we missed something */ |
1824 | /* now iterate over everything, in case we missed something */ |
1798 | pipecb (EV_A_ &pipe_w, EV_READ); |
1825 | pipecb (EV_A_ &pipe_w, EV_READ); |
|
|
1826 | #endif |
1799 | } |
1827 | } |
1800 | |
1828 | |
1801 | postfork = 0; |
1829 | postfork = 0; |
1802 | } |
1830 | } |
1803 | |
1831 | |
… | |
… | |
1865 | verify_watcher (EV_A_ ws [cnt]); |
1893 | verify_watcher (EV_A_ ws [cnt]); |
1866 | } |
1894 | } |
1867 | } |
1895 | } |
1868 | #endif |
1896 | #endif |
1869 | |
1897 | |
1870 | #if EV_MINIMAL < 2 |
1898 | #if EV_FEATURE_API |
1871 | void |
1899 | void |
1872 | ev_loop_verify (EV_P) |
1900 | ev_verify (EV_P) |
1873 | { |
1901 | { |
1874 | #if EV_VERIFY |
1902 | #if EV_VERIFY |
1875 | int i; |
1903 | int i; |
1876 | WL w; |
1904 | WL w; |
1877 | |
1905 | |
… | |
… | |
1916 | #if EV_ASYNC_ENABLE |
1944 | #if EV_ASYNC_ENABLE |
1917 | assert (asyncmax >= asynccnt); |
1945 | assert (asyncmax >= asynccnt); |
1918 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1946 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1919 | #endif |
1947 | #endif |
1920 | |
1948 | |
|
|
1949 | #if EV_PREPARE_ENABLE |
1921 | assert (preparemax >= preparecnt); |
1950 | assert (preparemax >= preparecnt); |
1922 | array_verify (EV_A_ (W *)prepares, preparecnt); |
1951 | array_verify (EV_A_ (W *)prepares, preparecnt); |
|
|
1952 | #endif |
1923 | |
1953 | |
|
|
1954 | #if EV_CHECK_ENABLE |
1924 | assert (checkmax >= checkcnt); |
1955 | assert (checkmax >= checkcnt); |
1925 | array_verify (EV_A_ (W *)checks, checkcnt); |
1956 | array_verify (EV_A_ (W *)checks, checkcnt); |
|
|
1957 | #endif |
1926 | |
1958 | |
1927 | # if 0 |
1959 | # if 0 |
|
|
1960 | #if EV_CHILD_ENABLE |
1928 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1961 | for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next) |
1929 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
1962 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
|
|
1963 | #endif |
1930 | # endif |
1964 | # endif |
1931 | #endif |
1965 | #endif |
1932 | } |
1966 | } |
1933 | #endif |
1967 | #endif |
1934 | |
1968 | |
… | |
… | |
1950 | |
1984 | |
1951 | loop_init (EV_A_ flags); |
1985 | loop_init (EV_A_ flags); |
1952 | |
1986 | |
1953 | if (ev_backend (EV_A)) |
1987 | if (ev_backend (EV_A)) |
1954 | { |
1988 | { |
1955 | #ifndef _WIN32 |
1989 | #if EV_CHILD_ENABLE |
1956 | ev_signal_init (&childev, childcb, SIGCHLD); |
1990 | ev_signal_init (&childev, childcb, SIGCHLD); |
1957 | ev_set_priority (&childev, EV_MAXPRI); |
1991 | ev_set_priority (&childev, EV_MAXPRI); |
1958 | ev_signal_start (EV_A_ &childev); |
1992 | ev_signal_start (EV_A_ &childev); |
1959 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1993 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1960 | #endif |
1994 | #endif |
… | |
… | |
1973 | EV_P = ev_default_loop_ptr; |
2007 | EV_P = ev_default_loop_ptr; |
1974 | #endif |
2008 | #endif |
1975 | |
2009 | |
1976 | ev_default_loop_ptr = 0; |
2010 | ev_default_loop_ptr = 0; |
1977 | |
2011 | |
1978 | #ifndef _WIN32 |
2012 | #if EV_CHILD_ENABLE |
1979 | ev_ref (EV_A); /* child watcher */ |
2013 | ev_ref (EV_A); /* child watcher */ |
1980 | ev_signal_stop (EV_A_ &childev); |
2014 | ev_signal_stop (EV_A_ &childev); |
1981 | #endif |
2015 | #endif |
1982 | |
2016 | |
1983 | loop_destroy (EV_A); |
2017 | loop_destroy (EV_A); |
… | |
… | |
2089 | EV_FREQUENT_CHECK; |
2123 | EV_FREQUENT_CHECK; |
2090 | feed_reverse (EV_A_ (W)w); |
2124 | feed_reverse (EV_A_ (W)w); |
2091 | } |
2125 | } |
2092 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2126 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2093 | |
2127 | |
2094 | feed_reverse_done (EV_A_ EV_TIMEOUT); |
2128 | feed_reverse_done (EV_A_ EV_TIMER); |
2095 | } |
2129 | } |
2096 | } |
2130 | } |
2097 | |
2131 | |
2098 | #if EV_PERIODIC_ENABLE |
2132 | #if EV_PERIODIC_ENABLE |
2099 | /* make periodics pending */ |
2133 | /* make periodics pending */ |
… | |
… | |
2152 | feed_reverse_done (EV_A_ EV_PERIODIC); |
2186 | feed_reverse_done (EV_A_ EV_PERIODIC); |
2153 | } |
2187 | } |
2154 | } |
2188 | } |
2155 | |
2189 | |
2156 | /* simply recalculate all periodics */ |
2190 | /* simply recalculate all periodics */ |
2157 | /* TODO: maybe ensure that at leats one event happens when jumping forward? */ |
2191 | /* TODO: maybe ensure that at least one event happens when jumping forward? */ |
2158 | static void noinline |
2192 | static void noinline |
2159 | periodics_reschedule (EV_P) |
2193 | periodics_reschedule (EV_P) |
2160 | { |
2194 | { |
2161 | int i; |
2195 | int i; |
2162 | |
2196 | |
… | |
… | |
2260 | } |
2294 | } |
2261 | |
2295 | |
2262 | void |
2296 | void |
2263 | ev_loop (EV_P_ int flags) |
2297 | ev_loop (EV_P_ int flags) |
2264 | { |
2298 | { |
2265 | #if EV_MINIMAL < 2 |
2299 | #if EV_FEATURE_API |
2266 | ++loop_depth; |
2300 | ++loop_depth; |
2267 | #endif |
2301 | #endif |
2268 | |
2302 | |
2269 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2303 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2270 | |
2304 | |
… | |
… | |
2273 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2307 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2274 | |
2308 | |
2275 | do |
2309 | do |
2276 | { |
2310 | { |
2277 | #if EV_VERIFY >= 2 |
2311 | #if EV_VERIFY >= 2 |
2278 | ev_loop_verify (EV_A); |
2312 | ev_verify (EV_A); |
2279 | #endif |
2313 | #endif |
2280 | |
2314 | |
2281 | #ifndef _WIN32 |
2315 | #ifndef _WIN32 |
2282 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2316 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2283 | if (expect_false (getpid () != curpid)) |
2317 | if (expect_false (getpid () != curpid)) |
… | |
… | |
2295 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2329 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2296 | EV_INVOKE_PENDING; |
2330 | EV_INVOKE_PENDING; |
2297 | } |
2331 | } |
2298 | #endif |
2332 | #endif |
2299 | |
2333 | |
|
|
2334 | #if EV_PREPARE_ENABLE |
2300 | /* queue prepare watchers (and execute them) */ |
2335 | /* queue prepare watchers (and execute them) */ |
2301 | if (expect_false (preparecnt)) |
2336 | if (expect_false (preparecnt)) |
2302 | { |
2337 | { |
2303 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2338 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2304 | EV_INVOKE_PENDING; |
2339 | EV_INVOKE_PENDING; |
2305 | } |
2340 | } |
|
|
2341 | #endif |
2306 | |
2342 | |
2307 | if (expect_false (loop_done)) |
2343 | if (expect_false (loop_done)) |
2308 | break; |
2344 | break; |
2309 | |
2345 | |
2310 | /* we might have forked, so reify kernel state if necessary */ |
2346 | /* we might have forked, so reify kernel state if necessary */ |
… | |
… | |
2361 | waittime -= sleeptime; |
2397 | waittime -= sleeptime; |
2362 | } |
2398 | } |
2363 | } |
2399 | } |
2364 | } |
2400 | } |
2365 | |
2401 | |
2366 | #if EV_MINIMAL < 2 |
2402 | #if EV_FEATURE_API |
2367 | ++loop_count; |
2403 | ++loop_count; |
2368 | #endif |
2404 | #endif |
2369 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2405 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2370 | backend_poll (EV_A_ waittime); |
2406 | backend_poll (EV_A_ waittime); |
2371 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
2407 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
… | |
… | |
2383 | #if EV_IDLE_ENABLE |
2419 | #if EV_IDLE_ENABLE |
2384 | /* queue idle watchers unless other events are pending */ |
2420 | /* queue idle watchers unless other events are pending */ |
2385 | idle_reify (EV_A); |
2421 | idle_reify (EV_A); |
2386 | #endif |
2422 | #endif |
2387 | |
2423 | |
|
|
2424 | #if EV_CHECK_ENABLE |
2388 | /* queue check watchers, to be executed first */ |
2425 | /* queue check watchers, to be executed first */ |
2389 | if (expect_false (checkcnt)) |
2426 | if (expect_false (checkcnt)) |
2390 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
2427 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
|
|
2428 | #endif |
2391 | |
2429 | |
2392 | EV_INVOKE_PENDING; |
2430 | EV_INVOKE_PENDING; |
2393 | } |
2431 | } |
2394 | while (expect_true ( |
2432 | while (expect_true ( |
2395 | activecnt |
2433 | activecnt |
… | |
… | |
2398 | )); |
2436 | )); |
2399 | |
2437 | |
2400 | if (loop_done == EVUNLOOP_ONE) |
2438 | if (loop_done == EVUNLOOP_ONE) |
2401 | loop_done = EVUNLOOP_CANCEL; |
2439 | loop_done = EVUNLOOP_CANCEL; |
2402 | |
2440 | |
2403 | #if EV_MINIMAL < 2 |
2441 | #if EV_FEATURE_API |
2404 | --loop_depth; |
2442 | --loop_depth; |
2405 | #endif |
2443 | #endif |
2406 | } |
2444 | } |
2407 | |
2445 | |
2408 | void |
2446 | void |
… | |
… | |
2562 | EV_FREQUENT_CHECK; |
2600 | EV_FREQUENT_CHECK; |
2563 | |
2601 | |
2564 | wlist_del (&anfds[w->fd].head, (WL)w); |
2602 | wlist_del (&anfds[w->fd].head, (WL)w); |
2565 | ev_stop (EV_A_ (W)w); |
2603 | ev_stop (EV_A_ (W)w); |
2566 | |
2604 | |
2567 | fd_change (EV_A_ w->fd, 1); |
2605 | fd_change (EV_A_ w->fd, EV_ANFD_REIFY); |
2568 | |
2606 | |
2569 | EV_FREQUENT_CHECK; |
2607 | EV_FREQUENT_CHECK; |
2570 | } |
2608 | } |
2571 | |
2609 | |
2572 | void noinline |
2610 | void noinline |
… | |
… | |
2725 | |
2763 | |
2726 | #ifndef SA_RESTART |
2764 | #ifndef SA_RESTART |
2727 | # define SA_RESTART 0 |
2765 | # define SA_RESTART 0 |
2728 | #endif |
2766 | #endif |
2729 | |
2767 | |
|
|
2768 | #if EV_SIGNAL_ENABLE |
|
|
2769 | |
2730 | void noinline |
2770 | void noinline |
2731 | ev_signal_start (EV_P_ ev_signal *w) |
2771 | ev_signal_start (EV_P_ ev_signal *w) |
2732 | { |
2772 | { |
2733 | if (expect_false (ev_is_active (w))) |
2773 | if (expect_false (ev_is_active (w))) |
2734 | return; |
2774 | return; |
… | |
… | |
2840 | } |
2880 | } |
2841 | |
2881 | |
2842 | EV_FREQUENT_CHECK; |
2882 | EV_FREQUENT_CHECK; |
2843 | } |
2883 | } |
2844 | |
2884 | |
|
|
2885 | #endif |
|
|
2886 | |
|
|
2887 | #if EV_CHILD_ENABLE |
|
|
2888 | |
2845 | void |
2889 | void |
2846 | ev_child_start (EV_P_ ev_child *w) |
2890 | ev_child_start (EV_P_ ev_child *w) |
2847 | { |
2891 | { |
2848 | #if EV_MULTIPLICITY |
2892 | #if EV_MULTIPLICITY |
2849 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
2893 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
… | |
… | |
2852 | return; |
2896 | return; |
2853 | |
2897 | |
2854 | EV_FREQUENT_CHECK; |
2898 | EV_FREQUENT_CHECK; |
2855 | |
2899 | |
2856 | ev_start (EV_A_ (W)w, 1); |
2900 | ev_start (EV_A_ (W)w, 1); |
2857 | wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2901 | wlist_add (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2858 | |
2902 | |
2859 | EV_FREQUENT_CHECK; |
2903 | EV_FREQUENT_CHECK; |
2860 | } |
2904 | } |
2861 | |
2905 | |
2862 | void |
2906 | void |
… | |
… | |
2866 | if (expect_false (!ev_is_active (w))) |
2910 | if (expect_false (!ev_is_active (w))) |
2867 | return; |
2911 | return; |
2868 | |
2912 | |
2869 | EV_FREQUENT_CHECK; |
2913 | EV_FREQUENT_CHECK; |
2870 | |
2914 | |
2871 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2915 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2872 | ev_stop (EV_A_ (W)w); |
2916 | ev_stop (EV_A_ (W)w); |
2873 | |
2917 | |
2874 | EV_FREQUENT_CHECK; |
2918 | EV_FREQUENT_CHECK; |
2875 | } |
2919 | } |
|
|
2920 | |
|
|
2921 | #endif |
2876 | |
2922 | |
2877 | #if EV_STAT_ENABLE |
2923 | #if EV_STAT_ENABLE |
2878 | |
2924 | |
2879 | # ifdef _WIN32 |
2925 | # ifdef _WIN32 |
2880 | # undef lstat |
2926 | # undef lstat |
… | |
… | |
2947 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2993 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2948 | } |
2994 | } |
2949 | } |
2995 | } |
2950 | |
2996 | |
2951 | if (w->wd >= 0) |
2997 | if (w->wd >= 0) |
2952 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2998 | wlist_add (&fs_hash [w->wd & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
2953 | |
2999 | |
2954 | /* now re-arm timer, if required */ |
3000 | /* now re-arm timer, if required */ |
2955 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
3001 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2956 | ev_timer_again (EV_A_ &w->timer); |
3002 | ev_timer_again (EV_A_ &w->timer); |
2957 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
3003 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
… | |
… | |
2965 | |
3011 | |
2966 | if (wd < 0) |
3012 | if (wd < 0) |
2967 | return; |
3013 | return; |
2968 | |
3014 | |
2969 | w->wd = -2; |
3015 | w->wd = -2; |
2970 | slot = wd & (EV_INOTIFY_HASHSIZE - 1); |
3016 | slot = wd & ((EV_INOTIFY_HASHSIZE) - 1); |
2971 | wlist_del (&fs_hash [slot].head, (WL)w); |
3017 | wlist_del (&fs_hash [slot].head, (WL)w); |
2972 | |
3018 | |
2973 | /* remove this watcher, if others are watching it, they will rearm */ |
3019 | /* remove this watcher, if others are watching it, they will rearm */ |
2974 | inotify_rm_watch (fs_fd, wd); |
3020 | inotify_rm_watch (fs_fd, wd); |
2975 | } |
3021 | } |
… | |
… | |
2977 | static void noinline |
3023 | static void noinline |
2978 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
3024 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
2979 | { |
3025 | { |
2980 | if (slot < 0) |
3026 | if (slot < 0) |
2981 | /* overflow, need to check for all hash slots */ |
3027 | /* overflow, need to check for all hash slots */ |
2982 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3028 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
2983 | infy_wd (EV_A_ slot, wd, ev); |
3029 | infy_wd (EV_A_ slot, wd, ev); |
2984 | else |
3030 | else |
2985 | { |
3031 | { |
2986 | WL w_; |
3032 | WL w_; |
2987 | |
3033 | |
2988 | for (w_ = fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head; w_; ) |
3034 | for (w_ = fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head; w_; ) |
2989 | { |
3035 | { |
2990 | ev_stat *w = (ev_stat *)w_; |
3036 | ev_stat *w = (ev_stat *)w_; |
2991 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
3037 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
2992 | |
3038 | |
2993 | if (w->wd == wd || wd == -1) |
3039 | if (w->wd == wd || wd == -1) |
2994 | { |
3040 | { |
2995 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
3041 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
2996 | { |
3042 | { |
2997 | wlist_del (&fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
3043 | wlist_del (&fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
2998 | w->wd = -1; |
3044 | w->wd = -1; |
2999 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3045 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3000 | } |
3046 | } |
3001 | |
3047 | |
3002 | stat_timer_cb (EV_A_ &w->timer, 0); |
3048 | stat_timer_cb (EV_A_ &w->timer, 0); |
… | |
… | |
3116 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3162 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3117 | ev_io_start (EV_A_ &fs_w); |
3163 | ev_io_start (EV_A_ &fs_w); |
3118 | ev_unref (EV_A); |
3164 | ev_unref (EV_A); |
3119 | } |
3165 | } |
3120 | |
3166 | |
3121 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3167 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
3122 | { |
3168 | { |
3123 | WL w_ = fs_hash [slot].head; |
3169 | WL w_ = fs_hash [slot].head; |
3124 | fs_hash [slot].head = 0; |
3170 | fs_hash [slot].head = 0; |
3125 | |
3171 | |
3126 | while (w_) |
3172 | while (w_) |
… | |
… | |
3301 | |
3347 | |
3302 | EV_FREQUENT_CHECK; |
3348 | EV_FREQUENT_CHECK; |
3303 | } |
3349 | } |
3304 | #endif |
3350 | #endif |
3305 | |
3351 | |
|
|
3352 | #if EV_PREPARE_ENABLE |
3306 | void |
3353 | void |
3307 | ev_prepare_start (EV_P_ ev_prepare *w) |
3354 | ev_prepare_start (EV_P_ ev_prepare *w) |
3308 | { |
3355 | { |
3309 | if (expect_false (ev_is_active (w))) |
3356 | if (expect_false (ev_is_active (w))) |
3310 | return; |
3357 | return; |
… | |
… | |
3336 | |
3383 | |
3337 | ev_stop (EV_A_ (W)w); |
3384 | ev_stop (EV_A_ (W)w); |
3338 | |
3385 | |
3339 | EV_FREQUENT_CHECK; |
3386 | EV_FREQUENT_CHECK; |
3340 | } |
3387 | } |
|
|
3388 | #endif |
3341 | |
3389 | |
|
|
3390 | #if EV_CHECK_ENABLE |
3342 | void |
3391 | void |
3343 | ev_check_start (EV_P_ ev_check *w) |
3392 | ev_check_start (EV_P_ ev_check *w) |
3344 | { |
3393 | { |
3345 | if (expect_false (ev_is_active (w))) |
3394 | if (expect_false (ev_is_active (w))) |
3346 | return; |
3395 | return; |
… | |
… | |
3372 | |
3421 | |
3373 | ev_stop (EV_A_ (W)w); |
3422 | ev_stop (EV_A_ (W)w); |
3374 | |
3423 | |
3375 | EV_FREQUENT_CHECK; |
3424 | EV_FREQUENT_CHECK; |
3376 | } |
3425 | } |
|
|
3426 | #endif |
3377 | |
3427 | |
3378 | #if EV_EMBED_ENABLE |
3428 | #if EV_EMBED_ENABLE |
3379 | void noinline |
3429 | void noinline |
3380 | ev_embed_sweep (EV_P_ ev_embed *w) |
3430 | ev_embed_sweep (EV_P_ ev_embed *w) |
3381 | { |
3431 | { |
… | |
… | |
3613 | { |
3663 | { |
3614 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3664 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3615 | |
3665 | |
3616 | if (expect_false (!once)) |
3666 | if (expect_false (!once)) |
3617 | { |
3667 | { |
3618 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
3668 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
3619 | return; |
3669 | return; |
3620 | } |
3670 | } |
3621 | |
3671 | |
3622 | once->cb = cb; |
3672 | once->cb = cb; |
3623 | once->arg = arg; |
3673 | once->arg = arg; |
… | |
… | |
3710 | if (types & EV_ASYNC) |
3760 | if (types & EV_ASYNC) |
3711 | for (i = asynccnt; i--; ) |
3761 | for (i = asynccnt; i--; ) |
3712 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3762 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3713 | #endif |
3763 | #endif |
3714 | |
3764 | |
|
|
3765 | #if EV_PREPARE_ENABLE |
3715 | if (types & EV_PREPARE) |
3766 | if (types & EV_PREPARE) |
3716 | for (i = preparecnt; i--; ) |
3767 | for (i = preparecnt; i--; ) |
3717 | #if EV_EMBED_ENABLE |
3768 | # if EV_EMBED_ENABLE |
3718 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3769 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3719 | #endif |
3770 | # endif |
3720 | cb (EV_A_ EV_PREPARE, prepares [i]); |
3771 | cb (EV_A_ EV_PREPARE, prepares [i]); |
|
|
3772 | #endif |
3721 | |
3773 | |
|
|
3774 | #if EV_CHECK_ENABLE |
3722 | if (types & EV_CHECK) |
3775 | if (types & EV_CHECK) |
3723 | for (i = checkcnt; i--; ) |
3776 | for (i = checkcnt; i--; ) |
3724 | cb (EV_A_ EV_CHECK, checks [i]); |
3777 | cb (EV_A_ EV_CHECK, checks [i]); |
|
|
3778 | #endif |
3725 | |
3779 | |
|
|
3780 | #if EV_SIGNAL_ENABLE |
3726 | if (types & EV_SIGNAL) |
3781 | if (types & EV_SIGNAL) |
3727 | for (i = 0; i < EV_NSIG - 1; ++i) |
3782 | for (i = 0; i < EV_NSIG - 1; ++i) |
3728 | for (wl = signals [i].head; wl; ) |
3783 | for (wl = signals [i].head; wl; ) |
3729 | { |
3784 | { |
3730 | wn = wl->next; |
3785 | wn = wl->next; |
3731 | cb (EV_A_ EV_SIGNAL, wl); |
3786 | cb (EV_A_ EV_SIGNAL, wl); |
3732 | wl = wn; |
3787 | wl = wn; |
3733 | } |
3788 | } |
|
|
3789 | #endif |
3734 | |
3790 | |
|
|
3791 | #if EV_CHILD_ENABLE |
3735 | if (types & EV_CHILD) |
3792 | if (types & EV_CHILD) |
3736 | for (i = EV_PID_HASHSIZE; i--; ) |
3793 | for (i = (EV_PID_HASHSIZE); i--; ) |
3737 | for (wl = childs [i]; wl; ) |
3794 | for (wl = childs [i]; wl; ) |
3738 | { |
3795 | { |
3739 | wn = wl->next; |
3796 | wn = wl->next; |
3740 | cb (EV_A_ EV_CHILD, wl); |
3797 | cb (EV_A_ EV_CHILD, wl); |
3741 | wl = wn; |
3798 | wl = wn; |
3742 | } |
3799 | } |
|
|
3800 | #endif |
3743 | /* EV_STAT 0x00001000 /* stat data changed */ |
3801 | /* EV_STAT 0x00001000 /* stat data changed */ |
3744 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3802 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3745 | } |
3803 | } |
3746 | #endif |
3804 | #endif |
3747 | |
3805 | |