1 | /* |
1 | /* |
2 | * libev event processing core, watcher management |
2 | * libev event processing core, watcher management |
3 | * |
3 | * |
4 | * Copyright (c) 2007,2008,2009 Marc Alexander Lehmann <libev@schmorp.de> |
4 | * Copyright (c) 2007,2008,2009,2010 Marc Alexander Lehmann <libev@schmorp.de> |
5 | * All rights reserved. |
5 | * All rights reserved. |
6 | * |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
8 | * tion, are permitted provided that the following conditions are met: |
8 | * tion, are permitted provided that the following conditions are met: |
9 | * |
9 | * |
… | |
… | |
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> |
… | |
… | |
163 | |
172 | |
164 | #include <assert.h> |
173 | #include <assert.h> |
165 | #include <errno.h> |
174 | #include <errno.h> |
166 | #include <sys/types.h> |
175 | #include <sys/types.h> |
167 | #include <time.h> |
176 | #include <time.h> |
|
|
177 | #include <limits.h> |
168 | |
178 | |
169 | #include <signal.h> |
179 | #include <signal.h> |
170 | |
180 | |
171 | #ifdef EV_H |
181 | #ifdef EV_H |
172 | # include EV_H |
182 | # include EV_H |
… | |
… | |
183 | # define WIN32_LEAN_AND_MEAN |
193 | # define WIN32_LEAN_AND_MEAN |
184 | # include <windows.h> |
194 | # include <windows.h> |
185 | # ifndef EV_SELECT_IS_WINSOCKET |
195 | # ifndef EV_SELECT_IS_WINSOCKET |
186 | # define EV_SELECT_IS_WINSOCKET 1 |
196 | # define EV_SELECT_IS_WINSOCKET 1 |
187 | # endif |
197 | # endif |
|
|
198 | # undef EV_AVOID_STDIO |
188 | #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 |
189 | |
208 | |
190 | /* 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 */ |
191 | |
210 | |
192 | /* try to deduce the maximum number of signals on this platform */ |
211 | /* try to deduce the maximum number of signals on this platform */ |
193 | #if defined (EV_NSIG) |
212 | #if defined (EV_NSIG) |
… | |
… | |
205 | #elif defined (MAXSIG) |
224 | #elif defined (MAXSIG) |
206 | # define EV_NSIG (MAXSIG+1) |
225 | # define EV_NSIG (MAXSIG+1) |
207 | #elif defined (MAX_SIG) |
226 | #elif defined (MAX_SIG) |
208 | # define EV_NSIG (MAX_SIG+1) |
227 | # define EV_NSIG (MAX_SIG+1) |
209 | #elif defined (SIGARRAYSIZE) |
228 | #elif defined (SIGARRAYSIZE) |
210 | # define EV_NSIG SIGARRAYSIZE /* Assume ary[SIGARRAYSIZE] */ |
229 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
211 | #elif defined (_sys_nsig) |
230 | #elif defined (_sys_nsig) |
212 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
231 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
213 | #else |
232 | #else |
214 | # error "unable to find value for NSIG, please report" |
233 | # error "unable to find value for NSIG, please report" |
215 | /* 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! :) */ |
216 | # define EV_NSIG 65 |
236 | # define EV_NSIG 65 |
217 | #endif |
237 | #endif |
218 | |
238 | |
219 | #ifndef EV_USE_CLOCK_SYSCALL |
239 | #ifndef EV_USE_CLOCK_SYSCALL |
220 | # if __linux && __GLIBC__ >= 2 |
240 | # if __linux && __GLIBC__ >= 2 |
221 | # define EV_USE_CLOCK_SYSCALL 1 |
241 | # define EV_USE_CLOCK_SYSCALL EV_FEATURE_OS |
222 | # else |
242 | # else |
223 | # define EV_USE_CLOCK_SYSCALL 0 |
243 | # define EV_USE_CLOCK_SYSCALL 0 |
224 | # endif |
244 | # endif |
225 | #endif |
245 | #endif |
226 | |
246 | |
227 | #ifndef EV_USE_MONOTONIC |
247 | #ifndef EV_USE_MONOTONIC |
228 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
248 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
229 | # define EV_USE_MONOTONIC 1 |
249 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
230 | # else |
250 | # else |
231 | # define EV_USE_MONOTONIC 0 |
251 | # define EV_USE_MONOTONIC 0 |
232 | # endif |
252 | # endif |
233 | #endif |
253 | #endif |
234 | |
254 | |
… | |
… | |
236 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
256 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
237 | #endif |
257 | #endif |
238 | |
258 | |
239 | #ifndef EV_USE_NANOSLEEP |
259 | #ifndef EV_USE_NANOSLEEP |
240 | # if _POSIX_C_SOURCE >= 199309L |
260 | # if _POSIX_C_SOURCE >= 199309L |
241 | # define EV_USE_NANOSLEEP 1 |
261 | # define EV_USE_NANOSLEEP EV_FEATURE_OS |
242 | # else |
262 | # else |
243 | # define EV_USE_NANOSLEEP 0 |
263 | # define EV_USE_NANOSLEEP 0 |
244 | # endif |
264 | # endif |
245 | #endif |
265 | #endif |
246 | |
266 | |
247 | #ifndef EV_USE_SELECT |
267 | #ifndef EV_USE_SELECT |
248 | # define EV_USE_SELECT 1 |
268 | # define EV_USE_SELECT EV_FEATURE_BACKENDS |
249 | #endif |
269 | #endif |
250 | |
270 | |
251 | #ifndef EV_USE_POLL |
271 | #ifndef EV_USE_POLL |
252 | # ifdef _WIN32 |
272 | # ifdef _WIN32 |
253 | # define EV_USE_POLL 0 |
273 | # define EV_USE_POLL 0 |
254 | # else |
274 | # else |
255 | # define EV_USE_POLL 1 |
275 | # define EV_USE_POLL EV_FEATURE_BACKENDS |
256 | # endif |
276 | # endif |
257 | #endif |
277 | #endif |
258 | |
278 | |
259 | #ifndef EV_USE_EPOLL |
279 | #ifndef EV_USE_EPOLL |
260 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
280 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
261 | # define EV_USE_EPOLL 1 |
281 | # define EV_USE_EPOLL EV_FEATURE_BACKENDS |
262 | # else |
282 | # else |
263 | # define EV_USE_EPOLL 0 |
283 | # define EV_USE_EPOLL 0 |
264 | # endif |
284 | # endif |
265 | #endif |
285 | #endif |
266 | |
286 | |
… | |
… | |
272 | # define EV_USE_PORT 0 |
292 | # define EV_USE_PORT 0 |
273 | #endif |
293 | #endif |
274 | |
294 | |
275 | #ifndef EV_USE_INOTIFY |
295 | #ifndef EV_USE_INOTIFY |
276 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
296 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
277 | # define EV_USE_INOTIFY 1 |
297 | # define EV_USE_INOTIFY EV_FEATURE_OS |
278 | # else |
298 | # else |
279 | # define EV_USE_INOTIFY 0 |
299 | # define EV_USE_INOTIFY 0 |
280 | # endif |
300 | # endif |
281 | #endif |
301 | #endif |
282 | |
302 | |
283 | #ifndef EV_PID_HASHSIZE |
303 | #ifndef EV_PID_HASHSIZE |
284 | # if EV_MINIMAL |
304 | # define EV_PID_HASHSIZE EV_FEATURE_DATA ? 16 : 1 |
285 | # define EV_PID_HASHSIZE 1 |
|
|
286 | # else |
|
|
287 | # define EV_PID_HASHSIZE 16 |
|
|
288 | # endif |
|
|
289 | #endif |
305 | #endif |
290 | |
306 | |
291 | #ifndef EV_INOTIFY_HASHSIZE |
307 | #ifndef EV_INOTIFY_HASHSIZE |
292 | # if EV_MINIMAL |
308 | # define EV_INOTIFY_HASHSIZE EV_FEATURE_DATA ? 16 : 1 |
293 | # define EV_INOTIFY_HASHSIZE 1 |
|
|
294 | # else |
|
|
295 | # define EV_INOTIFY_HASHSIZE 16 |
|
|
296 | # endif |
|
|
297 | #endif |
309 | #endif |
298 | |
310 | |
299 | #ifndef EV_USE_EVENTFD |
311 | #ifndef EV_USE_EVENTFD |
300 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
312 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
301 | # define EV_USE_EVENTFD 1 |
313 | # define EV_USE_EVENTFD EV_FEATURE_OS |
302 | # else |
314 | # else |
303 | # define EV_USE_EVENTFD 0 |
315 | # define EV_USE_EVENTFD 0 |
304 | # endif |
316 | # endif |
305 | #endif |
317 | #endif |
306 | |
318 | |
307 | #ifndef EV_USE_SIGNALFD |
319 | #ifndef EV_USE_SIGNALFD |
308 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
320 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
309 | # define EV_USE_SIGNALFD 1 |
321 | # define EV_USE_SIGNALFD EV_FEATURE_OS |
310 | # else |
322 | # else |
311 | # define EV_USE_SIGNALFD 0 |
323 | # define EV_USE_SIGNALFD 0 |
312 | # endif |
324 | # endif |
313 | #endif |
325 | #endif |
314 | |
326 | |
… | |
… | |
317 | # define EV_USE_4HEAP 1 |
329 | # define EV_USE_4HEAP 1 |
318 | # define EV_HEAP_CACHE_AT 1 |
330 | # define EV_HEAP_CACHE_AT 1 |
319 | #endif |
331 | #endif |
320 | |
332 | |
321 | #ifndef EV_VERIFY |
333 | #ifndef EV_VERIFY |
322 | # define EV_VERIFY !EV_MINIMAL |
334 | # define EV_VERIFY (EV_FEATURE_API ? 1 : 0) |
323 | #endif |
335 | #endif |
324 | |
336 | |
325 | #ifndef EV_USE_4HEAP |
337 | #ifndef EV_USE_4HEAP |
326 | # define EV_USE_4HEAP !EV_MINIMAL |
338 | # define EV_USE_4HEAP EV_FEATURE_DATA |
327 | #endif |
339 | #endif |
328 | |
340 | |
329 | #ifndef EV_HEAP_CACHE_AT |
341 | #ifndef EV_HEAP_CACHE_AT |
330 | # define EV_HEAP_CACHE_AT !EV_MINIMAL |
342 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
331 | #endif |
343 | #endif |
332 | |
344 | |
333 | /* 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, */ |
334 | /* which makes programs even slower. might work on other unices, too. */ |
346 | /* which makes programs even slower. might work on other unices, too. */ |
335 | #if EV_USE_CLOCK_SYSCALL |
347 | #if EV_USE_CLOCK_SYSCALL |
… | |
… | |
402 | # endif |
414 | # endif |
403 | # endif |
415 | # endif |
404 | # ifdef __cplusplus |
416 | # ifdef __cplusplus |
405 | extern "C" { |
417 | extern "C" { |
406 | # endif |
418 | # endif |
407 | int eventfd (unsigned int initval, int flags); |
419 | int (eventfd) (unsigned int initval, int flags); |
408 | # ifdef __cplusplus |
420 | # ifdef __cplusplus |
409 | } |
421 | } |
410 | # endif |
422 | # endif |
411 | #endif |
423 | #endif |
412 | |
424 | |
… | |
… | |
436 | # ifdef __cplusplus |
448 | # ifdef __cplusplus |
437 | } |
449 | } |
438 | # endif |
450 | # endif |
439 | #endif |
451 | #endif |
440 | |
452 | |
441 | |
|
|
442 | /**/ |
453 | /**/ |
443 | |
454 | |
444 | #if EV_VERIFY >= 3 |
455 | #if EV_VERIFY >= 3 |
445 | # define EV_FREQUENT_CHECK ev_loop_verify (EV_A) |
456 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
446 | #else |
457 | #else |
447 | # define EV_FREQUENT_CHECK do { } while (0) |
458 | # define EV_FREQUENT_CHECK do { } while (0) |
448 | #endif |
459 | #endif |
449 | |
460 | |
450 | /* |
461 | /* |
… | |
… | |
458 | #define TIME_EPSILON 0.0001220703125 /* 1/8192 */ |
469 | #define TIME_EPSILON 0.0001220703125 /* 1/8192 */ |
459 | |
470 | |
460 | #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) */ |
461 | #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) */ |
462 | |
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 | |
463 | #if __GNUC__ >= 4 |
477 | #if __GNUC__ >= 4 |
464 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
478 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
465 | # define noinline __attribute__ ((noinline)) |
479 | # define noinline __attribute__ ((noinline)) |
466 | #else |
480 | #else |
467 | # define expect(expr,value) (expr) |
481 | # define expect(expr,value) (expr) |
… | |
… | |
473 | |
487 | |
474 | #define expect_false(expr) expect ((expr) != 0, 0) |
488 | #define expect_false(expr) expect ((expr) != 0, 0) |
475 | #define expect_true(expr) expect ((expr) != 0, 1) |
489 | #define expect_true(expr) expect ((expr) != 0, 1) |
476 | #define inline_size static inline |
490 | #define inline_size static inline |
477 | |
491 | |
478 | #if EV_MINIMAL |
492 | #if EV_FEATURE_CODE |
|
|
493 | # define inline_speed static inline |
|
|
494 | #else |
479 | # define inline_speed static noinline |
495 | # define inline_speed static noinline |
480 | #else |
|
|
481 | # define inline_speed static inline |
|
|
482 | #endif |
496 | #endif |
483 | |
497 | |
484 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
498 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
485 | |
499 | |
486 | #if EV_MINPRI == EV_MAXPRI |
500 | #if EV_MINPRI == EV_MAXPRI |
… | |
… | |
499 | #define ev_active(w) ((W)(w))->active |
513 | #define ev_active(w) ((W)(w))->active |
500 | #define ev_at(w) ((WT)(w))->at |
514 | #define ev_at(w) ((WT)(w))->at |
501 | |
515 | |
502 | #if EV_USE_REALTIME |
516 | #if EV_USE_REALTIME |
503 | /* 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 */ |
504 | /* giving it a reasonably high chance of working on typical architetcures */ |
518 | /* giving it a reasonably high chance of working on typical architectures */ |
505 | 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? */ |
506 | #endif |
520 | #endif |
507 | |
521 | |
508 | #if EV_USE_MONOTONIC |
522 | #if EV_USE_MONOTONIC |
509 | 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? */ |
… | |
… | |
522 | #ifdef _WIN32 |
536 | #ifdef _WIN32 |
523 | # include "ev_win32.c" |
537 | # include "ev_win32.c" |
524 | #endif |
538 | #endif |
525 | |
539 | |
526 | /*****************************************************************************/ |
540 | /*****************************************************************************/ |
|
|
541 | |
|
|
542 | #if EV_AVOID_STDIO |
|
|
543 | static void noinline |
|
|
544 | ev_printerr (const char *msg) |
|
|
545 | { |
|
|
546 | write (STDERR_FILENO, msg, strlen (msg)); |
|
|
547 | } |
|
|
548 | #endif |
527 | |
549 | |
528 | static void (*syserr_cb)(const char *msg); |
550 | static void (*syserr_cb)(const char *msg); |
529 | |
551 | |
530 | void |
552 | void |
531 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
553 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
… | |
… | |
541 | |
563 | |
542 | if (syserr_cb) |
564 | if (syserr_cb) |
543 | syserr_cb (msg); |
565 | syserr_cb (msg); |
544 | else |
566 | else |
545 | { |
567 | { |
|
|
568 | #if EV_AVOID_STDIO |
|
|
569 | const char *err = strerror (errno); |
|
|
570 | |
|
|
571 | ev_printerr (msg); |
|
|
572 | ev_printerr (": "); |
|
|
573 | ev_printerr (err); |
|
|
574 | ev_printerr ("\n"); |
|
|
575 | #else |
546 | perror (msg); |
576 | perror (msg); |
|
|
577 | #endif |
547 | abort (); |
578 | abort (); |
548 | } |
579 | } |
549 | } |
580 | } |
550 | |
581 | |
551 | static void * |
582 | static void * |
552 | ev_realloc_emul (void *ptr, long size) |
583 | ev_realloc_emul (void *ptr, long size) |
553 | { |
584 | { |
|
|
585 | #if __GLIBC__ |
|
|
586 | return realloc (ptr, size); |
|
|
587 | #else |
554 | /* some systems, notably openbsd and darwin, fail to properly |
588 | /* some systems, notably openbsd and darwin, fail to properly |
555 | * 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 |
556 | * the single unix specification, so work around them here. |
590 | * the single unix specification, so work around them here. |
557 | */ |
591 | */ |
558 | |
592 | |
559 | if (size) |
593 | if (size) |
560 | return realloc (ptr, size); |
594 | return realloc (ptr, size); |
561 | |
595 | |
562 | free (ptr); |
596 | free (ptr); |
563 | return 0; |
597 | return 0; |
|
|
598 | #endif |
564 | } |
599 | } |
565 | |
600 | |
566 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
601 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
567 | |
602 | |
568 | void |
603 | void |
… | |
… | |
576 | { |
611 | { |
577 | ptr = alloc (ptr, size); |
612 | ptr = alloc (ptr, size); |
578 | |
613 | |
579 | if (!ptr && size) |
614 | if (!ptr && size) |
580 | { |
615 | { |
|
|
616 | #if EV_AVOID_STDIO |
|
|
617 | ev_printerr ("libev: memory allocation failed, aborting.\n"); |
|
|
618 | #else |
581 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
619 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
|
|
620 | #endif |
582 | abort (); |
621 | abort (); |
583 | } |
622 | } |
584 | |
623 | |
585 | return ptr; |
624 | return ptr; |
586 | } |
625 | } |
… | |
… | |
668 | |
707 | |
669 | static int ev_default_loop_ptr; |
708 | static int ev_default_loop_ptr; |
670 | |
709 | |
671 | #endif |
710 | #endif |
672 | |
711 | |
673 | #if EV_MINIMAL < 2 |
712 | #if EV_FEATURE_API |
674 | # 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) |
675 | # 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) |
676 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
715 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
677 | #else |
716 | #else |
678 | # define EV_RELEASE_CB (void)0 |
717 | # define EV_RELEASE_CB (void)0 |
679 | # define EV_ACQUIRE_CB (void)0 |
718 | # define EV_ACQUIRE_CB (void)0 |
680 | # define EV_INVOKE_PENDING ev_invoke_pending (EV_A) |
719 | # define EV_INVOKE_PENDING ev_invoke_pending (EV_A) |
681 | #endif |
720 | #endif |
682 | |
721 | |
683 | #define EVUNLOOP_RECURSE 0x80 |
722 | #define EVBREAK_RECURSE 0x80 |
684 | |
723 | |
685 | /*****************************************************************************/ |
724 | /*****************************************************************************/ |
686 | |
725 | |
687 | #ifndef EV_HAVE_EV_TIME |
726 | #ifndef EV_HAVE_EV_TIME |
688 | ev_tstamp |
727 | ev_tstamp |
… | |
… | |
732 | if (delay > 0.) |
771 | if (delay > 0.) |
733 | { |
772 | { |
734 | #if EV_USE_NANOSLEEP |
773 | #if EV_USE_NANOSLEEP |
735 | struct timespec ts; |
774 | struct timespec ts; |
736 | |
775 | |
737 | ts.tv_sec = (time_t)delay; |
776 | EV_TS_SET (ts, delay); |
738 | ts.tv_nsec = (long)((delay - (ev_tstamp)(ts.tv_sec)) * 1e9); |
|
|
739 | |
|
|
740 | nanosleep (&ts, 0); |
777 | nanosleep (&ts, 0); |
741 | #elif defined(_WIN32) |
778 | #elif defined(_WIN32) |
742 | Sleep ((unsigned long)(delay * 1e3)); |
779 | Sleep ((unsigned long)(delay * 1e3)); |
743 | #else |
780 | #else |
744 | struct timeval tv; |
781 | struct timeval tv; |
745 | |
782 | |
746 | tv.tv_sec = (time_t)delay; |
|
|
747 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
|
|
748 | |
|
|
749 | /* 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 */ |
750 | /* something not guaranteed by newer posix versions, but guaranteed */ |
784 | /* something not guaranteed by newer posix versions, but guaranteed */ |
751 | /* by older ones */ |
785 | /* by older ones */ |
|
|
786 | EV_TV_SET (tv, delay); |
752 | select (0, 0, 0, 0, &tv); |
787 | select (0, 0, 0, 0, &tv); |
753 | #endif |
788 | #endif |
754 | } |
789 | } |
755 | } |
790 | } |
756 | |
791 | |
757 | /*****************************************************************************/ |
792 | /*****************************************************************************/ |
758 | |
793 | |
759 | #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 */ |
760 | |
795 | |
761 | /* find a suitable new size for the given array, */ |
796 | /* find a suitable new size for the given array, */ |
762 | /* hopefully by rounding to a ncie-to-malloc size */ |
797 | /* hopefully by rounding to a nice-to-malloc size */ |
763 | inline_size int |
798 | inline_size int |
764 | array_nextsize (int elem, int cur, int cnt) |
799 | array_nextsize (int elem, int cur, int cnt) |
765 | { |
800 | { |
766 | int ncur = cur + 1; |
801 | int ncur = cur + 1; |
767 | |
802 | |
… | |
… | |
863 | } |
898 | } |
864 | |
899 | |
865 | /*****************************************************************************/ |
900 | /*****************************************************************************/ |
866 | |
901 | |
867 | inline_speed void |
902 | inline_speed void |
868 | fd_event_nc (EV_P_ int fd, int revents) |
903 | fd_event_nocheck (EV_P_ int fd, int revents) |
869 | { |
904 | { |
870 | ANFD *anfd = anfds + fd; |
905 | ANFD *anfd = anfds + fd; |
871 | ev_io *w; |
906 | ev_io *w; |
872 | |
907 | |
873 | 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) |
… | |
… | |
885 | fd_event (EV_P_ int fd, int revents) |
920 | fd_event (EV_P_ int fd, int revents) |
886 | { |
921 | { |
887 | ANFD *anfd = anfds + fd; |
922 | ANFD *anfd = anfds + fd; |
888 | |
923 | |
889 | if (expect_true (!anfd->reify)) |
924 | if (expect_true (!anfd->reify)) |
890 | fd_event_nc (EV_A_ fd, revents); |
925 | fd_event_nocheck (EV_A_ fd, revents); |
891 | } |
926 | } |
892 | |
927 | |
893 | void |
928 | void |
894 | ev_feed_fd_event (EV_P_ int fd, int revents) |
929 | ev_feed_fd_event (EV_P_ int fd, int revents) |
895 | { |
930 | { |
896 | if (fd >= 0 && fd < anfdmax) |
931 | if (fd >= 0 && fd < anfdmax) |
897 | fd_event_nc (EV_A_ fd, revents); |
932 | fd_event_nocheck (EV_A_ fd, revents); |
898 | } |
933 | } |
899 | |
934 | |
900 | /* make sure the external fd watch events are in-sync */ |
935 | /* make sure the external fd watch events are in-sync */ |
901 | /* with the kernel/libev internal state */ |
936 | /* with the kernel/libev internal state */ |
902 | inline_size void |
937 | inline_size void |
… | |
… | |
908 | { |
943 | { |
909 | int fd = fdchanges [i]; |
944 | int fd = fdchanges [i]; |
910 | ANFD *anfd = anfds + fd; |
945 | ANFD *anfd = anfds + fd; |
911 | ev_io *w; |
946 | ev_io *w; |
912 | |
947 | |
913 | unsigned char events = 0; |
948 | unsigned char o_events = anfd->events; |
|
|
949 | unsigned char o_reify = anfd->reify; |
914 | |
950 | |
915 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
951 | anfd->reify = 0; |
916 | events |= (unsigned char)w->events; |
|
|
917 | |
952 | |
918 | #if EV_SELECT_IS_WINSOCKET |
953 | #if EV_SELECT_IS_WINSOCKET |
919 | if (events) |
954 | if (o_reify & EV__IOFDSET) |
920 | { |
955 | { |
921 | unsigned long arg; |
956 | unsigned long arg; |
922 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
957 | anfd->handle = EV_FD_TO_WIN32_HANDLE (fd); |
923 | 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)); |
924 | } |
959 | } |
925 | #endif |
960 | #endif |
926 | |
961 | |
|
|
962 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
927 | { |
963 | { |
928 | unsigned char o_events = anfd->events; |
|
|
929 | unsigned char o_reify = anfd->reify; |
|
|
930 | |
|
|
931 | anfd->reify = 0; |
|
|
932 | anfd->events = events; |
964 | anfd->events = 0; |
933 | |
965 | |
934 | 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) |
935 | backend_modify (EV_A_ fd, o_events, events); |
974 | backend_modify (EV_A_ fd, o_events, anfd->events); |
936 | } |
|
|
937 | } |
975 | } |
938 | |
976 | |
939 | fdchangecnt = 0; |
977 | fdchangecnt = 0; |
940 | } |
978 | } |
941 | |
979 | |
… | |
… | |
965 | ev_io_stop (EV_A_ w); |
1003 | ev_io_stop (EV_A_ w); |
966 | 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); |
967 | } |
1005 | } |
968 | } |
1006 | } |
969 | |
1007 | |
970 | /* check whether the given fd is atcually valid, for error recovery */ |
1008 | /* check whether the given fd is actually valid, for error recovery */ |
971 | inline_size int |
1009 | inline_size int |
972 | fd_valid (int fd) |
1010 | fd_valid (int fd) |
973 | { |
1011 | { |
974 | #ifdef _WIN32 |
1012 | #ifdef _WIN32 |
975 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
1013 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
… | |
… | |
1017 | anfds [fd].emask = 0; |
1055 | anfds [fd].emask = 0; |
1018 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1056 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1019 | } |
1057 | } |
1020 | } |
1058 | } |
1021 | |
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 | |
1022 | /*****************************************************************************/ |
1074 | /*****************************************************************************/ |
1023 | |
1075 | |
1024 | /* |
1076 | /* |
1025 | * 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 |
1026 | * 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 |
1027 | * the branching factor of the d-tree. |
1079 | * the branching factor of the d-tree. |
1028 | */ |
1080 | */ |
1029 | |
1081 | |
1030 | /* |
1082 | /* |
… | |
… | |
1178 | |
1230 | |
1179 | static ANSIG signals [EV_NSIG - 1]; |
1231 | static ANSIG signals [EV_NSIG - 1]; |
1180 | |
1232 | |
1181 | /*****************************************************************************/ |
1233 | /*****************************************************************************/ |
1182 | |
1234 | |
1183 | /* used to prepare libev internal fd's */ |
1235 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1184 | /* this is not fork-safe */ |
|
|
1185 | inline_speed void |
|
|
1186 | fd_intern (int fd) |
|
|
1187 | { |
|
|
1188 | #ifdef _WIN32 |
|
|
1189 | unsigned long arg = 1; |
|
|
1190 | ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg); |
|
|
1191 | #else |
|
|
1192 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1193 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1194 | #endif |
|
|
1195 | } |
|
|
1196 | |
1236 | |
1197 | static void noinline |
1237 | static void noinline |
1198 | evpipe_init (EV_P) |
1238 | evpipe_init (EV_P) |
1199 | { |
1239 | { |
1200 | if (!ev_is_active (&pipe_w)) |
1240 | if (!ev_is_active (&pipe_w)) |
1201 | { |
1241 | { |
1202 | #if EV_USE_EVENTFD |
1242 | # if EV_USE_EVENTFD |
1203 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1243 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1204 | if (evfd < 0 && errno == EINVAL) |
1244 | if (evfd < 0 && errno == EINVAL) |
1205 | evfd = eventfd (0, 0); |
1245 | evfd = eventfd (0, 0); |
1206 | |
1246 | |
1207 | if (evfd >= 0) |
1247 | if (evfd >= 0) |
… | |
… | |
1209 | evpipe [0] = -1; |
1249 | evpipe [0] = -1; |
1210 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1250 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1211 | ev_io_set (&pipe_w, evfd, EV_READ); |
1251 | ev_io_set (&pipe_w, evfd, EV_READ); |
1212 | } |
1252 | } |
1213 | else |
1253 | else |
1214 | #endif |
1254 | # endif |
1215 | { |
1255 | { |
1216 | while (pipe (evpipe)) |
1256 | while (pipe (evpipe)) |
1217 | ev_syserr ("(libev) error creating signal/async pipe"); |
1257 | ev_syserr ("(libev) error creating signal/async pipe"); |
1218 | |
1258 | |
1219 | fd_intern (evpipe [0]); |
1259 | fd_intern (evpipe [0]); |
… | |
… | |
1230 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1270 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1231 | { |
1271 | { |
1232 | if (!*flag) |
1272 | if (!*flag) |
1233 | { |
1273 | { |
1234 | 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; |
1235 | |
1276 | |
1236 | *flag = 1; |
1277 | *flag = 1; |
1237 | |
1278 | |
1238 | #if EV_USE_EVENTFD |
1279 | #if EV_USE_EVENTFD |
1239 | if (evfd >= 0) |
1280 | if (evfd >= 0) |
… | |
… | |
1241 | uint64_t counter = 1; |
1282 | uint64_t counter = 1; |
1242 | write (evfd, &counter, sizeof (uint64_t)); |
1283 | write (evfd, &counter, sizeof (uint64_t)); |
1243 | } |
1284 | } |
1244 | else |
1285 | else |
1245 | #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. */ |
1246 | write (evpipe [1], &old_errno, 1); |
1292 | write (evpipe [1], &dummy, 1); |
1247 | |
1293 | |
1248 | errno = old_errno; |
1294 | errno = old_errno; |
1249 | } |
1295 | } |
1250 | } |
1296 | } |
1251 | |
1297 | |
… | |
… | |
1264 | } |
1310 | } |
1265 | else |
1311 | else |
1266 | #endif |
1312 | #endif |
1267 | { |
1313 | { |
1268 | char dummy; |
1314 | char dummy; |
|
|
1315 | /* see discussion in evpipe_write when you think this read should be recv in win32 */ |
1269 | read (evpipe [0], &dummy, 1); |
1316 | read (evpipe [0], &dummy, 1); |
1270 | } |
1317 | } |
1271 | |
1318 | |
1272 | if (sig_pending) |
1319 | if (sig_pending) |
1273 | { |
1320 | { |
… | |
… | |
1352 | break; |
1399 | break; |
1353 | } |
1400 | } |
1354 | } |
1401 | } |
1355 | #endif |
1402 | #endif |
1356 | |
1403 | |
|
|
1404 | #endif |
|
|
1405 | |
1357 | /*****************************************************************************/ |
1406 | /*****************************************************************************/ |
1358 | |
1407 | |
|
|
1408 | #if EV_CHILD_ENABLE |
1359 | static WL childs [EV_PID_HASHSIZE]; |
1409 | static WL childs [EV_PID_HASHSIZE]; |
1360 | |
|
|
1361 | #ifndef _WIN32 |
|
|
1362 | |
1410 | |
1363 | static ev_signal childev; |
1411 | static ev_signal childev; |
1364 | |
1412 | |
1365 | #ifndef WIFCONTINUED |
1413 | #ifndef WIFCONTINUED |
1366 | # define WIFCONTINUED(status) 0 |
1414 | # define WIFCONTINUED(status) 0 |
… | |
… | |
1371 | child_reap (EV_P_ int chain, int pid, int status) |
1419 | child_reap (EV_P_ int chain, int pid, int status) |
1372 | { |
1420 | { |
1373 | ev_child *w; |
1421 | ev_child *w; |
1374 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1422 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1375 | |
1423 | |
1376 | 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) |
1377 | { |
1425 | { |
1378 | if ((w->pid == pid || !w->pid) |
1426 | if ((w->pid == pid || !w->pid) |
1379 | && (!traced || (w->flags & 1))) |
1427 | && (!traced || (w->flags & 1))) |
1380 | { |
1428 | { |
1381 | 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 */ |
… | |
… | |
1406 | /* 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 */ |
1407 | /* 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 */ |
1408 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1456 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1409 | |
1457 | |
1410 | child_reap (EV_A_ pid, pid, status); |
1458 | child_reap (EV_A_ pid, pid, status); |
1411 | if (EV_PID_HASHSIZE > 1) |
1459 | if ((EV_PID_HASHSIZE) > 1) |
1412 | 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 */ |
1413 | } |
1461 | } |
1414 | |
1462 | |
1415 | #endif |
1463 | #endif |
1416 | |
1464 | |
… | |
… | |
1483 | #ifdef __APPLE__ |
1531 | #ifdef __APPLE__ |
1484 | /* only select works correctly on that "unix-certified" platform */ |
1532 | /* only select works correctly on that "unix-certified" platform */ |
1485 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1533 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1486 | 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 */ |
1487 | #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 |
1488 | |
1539 | |
1489 | return flags; |
1540 | return flags; |
1490 | } |
1541 | } |
1491 | |
1542 | |
1492 | unsigned int |
1543 | unsigned int |
… | |
… | |
1505 | ev_backend (EV_P) |
1556 | ev_backend (EV_P) |
1506 | { |
1557 | { |
1507 | return backend; |
1558 | return backend; |
1508 | } |
1559 | } |
1509 | |
1560 | |
1510 | #if EV_MINIMAL < 2 |
1561 | #if EV_FEATURE_API |
1511 | unsigned int |
1562 | unsigned int |
1512 | ev_loop_count (EV_P) |
1563 | ev_iteration (EV_P) |
1513 | { |
1564 | { |
1514 | return loop_count; |
1565 | return loop_count; |
1515 | } |
1566 | } |
1516 | |
1567 | |
1517 | unsigned int |
1568 | unsigned int |
1518 | ev_loop_depth (EV_P) |
1569 | ev_depth (EV_P) |
1519 | { |
1570 | { |
1520 | return loop_depth; |
1571 | return loop_depth; |
1521 | } |
1572 | } |
1522 | |
1573 | |
1523 | void |
1574 | void |
… | |
… | |
1595 | |
1646 | |
1596 | ev_rt_now = ev_time (); |
1647 | ev_rt_now = ev_time (); |
1597 | mn_now = get_clock (); |
1648 | mn_now = get_clock (); |
1598 | now_floor = mn_now; |
1649 | now_floor = mn_now; |
1599 | rtmn_diff = ev_rt_now - mn_now; |
1650 | rtmn_diff = ev_rt_now - mn_now; |
1600 | #if EV_MINIMAL < 2 |
1651 | #if EV_FEATURE_API |
1601 | invoke_cb = ev_invoke_pending; |
1652 | invoke_cb = ev_invoke_pending; |
1602 | #endif |
1653 | #endif |
1603 | |
1654 | |
1604 | io_blocktime = 0.; |
1655 | io_blocktime = 0.; |
1605 | timeout_blocktime = 0.; |
1656 | timeout_blocktime = 0.; |
… | |
… | |
1635 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1686 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1636 | #endif |
1687 | #endif |
1637 | |
1688 | |
1638 | ev_prepare_init (&pending_w, pendingcb); |
1689 | ev_prepare_init (&pending_w, pendingcb); |
1639 | |
1690 | |
|
|
1691 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1640 | ev_init (&pipe_w, pipecb); |
1692 | ev_init (&pipe_w, pipecb); |
1641 | ev_set_priority (&pipe_w, EV_MAXPRI); |
1693 | ev_set_priority (&pipe_w, EV_MAXPRI); |
|
|
1694 | #endif |
1642 | } |
1695 | } |
1643 | } |
1696 | } |
1644 | |
1697 | |
1645 | /* free up a loop structure */ |
1698 | /* free up a loop structure */ |
1646 | static void noinline |
1699 | static void noinline |
… | |
… | |
1764 | { |
1817 | { |
1765 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1818 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1766 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1819 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1767 | } |
1820 | } |
1768 | |
1821 | |
|
|
1822 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1769 | evpipe_init (EV_A); |
1823 | evpipe_init (EV_A); |
1770 | /* now iterate over everything, in case we missed something */ |
1824 | /* now iterate over everything, in case we missed something */ |
1771 | pipecb (EV_A_ &pipe_w, EV_READ); |
1825 | pipecb (EV_A_ &pipe_w, EV_READ); |
|
|
1826 | #endif |
1772 | } |
1827 | } |
1773 | |
1828 | |
1774 | postfork = 0; |
1829 | postfork = 0; |
1775 | } |
1830 | } |
1776 | |
1831 | |
… | |
… | |
1838 | verify_watcher (EV_A_ ws [cnt]); |
1893 | verify_watcher (EV_A_ ws [cnt]); |
1839 | } |
1894 | } |
1840 | } |
1895 | } |
1841 | #endif |
1896 | #endif |
1842 | |
1897 | |
1843 | #if EV_MINIMAL < 2 |
1898 | #if EV_FEATURE_API |
1844 | void |
1899 | void |
1845 | ev_loop_verify (EV_P) |
1900 | ev_verify (EV_P) |
1846 | { |
1901 | { |
1847 | #if EV_VERIFY |
1902 | #if EV_VERIFY |
1848 | int i; |
1903 | int i; |
1849 | WL w; |
1904 | WL w; |
1850 | |
1905 | |
… | |
… | |
1889 | #if EV_ASYNC_ENABLE |
1944 | #if EV_ASYNC_ENABLE |
1890 | assert (asyncmax >= asynccnt); |
1945 | assert (asyncmax >= asynccnt); |
1891 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1946 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1892 | #endif |
1947 | #endif |
1893 | |
1948 | |
|
|
1949 | #if EV_PREPARE_ENABLE |
1894 | assert (preparemax >= preparecnt); |
1950 | assert (preparemax >= preparecnt); |
1895 | array_verify (EV_A_ (W *)prepares, preparecnt); |
1951 | array_verify (EV_A_ (W *)prepares, preparecnt); |
|
|
1952 | #endif |
1896 | |
1953 | |
|
|
1954 | #if EV_CHECK_ENABLE |
1897 | assert (checkmax >= checkcnt); |
1955 | assert (checkmax >= checkcnt); |
1898 | array_verify (EV_A_ (W *)checks, checkcnt); |
1956 | array_verify (EV_A_ (W *)checks, checkcnt); |
|
|
1957 | #endif |
1899 | |
1958 | |
1900 | # if 0 |
1959 | # if 0 |
|
|
1960 | #if EV_CHILD_ENABLE |
1901 | 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) |
1902 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
1962 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
|
|
1963 | #endif |
1903 | # endif |
1964 | # endif |
1904 | #endif |
1965 | #endif |
1905 | } |
1966 | } |
1906 | #endif |
1967 | #endif |
1907 | |
1968 | |
… | |
… | |
1923 | |
1984 | |
1924 | loop_init (EV_A_ flags); |
1985 | loop_init (EV_A_ flags); |
1925 | |
1986 | |
1926 | if (ev_backend (EV_A)) |
1987 | if (ev_backend (EV_A)) |
1927 | { |
1988 | { |
1928 | #ifndef _WIN32 |
1989 | #if EV_CHILD_ENABLE |
1929 | ev_signal_init (&childev, childcb, SIGCHLD); |
1990 | ev_signal_init (&childev, childcb, SIGCHLD); |
1930 | ev_set_priority (&childev, EV_MAXPRI); |
1991 | ev_set_priority (&childev, EV_MAXPRI); |
1931 | ev_signal_start (EV_A_ &childev); |
1992 | ev_signal_start (EV_A_ &childev); |
1932 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1993 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1933 | #endif |
1994 | #endif |
… | |
… | |
1946 | EV_P = ev_default_loop_ptr; |
2007 | EV_P = ev_default_loop_ptr; |
1947 | #endif |
2008 | #endif |
1948 | |
2009 | |
1949 | ev_default_loop_ptr = 0; |
2010 | ev_default_loop_ptr = 0; |
1950 | |
2011 | |
1951 | #ifndef _WIN32 |
2012 | #if EV_CHILD_ENABLE |
1952 | ev_ref (EV_A); /* child watcher */ |
2013 | ev_ref (EV_A); /* child watcher */ |
1953 | ev_signal_stop (EV_A_ &childev); |
2014 | ev_signal_stop (EV_A_ &childev); |
1954 | #endif |
2015 | #endif |
1955 | |
2016 | |
1956 | loop_destroy (EV_A); |
2017 | loop_destroy (EV_A); |
… | |
… | |
2062 | EV_FREQUENT_CHECK; |
2123 | EV_FREQUENT_CHECK; |
2063 | feed_reverse (EV_A_ (W)w); |
2124 | feed_reverse (EV_A_ (W)w); |
2064 | } |
2125 | } |
2065 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2126 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2066 | |
2127 | |
2067 | feed_reverse_done (EV_A_ EV_TIMEOUT); |
2128 | feed_reverse_done (EV_A_ EV_TIMER); |
2068 | } |
2129 | } |
2069 | } |
2130 | } |
2070 | |
2131 | |
2071 | #if EV_PERIODIC_ENABLE |
2132 | #if EV_PERIODIC_ENABLE |
2072 | /* make periodics pending */ |
2133 | /* make periodics pending */ |
… | |
… | |
2125 | feed_reverse_done (EV_A_ EV_PERIODIC); |
2186 | feed_reverse_done (EV_A_ EV_PERIODIC); |
2126 | } |
2187 | } |
2127 | } |
2188 | } |
2128 | |
2189 | |
2129 | /* simply recalculate all periodics */ |
2190 | /* simply recalculate all periodics */ |
2130 | /* 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? */ |
2131 | static void noinline |
2192 | static void noinline |
2132 | periodics_reschedule (EV_P) |
2193 | periodics_reschedule (EV_P) |
2133 | { |
2194 | { |
2134 | int i; |
2195 | int i; |
2135 | |
2196 | |
… | |
… | |
2231 | mn_now = ev_rt_now; |
2292 | mn_now = ev_rt_now; |
2232 | } |
2293 | } |
2233 | } |
2294 | } |
2234 | |
2295 | |
2235 | void |
2296 | void |
2236 | ev_loop (EV_P_ int flags) |
2297 | ev_run (EV_P_ int flags) |
2237 | { |
2298 | { |
2238 | #if EV_MINIMAL < 2 |
2299 | #if EV_FEATURE_API |
2239 | ++loop_depth; |
2300 | ++loop_depth; |
2240 | #endif |
2301 | #endif |
2241 | |
2302 | |
2242 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2303 | assert (("libev: ev_loop recursion during release detected", loop_done != EVBREAK_RECURSE)); |
2243 | |
2304 | |
2244 | loop_done = EVUNLOOP_CANCEL; |
2305 | loop_done = EVBREAK_CANCEL; |
2245 | |
2306 | |
2246 | 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 */ |
2247 | |
2308 | |
2248 | do |
2309 | do |
2249 | { |
2310 | { |
2250 | #if EV_VERIFY >= 2 |
2311 | #if EV_VERIFY >= 2 |
2251 | ev_loop_verify (EV_A); |
2312 | ev_verify (EV_A); |
2252 | #endif |
2313 | #endif |
2253 | |
2314 | |
2254 | #ifndef _WIN32 |
2315 | #ifndef _WIN32 |
2255 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2316 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2256 | if (expect_false (getpid () != curpid)) |
2317 | if (expect_false (getpid () != curpid)) |
… | |
… | |
2268 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2329 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2269 | EV_INVOKE_PENDING; |
2330 | EV_INVOKE_PENDING; |
2270 | } |
2331 | } |
2271 | #endif |
2332 | #endif |
2272 | |
2333 | |
|
|
2334 | #if EV_PREPARE_ENABLE |
2273 | /* queue prepare watchers (and execute them) */ |
2335 | /* queue prepare watchers (and execute them) */ |
2274 | if (expect_false (preparecnt)) |
2336 | if (expect_false (preparecnt)) |
2275 | { |
2337 | { |
2276 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2338 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2277 | EV_INVOKE_PENDING; |
2339 | EV_INVOKE_PENDING; |
2278 | } |
2340 | } |
|
|
2341 | #endif |
2279 | |
2342 | |
2280 | if (expect_false (loop_done)) |
2343 | if (expect_false (loop_done)) |
2281 | break; |
2344 | break; |
2282 | |
2345 | |
2283 | /* we might have forked, so reify kernel state if necessary */ |
2346 | /* we might have forked, so reify kernel state if necessary */ |
… | |
… | |
2290 | /* calculate blocking time */ |
2353 | /* calculate blocking time */ |
2291 | { |
2354 | { |
2292 | ev_tstamp waittime = 0.; |
2355 | ev_tstamp waittime = 0.; |
2293 | ev_tstamp sleeptime = 0.; |
2356 | ev_tstamp sleeptime = 0.; |
2294 | |
2357 | |
|
|
2358 | /* remember old timestamp for io_blocktime calculation */ |
|
|
2359 | ev_tstamp prev_mn_now = mn_now; |
|
|
2360 | |
|
|
2361 | /* update time to cancel out callback processing overhead */ |
|
|
2362 | time_update (EV_A_ 1e100); |
|
|
2363 | |
2295 | if (expect_true (!(flags & EVLOOP_NONBLOCK || idleall || !activecnt))) |
2364 | if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt))) |
2296 | { |
2365 | { |
2297 | /* remember old timestamp for io_blocktime calculation */ |
|
|
2298 | ev_tstamp prev_mn_now = mn_now; |
|
|
2299 | |
|
|
2300 | /* update time to cancel out callback processing overhead */ |
|
|
2301 | time_update (EV_A_ 1e100); |
|
|
2302 | |
|
|
2303 | waittime = MAX_BLOCKTIME; |
2366 | waittime = MAX_BLOCKTIME; |
2304 | |
2367 | |
2305 | if (timercnt) |
2368 | if (timercnt) |
2306 | { |
2369 | { |
2307 | ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now + backend_fudge; |
2370 | ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now + backend_fudge; |
… | |
… | |
2334 | waittime -= sleeptime; |
2397 | waittime -= sleeptime; |
2335 | } |
2398 | } |
2336 | } |
2399 | } |
2337 | } |
2400 | } |
2338 | |
2401 | |
2339 | #if EV_MINIMAL < 2 |
2402 | #if EV_FEATURE_API |
2340 | ++loop_count; |
2403 | ++loop_count; |
2341 | #endif |
2404 | #endif |
2342 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2405 | assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */ |
2343 | backend_poll (EV_A_ waittime); |
2406 | backend_poll (EV_A_ waittime); |
2344 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
2407 | assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ |
2345 | |
2408 | |
2346 | /* update ev_rt_now, do magic */ |
2409 | /* update ev_rt_now, do magic */ |
2347 | time_update (EV_A_ waittime + sleeptime); |
2410 | time_update (EV_A_ waittime + sleeptime); |
2348 | } |
2411 | } |
2349 | |
2412 | |
… | |
… | |
2356 | #if EV_IDLE_ENABLE |
2419 | #if EV_IDLE_ENABLE |
2357 | /* queue idle watchers unless other events are pending */ |
2420 | /* queue idle watchers unless other events are pending */ |
2358 | idle_reify (EV_A); |
2421 | idle_reify (EV_A); |
2359 | #endif |
2422 | #endif |
2360 | |
2423 | |
|
|
2424 | #if EV_CHECK_ENABLE |
2361 | /* queue check watchers, to be executed first */ |
2425 | /* queue check watchers, to be executed first */ |
2362 | if (expect_false (checkcnt)) |
2426 | if (expect_false (checkcnt)) |
2363 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
2427 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
|
|
2428 | #endif |
2364 | |
2429 | |
2365 | EV_INVOKE_PENDING; |
2430 | EV_INVOKE_PENDING; |
2366 | } |
2431 | } |
2367 | while (expect_true ( |
2432 | while (expect_true ( |
2368 | activecnt |
2433 | activecnt |
2369 | && !loop_done |
2434 | && !loop_done |
2370 | && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)) |
2435 | && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT)) |
2371 | )); |
2436 | )); |
2372 | |
2437 | |
2373 | if (loop_done == EVUNLOOP_ONE) |
2438 | if (loop_done == EVBREAK_ONE) |
2374 | loop_done = EVUNLOOP_CANCEL; |
2439 | loop_done = EVBREAK_CANCEL; |
2375 | |
2440 | |
2376 | #if EV_MINIMAL < 2 |
2441 | #if EV_FEATURE_API |
2377 | --loop_depth; |
2442 | --loop_depth; |
2378 | #endif |
2443 | #endif |
2379 | } |
2444 | } |
2380 | |
2445 | |
2381 | void |
2446 | void |
2382 | ev_unloop (EV_P_ int how) |
2447 | ev_break (EV_P_ int how) |
2383 | { |
2448 | { |
2384 | loop_done = how; |
2449 | loop_done = how; |
2385 | } |
2450 | } |
2386 | |
2451 | |
2387 | void |
2452 | void |
… | |
… | |
2507 | |
2572 | |
2508 | if (expect_false (ev_is_active (w))) |
2573 | if (expect_false (ev_is_active (w))) |
2509 | return; |
2574 | return; |
2510 | |
2575 | |
2511 | assert (("libev: ev_io_start called with negative fd", fd >= 0)); |
2576 | assert (("libev: ev_io_start called with negative fd", fd >= 0)); |
2512 | assert (("libev: ev_io start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
2577 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
2513 | |
2578 | |
2514 | EV_FREQUENT_CHECK; |
2579 | EV_FREQUENT_CHECK; |
2515 | |
2580 | |
2516 | ev_start (EV_A_ (W)w, 1); |
2581 | ev_start (EV_A_ (W)w, 1); |
2517 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
2582 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
… | |
… | |
2535 | EV_FREQUENT_CHECK; |
2600 | EV_FREQUENT_CHECK; |
2536 | |
2601 | |
2537 | wlist_del (&anfds[w->fd].head, (WL)w); |
2602 | wlist_del (&anfds[w->fd].head, (WL)w); |
2538 | ev_stop (EV_A_ (W)w); |
2603 | ev_stop (EV_A_ (W)w); |
2539 | |
2604 | |
2540 | fd_change (EV_A_ w->fd, 1); |
2605 | fd_change (EV_A_ w->fd, EV_ANFD_REIFY); |
2541 | |
2606 | |
2542 | EV_FREQUENT_CHECK; |
2607 | EV_FREQUENT_CHECK; |
2543 | } |
2608 | } |
2544 | |
2609 | |
2545 | void noinline |
2610 | void noinline |
… | |
… | |
2587 | timers [active] = timers [timercnt + HEAP0]; |
2652 | timers [active] = timers [timercnt + HEAP0]; |
2588 | adjustheap (timers, timercnt, active); |
2653 | adjustheap (timers, timercnt, active); |
2589 | } |
2654 | } |
2590 | } |
2655 | } |
2591 | |
2656 | |
2592 | EV_FREQUENT_CHECK; |
|
|
2593 | |
|
|
2594 | ev_at (w) -= mn_now; |
2657 | ev_at (w) -= mn_now; |
2595 | |
2658 | |
2596 | ev_stop (EV_A_ (W)w); |
2659 | ev_stop (EV_A_ (W)w); |
|
|
2660 | |
|
|
2661 | EV_FREQUENT_CHECK; |
2597 | } |
2662 | } |
2598 | |
2663 | |
2599 | void noinline |
2664 | void noinline |
2600 | ev_timer_again (EV_P_ ev_timer *w) |
2665 | ev_timer_again (EV_P_ ev_timer *w) |
2601 | { |
2666 | { |
… | |
… | |
2680 | periodics [active] = periodics [periodiccnt + HEAP0]; |
2745 | periodics [active] = periodics [periodiccnt + HEAP0]; |
2681 | adjustheap (periodics, periodiccnt, active); |
2746 | adjustheap (periodics, periodiccnt, active); |
2682 | } |
2747 | } |
2683 | } |
2748 | } |
2684 | |
2749 | |
2685 | EV_FREQUENT_CHECK; |
|
|
2686 | |
|
|
2687 | ev_stop (EV_A_ (W)w); |
2750 | ev_stop (EV_A_ (W)w); |
|
|
2751 | |
|
|
2752 | EV_FREQUENT_CHECK; |
2688 | } |
2753 | } |
2689 | |
2754 | |
2690 | void noinline |
2755 | void noinline |
2691 | ev_periodic_again (EV_P_ ev_periodic *w) |
2756 | ev_periodic_again (EV_P_ ev_periodic *w) |
2692 | { |
2757 | { |
… | |
… | |
2697 | #endif |
2762 | #endif |
2698 | |
2763 | |
2699 | #ifndef SA_RESTART |
2764 | #ifndef SA_RESTART |
2700 | # define SA_RESTART 0 |
2765 | # define SA_RESTART 0 |
2701 | #endif |
2766 | #endif |
|
|
2767 | |
|
|
2768 | #if EV_SIGNAL_ENABLE |
2702 | |
2769 | |
2703 | void noinline |
2770 | void noinline |
2704 | ev_signal_start (EV_P_ ev_signal *w) |
2771 | ev_signal_start (EV_P_ ev_signal *w) |
2705 | { |
2772 | { |
2706 | if (expect_false (ev_is_active (w))) |
2773 | if (expect_false (ev_is_active (w))) |
… | |
… | |
2813 | } |
2880 | } |
2814 | |
2881 | |
2815 | EV_FREQUENT_CHECK; |
2882 | EV_FREQUENT_CHECK; |
2816 | } |
2883 | } |
2817 | |
2884 | |
|
|
2885 | #endif |
|
|
2886 | |
|
|
2887 | #if EV_CHILD_ENABLE |
|
|
2888 | |
2818 | void |
2889 | void |
2819 | ev_child_start (EV_P_ ev_child *w) |
2890 | ev_child_start (EV_P_ ev_child *w) |
2820 | { |
2891 | { |
2821 | #if EV_MULTIPLICITY |
2892 | #if EV_MULTIPLICITY |
2822 | 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)); |
… | |
… | |
2825 | return; |
2896 | return; |
2826 | |
2897 | |
2827 | EV_FREQUENT_CHECK; |
2898 | EV_FREQUENT_CHECK; |
2828 | |
2899 | |
2829 | ev_start (EV_A_ (W)w, 1); |
2900 | ev_start (EV_A_ (W)w, 1); |
2830 | wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2901 | wlist_add (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2831 | |
2902 | |
2832 | EV_FREQUENT_CHECK; |
2903 | EV_FREQUENT_CHECK; |
2833 | } |
2904 | } |
2834 | |
2905 | |
2835 | void |
2906 | void |
… | |
… | |
2839 | if (expect_false (!ev_is_active (w))) |
2910 | if (expect_false (!ev_is_active (w))) |
2840 | return; |
2911 | return; |
2841 | |
2912 | |
2842 | EV_FREQUENT_CHECK; |
2913 | EV_FREQUENT_CHECK; |
2843 | |
2914 | |
2844 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2915 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2845 | ev_stop (EV_A_ (W)w); |
2916 | ev_stop (EV_A_ (W)w); |
2846 | |
2917 | |
2847 | EV_FREQUENT_CHECK; |
2918 | EV_FREQUENT_CHECK; |
2848 | } |
2919 | } |
|
|
2920 | |
|
|
2921 | #endif |
2849 | |
2922 | |
2850 | #if EV_STAT_ENABLE |
2923 | #if EV_STAT_ENABLE |
2851 | |
2924 | |
2852 | # ifdef _WIN32 |
2925 | # ifdef _WIN32 |
2853 | # undef lstat |
2926 | # undef lstat |
… | |
… | |
2859 | #define MIN_STAT_INTERVAL 0.1074891 |
2932 | #define MIN_STAT_INTERVAL 0.1074891 |
2860 | |
2933 | |
2861 | static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
2934 | static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
2862 | |
2935 | |
2863 | #if EV_USE_INOTIFY |
2936 | #if EV_USE_INOTIFY |
2864 | # define EV_INOTIFY_BUFSIZE 8192 |
2937 | |
|
|
2938 | /* the * 2 is to allow for alignment padding, which for some reason is >> 8 */ |
|
|
2939 | # define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) |
2865 | |
2940 | |
2866 | static void noinline |
2941 | static void noinline |
2867 | infy_add (EV_P_ ev_stat *w) |
2942 | infy_add (EV_P_ ev_stat *w) |
2868 | { |
2943 | { |
2869 | w->wd = inotify_add_watch (fs_fd, w->path, IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY | IN_DONT_FOLLOW | IN_MASK_ADD); |
2944 | w->wd = inotify_add_watch (fs_fd, w->path, IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY | IN_DONT_FOLLOW | IN_MASK_ADD); |
… | |
… | |
2918 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2993 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2919 | } |
2994 | } |
2920 | } |
2995 | } |
2921 | |
2996 | |
2922 | if (w->wd >= 0) |
2997 | if (w->wd >= 0) |
2923 | 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); |
2924 | |
2999 | |
2925 | /* now re-arm timer, if required */ |
3000 | /* now re-arm timer, if required */ |
2926 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
3001 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2927 | ev_timer_again (EV_A_ &w->timer); |
3002 | ev_timer_again (EV_A_ &w->timer); |
2928 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
3003 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
… | |
… | |
2936 | |
3011 | |
2937 | if (wd < 0) |
3012 | if (wd < 0) |
2938 | return; |
3013 | return; |
2939 | |
3014 | |
2940 | w->wd = -2; |
3015 | w->wd = -2; |
2941 | slot = wd & (EV_INOTIFY_HASHSIZE - 1); |
3016 | slot = wd & ((EV_INOTIFY_HASHSIZE) - 1); |
2942 | wlist_del (&fs_hash [slot].head, (WL)w); |
3017 | wlist_del (&fs_hash [slot].head, (WL)w); |
2943 | |
3018 | |
2944 | /* remove this watcher, if others are watching it, they will rearm */ |
3019 | /* remove this watcher, if others are watching it, they will rearm */ |
2945 | inotify_rm_watch (fs_fd, wd); |
3020 | inotify_rm_watch (fs_fd, wd); |
2946 | } |
3021 | } |
… | |
… | |
2948 | static void noinline |
3023 | static void noinline |
2949 | 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) |
2950 | { |
3025 | { |
2951 | if (slot < 0) |
3026 | if (slot < 0) |
2952 | /* overflow, need to check for all hash slots */ |
3027 | /* overflow, need to check for all hash slots */ |
2953 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3028 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
2954 | infy_wd (EV_A_ slot, wd, ev); |
3029 | infy_wd (EV_A_ slot, wd, ev); |
2955 | else |
3030 | else |
2956 | { |
3031 | { |
2957 | WL w_; |
3032 | WL w_; |
2958 | |
3033 | |
2959 | for (w_ = fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head; w_; ) |
3034 | for (w_ = fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head; w_; ) |
2960 | { |
3035 | { |
2961 | ev_stat *w = (ev_stat *)w_; |
3036 | ev_stat *w = (ev_stat *)w_; |
2962 | 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 */ |
2963 | |
3038 | |
2964 | if (w->wd == wd || wd == -1) |
3039 | if (w->wd == wd || wd == -1) |
2965 | { |
3040 | { |
2966 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
3041 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
2967 | { |
3042 | { |
2968 | 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); |
2969 | w->wd = -1; |
3044 | w->wd = -1; |
2970 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3045 | infy_add (EV_A_ w); /* re-add, no matter what */ |
2971 | } |
3046 | } |
2972 | |
3047 | |
2973 | stat_timer_cb (EV_A_ &w->timer, 0); |
3048 | stat_timer_cb (EV_A_ &w->timer, 0); |
… | |
… | |
2978 | |
3053 | |
2979 | static void |
3054 | static void |
2980 | infy_cb (EV_P_ ev_io *w, int revents) |
3055 | infy_cb (EV_P_ ev_io *w, int revents) |
2981 | { |
3056 | { |
2982 | char buf [EV_INOTIFY_BUFSIZE]; |
3057 | char buf [EV_INOTIFY_BUFSIZE]; |
2983 | struct inotify_event *ev = (struct inotify_event *)buf; |
|
|
2984 | int ofs; |
3058 | int ofs; |
2985 | int len = read (fs_fd, buf, sizeof (buf)); |
3059 | int len = read (fs_fd, buf, sizeof (buf)); |
2986 | |
3060 | |
2987 | for (ofs = 0; ofs < len; ofs += sizeof (struct inotify_event) + ev->len) |
3061 | for (ofs = 0; ofs < len; ) |
|
|
3062 | { |
|
|
3063 | struct inotify_event *ev = (struct inotify_event *)(buf + ofs); |
2988 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
3064 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
|
|
3065 | ofs += sizeof (struct inotify_event) + ev->len; |
|
|
3066 | } |
|
|
3067 | } |
|
|
3068 | |
|
|
3069 | inline_size unsigned int |
|
|
3070 | ev_linux_version (void) |
|
|
3071 | { |
|
|
3072 | struct utsname buf; |
|
|
3073 | unsigned int v; |
|
|
3074 | int i; |
|
|
3075 | char *p = buf.release; |
|
|
3076 | |
|
|
3077 | if (uname (&buf)) |
|
|
3078 | return 0; |
|
|
3079 | |
|
|
3080 | for (i = 3+1; --i; ) |
|
|
3081 | { |
|
|
3082 | unsigned int c = 0; |
|
|
3083 | |
|
|
3084 | for (;;) |
|
|
3085 | { |
|
|
3086 | if (*p >= '0' && *p <= '9') |
|
|
3087 | c = c * 10 + *p++ - '0'; |
|
|
3088 | else |
|
|
3089 | { |
|
|
3090 | p += *p == '.'; |
|
|
3091 | break; |
|
|
3092 | } |
|
|
3093 | } |
|
|
3094 | |
|
|
3095 | v = (v << 8) | c; |
|
|
3096 | } |
|
|
3097 | |
|
|
3098 | return v; |
2989 | } |
3099 | } |
2990 | |
3100 | |
2991 | inline_size void |
3101 | inline_size void |
2992 | check_2625 (EV_P) |
3102 | ev_check_2625 (EV_P) |
2993 | { |
3103 | { |
2994 | /* kernels < 2.6.25 are borked |
3104 | /* kernels < 2.6.25 are borked |
2995 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
3105 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
2996 | */ |
3106 | */ |
2997 | struct utsname buf; |
3107 | if (ev_linux_version () < 0x020619) |
2998 | int major, minor, micro; |
|
|
2999 | |
|
|
3000 | if (uname (&buf)) |
|
|
3001 | return; |
|
|
3002 | |
|
|
3003 | if (sscanf (buf.release, "%d.%d.%d", &major, &minor, µ) != 3) |
|
|
3004 | return; |
|
|
3005 | |
|
|
3006 | if (major < 2 |
|
|
3007 | || (major == 2 && minor < 6) |
|
|
3008 | || (major == 2 && minor == 6 && micro < 25)) |
|
|
3009 | return; |
3108 | return; |
3010 | |
3109 | |
3011 | fs_2625 = 1; |
3110 | fs_2625 = 1; |
3012 | } |
3111 | } |
3013 | |
3112 | |
… | |
… | |
3028 | if (fs_fd != -2) |
3127 | if (fs_fd != -2) |
3029 | return; |
3128 | return; |
3030 | |
3129 | |
3031 | fs_fd = -1; |
3130 | fs_fd = -1; |
3032 | |
3131 | |
3033 | check_2625 (EV_A); |
3132 | ev_check_2625 (EV_A); |
3034 | |
3133 | |
3035 | fs_fd = infy_newfd (); |
3134 | fs_fd = infy_newfd (); |
3036 | |
3135 | |
3037 | if (fs_fd >= 0) |
3136 | if (fs_fd >= 0) |
3038 | { |
3137 | { |
… | |
… | |
3063 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3162 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3064 | ev_io_start (EV_A_ &fs_w); |
3163 | ev_io_start (EV_A_ &fs_w); |
3065 | ev_unref (EV_A); |
3164 | ev_unref (EV_A); |
3066 | } |
3165 | } |
3067 | |
3166 | |
3068 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3167 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
3069 | { |
3168 | { |
3070 | WL w_ = fs_hash [slot].head; |
3169 | WL w_ = fs_hash [slot].head; |
3071 | fs_hash [slot].head = 0; |
3170 | fs_hash [slot].head = 0; |
3072 | |
3171 | |
3073 | while (w_) |
3172 | while (w_) |
… | |
… | |
3248 | |
3347 | |
3249 | EV_FREQUENT_CHECK; |
3348 | EV_FREQUENT_CHECK; |
3250 | } |
3349 | } |
3251 | #endif |
3350 | #endif |
3252 | |
3351 | |
|
|
3352 | #if EV_PREPARE_ENABLE |
3253 | void |
3353 | void |
3254 | ev_prepare_start (EV_P_ ev_prepare *w) |
3354 | ev_prepare_start (EV_P_ ev_prepare *w) |
3255 | { |
3355 | { |
3256 | if (expect_false (ev_is_active (w))) |
3356 | if (expect_false (ev_is_active (w))) |
3257 | return; |
3357 | return; |
… | |
… | |
3283 | |
3383 | |
3284 | ev_stop (EV_A_ (W)w); |
3384 | ev_stop (EV_A_ (W)w); |
3285 | |
3385 | |
3286 | EV_FREQUENT_CHECK; |
3386 | EV_FREQUENT_CHECK; |
3287 | } |
3387 | } |
|
|
3388 | #endif |
3288 | |
3389 | |
|
|
3390 | #if EV_CHECK_ENABLE |
3289 | void |
3391 | void |
3290 | ev_check_start (EV_P_ ev_check *w) |
3392 | ev_check_start (EV_P_ ev_check *w) |
3291 | { |
3393 | { |
3292 | if (expect_false (ev_is_active (w))) |
3394 | if (expect_false (ev_is_active (w))) |
3293 | return; |
3395 | return; |
… | |
… | |
3319 | |
3421 | |
3320 | ev_stop (EV_A_ (W)w); |
3422 | ev_stop (EV_A_ (W)w); |
3321 | |
3423 | |
3322 | EV_FREQUENT_CHECK; |
3424 | EV_FREQUENT_CHECK; |
3323 | } |
3425 | } |
|
|
3426 | #endif |
3324 | |
3427 | |
3325 | #if EV_EMBED_ENABLE |
3428 | #if EV_EMBED_ENABLE |
3326 | void noinline |
3429 | void noinline |
3327 | ev_embed_sweep (EV_P_ ev_embed *w) |
3430 | ev_embed_sweep (EV_P_ ev_embed *w) |
3328 | { |
3431 | { |
3329 | ev_loop (w->other, EVLOOP_NONBLOCK); |
3432 | ev_run (w->other, EVRUN_NOWAIT); |
3330 | } |
3433 | } |
3331 | |
3434 | |
3332 | static void |
3435 | static void |
3333 | embed_io_cb (EV_P_ ev_io *io, int revents) |
3436 | embed_io_cb (EV_P_ ev_io *io, int revents) |
3334 | { |
3437 | { |
3335 | ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io)); |
3438 | ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io)); |
3336 | |
3439 | |
3337 | if (ev_cb (w)) |
3440 | if (ev_cb (w)) |
3338 | ev_feed_event (EV_A_ (W)w, EV_EMBED); |
3441 | ev_feed_event (EV_A_ (W)w, EV_EMBED); |
3339 | else |
3442 | else |
3340 | ev_loop (w->other, EVLOOP_NONBLOCK); |
3443 | ev_run (w->other, EVRUN_NOWAIT); |
3341 | } |
3444 | } |
3342 | |
3445 | |
3343 | static void |
3446 | static void |
3344 | embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents) |
3447 | embed_prepare_cb (EV_P_ ev_prepare *prepare, int revents) |
3345 | { |
3448 | { |
… | |
… | |
3349 | EV_P = w->other; |
3452 | EV_P = w->other; |
3350 | |
3453 | |
3351 | while (fdchangecnt) |
3454 | while (fdchangecnt) |
3352 | { |
3455 | { |
3353 | fd_reify (EV_A); |
3456 | fd_reify (EV_A); |
3354 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
3457 | ev_run (EV_A_ EVRUN_NOWAIT); |
3355 | } |
3458 | } |
3356 | } |
3459 | } |
3357 | } |
3460 | } |
3358 | |
3461 | |
3359 | static void |
3462 | static void |
… | |
… | |
3365 | |
3468 | |
3366 | { |
3469 | { |
3367 | EV_P = w->other; |
3470 | EV_P = w->other; |
3368 | |
3471 | |
3369 | ev_loop_fork (EV_A); |
3472 | ev_loop_fork (EV_A); |
3370 | ev_loop (EV_A_ EVLOOP_NONBLOCK); |
3473 | ev_run (EV_A_ EVRUN_NOWAIT); |
3371 | } |
3474 | } |
3372 | |
3475 | |
3373 | ev_embed_start (EV_A_ w); |
3476 | ev_embed_start (EV_A_ w); |
3374 | } |
3477 | } |
3375 | |
3478 | |
… | |
… | |
3423 | |
3526 | |
3424 | ev_io_stop (EV_A_ &w->io); |
3527 | ev_io_stop (EV_A_ &w->io); |
3425 | ev_prepare_stop (EV_A_ &w->prepare); |
3528 | ev_prepare_stop (EV_A_ &w->prepare); |
3426 | ev_fork_stop (EV_A_ &w->fork); |
3529 | ev_fork_stop (EV_A_ &w->fork); |
3427 | |
3530 | |
|
|
3531 | ev_stop (EV_A_ (W)w); |
|
|
3532 | |
3428 | EV_FREQUENT_CHECK; |
3533 | EV_FREQUENT_CHECK; |
3429 | } |
3534 | } |
3430 | #endif |
3535 | #endif |
3431 | |
3536 | |
3432 | #if EV_FORK_ENABLE |
3537 | #if EV_FORK_ENABLE |
… | |
… | |
3471 | void |
3576 | void |
3472 | ev_async_start (EV_P_ ev_async *w) |
3577 | ev_async_start (EV_P_ ev_async *w) |
3473 | { |
3578 | { |
3474 | if (expect_false (ev_is_active (w))) |
3579 | if (expect_false (ev_is_active (w))) |
3475 | return; |
3580 | return; |
|
|
3581 | |
|
|
3582 | w->sent = 0; |
3476 | |
3583 | |
3477 | evpipe_init (EV_A); |
3584 | evpipe_init (EV_A); |
3478 | |
3585 | |
3479 | EV_FREQUENT_CHECK; |
3586 | EV_FREQUENT_CHECK; |
3480 | |
3587 | |
… | |
… | |
3558 | { |
3665 | { |
3559 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3666 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3560 | |
3667 | |
3561 | if (expect_false (!once)) |
3668 | if (expect_false (!once)) |
3562 | { |
3669 | { |
3563 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
3670 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
3564 | return; |
3671 | return; |
3565 | } |
3672 | } |
3566 | |
3673 | |
3567 | once->cb = cb; |
3674 | once->cb = cb; |
3568 | once->arg = arg; |
3675 | once->arg = arg; |
… | |
… | |
3655 | if (types & EV_ASYNC) |
3762 | if (types & EV_ASYNC) |
3656 | for (i = asynccnt; i--; ) |
3763 | for (i = asynccnt; i--; ) |
3657 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3764 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3658 | #endif |
3765 | #endif |
3659 | |
3766 | |
|
|
3767 | #if EV_PREPARE_ENABLE |
3660 | if (types & EV_PREPARE) |
3768 | if (types & EV_PREPARE) |
3661 | for (i = preparecnt; i--; ) |
3769 | for (i = preparecnt; i--; ) |
3662 | #if EV_EMBED_ENABLE |
3770 | # if EV_EMBED_ENABLE |
3663 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3771 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3664 | #endif |
3772 | # endif |
3665 | cb (EV_A_ EV_PREPARE, prepares [i]); |
3773 | cb (EV_A_ EV_PREPARE, prepares [i]); |
|
|
3774 | #endif |
3666 | |
3775 | |
|
|
3776 | #if EV_CHECK_ENABLE |
3667 | if (types & EV_CHECK) |
3777 | if (types & EV_CHECK) |
3668 | for (i = checkcnt; i--; ) |
3778 | for (i = checkcnt; i--; ) |
3669 | cb (EV_A_ EV_CHECK, checks [i]); |
3779 | cb (EV_A_ EV_CHECK, checks [i]); |
|
|
3780 | #endif |
3670 | |
3781 | |
|
|
3782 | #if EV_SIGNAL_ENABLE |
3671 | if (types & EV_SIGNAL) |
3783 | if (types & EV_SIGNAL) |
3672 | for (i = 0; i < EV_NSIG - 1; ++i) |
3784 | for (i = 0; i < EV_NSIG - 1; ++i) |
3673 | for (wl = signals [i].head; wl; ) |
3785 | for (wl = signals [i].head; wl; ) |
3674 | { |
3786 | { |
3675 | wn = wl->next; |
3787 | wn = wl->next; |
3676 | cb (EV_A_ EV_SIGNAL, wl); |
3788 | cb (EV_A_ EV_SIGNAL, wl); |
3677 | wl = wn; |
3789 | wl = wn; |
3678 | } |
3790 | } |
|
|
3791 | #endif |
3679 | |
3792 | |
|
|
3793 | #if EV_CHILD_ENABLE |
3680 | if (types & EV_CHILD) |
3794 | if (types & EV_CHILD) |
3681 | for (i = EV_PID_HASHSIZE; i--; ) |
3795 | for (i = (EV_PID_HASHSIZE); i--; ) |
3682 | for (wl = childs [i]; wl; ) |
3796 | for (wl = childs [i]; wl; ) |
3683 | { |
3797 | { |
3684 | wn = wl->next; |
3798 | wn = wl->next; |
3685 | cb (EV_A_ EV_CHILD, wl); |
3799 | cb (EV_A_ EV_CHILD, wl); |
3686 | wl = wn; |
3800 | wl = wn; |
3687 | } |
3801 | } |
|
|
3802 | #endif |
3688 | /* EV_STAT 0x00001000 /* stat data changed */ |
3803 | /* EV_STAT 0x00001000 /* stat data changed */ |
3689 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3804 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3690 | } |
3805 | } |
3691 | #endif |
3806 | #endif |
3692 | |
3807 | |