… | |
… | |
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) |
… | |
… | |
219 | # define EV_NSIG 65 |
236 | # define EV_NSIG 65 |
220 | #endif |
237 | #endif |
221 | |
238 | |
222 | #ifndef EV_USE_CLOCK_SYSCALL |
239 | #ifndef EV_USE_CLOCK_SYSCALL |
223 | # if __linux && __GLIBC__ >= 2 |
240 | # if __linux && __GLIBC__ >= 2 |
224 | # define EV_USE_CLOCK_SYSCALL 1 |
241 | # define EV_USE_CLOCK_SYSCALL EV_FEATURE_OS |
225 | # else |
242 | # else |
226 | # define EV_USE_CLOCK_SYSCALL 0 |
243 | # define EV_USE_CLOCK_SYSCALL 0 |
227 | # endif |
244 | # endif |
228 | #endif |
245 | #endif |
229 | |
246 | |
230 | #ifndef EV_USE_MONOTONIC |
247 | #ifndef EV_USE_MONOTONIC |
231 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
248 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
232 | # define EV_USE_MONOTONIC 1 |
249 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
233 | # else |
250 | # else |
234 | # define EV_USE_MONOTONIC 0 |
251 | # define EV_USE_MONOTONIC 0 |
235 | # endif |
252 | # endif |
236 | #endif |
253 | #endif |
237 | |
254 | |
… | |
… | |
239 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
256 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
240 | #endif |
257 | #endif |
241 | |
258 | |
242 | #ifndef EV_USE_NANOSLEEP |
259 | #ifndef EV_USE_NANOSLEEP |
243 | # if _POSIX_C_SOURCE >= 199309L |
260 | # if _POSIX_C_SOURCE >= 199309L |
244 | # define EV_USE_NANOSLEEP 1 |
261 | # define EV_USE_NANOSLEEP EV_FEATURE_OS |
245 | # else |
262 | # else |
246 | # define EV_USE_NANOSLEEP 0 |
263 | # define EV_USE_NANOSLEEP 0 |
247 | # endif |
264 | # endif |
248 | #endif |
265 | #endif |
249 | |
266 | |
250 | #ifndef EV_USE_SELECT |
267 | #ifndef EV_USE_SELECT |
251 | # define EV_USE_SELECT 1 |
268 | # define EV_USE_SELECT EV_FEATURE_BACKENDS |
252 | #endif |
269 | #endif |
253 | |
270 | |
254 | #ifndef EV_USE_POLL |
271 | #ifndef EV_USE_POLL |
255 | # ifdef _WIN32 |
272 | # ifdef _WIN32 |
256 | # define EV_USE_POLL 0 |
273 | # define EV_USE_POLL 0 |
257 | # else |
274 | # else |
258 | # define EV_USE_POLL 1 |
275 | # define EV_USE_POLL EV_FEATURE_BACKENDS |
259 | # endif |
276 | # endif |
260 | #endif |
277 | #endif |
261 | |
278 | |
262 | #ifndef EV_USE_EPOLL |
279 | #ifndef EV_USE_EPOLL |
263 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
280 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
264 | # define EV_USE_EPOLL 1 |
281 | # define EV_USE_EPOLL EV_FEATURE_BACKENDS |
265 | # else |
282 | # else |
266 | # define EV_USE_EPOLL 0 |
283 | # define EV_USE_EPOLL 0 |
267 | # endif |
284 | # endif |
268 | #endif |
285 | #endif |
269 | |
286 | |
… | |
… | |
275 | # define EV_USE_PORT 0 |
292 | # define EV_USE_PORT 0 |
276 | #endif |
293 | #endif |
277 | |
294 | |
278 | #ifndef EV_USE_INOTIFY |
295 | #ifndef EV_USE_INOTIFY |
279 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
296 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
280 | # define EV_USE_INOTIFY 1 |
297 | # define EV_USE_INOTIFY EV_FEATURE_OS |
281 | # else |
298 | # else |
282 | # define EV_USE_INOTIFY 0 |
299 | # define EV_USE_INOTIFY 0 |
283 | # endif |
300 | # endif |
284 | #endif |
301 | #endif |
285 | |
302 | |
286 | #ifndef EV_PID_HASHSIZE |
303 | #ifndef EV_PID_HASHSIZE |
287 | # if EV_MINIMAL |
304 | # define EV_PID_HASHSIZE EV_FEATURE_DATA ? 16 : 1 |
288 | # define EV_PID_HASHSIZE 1 |
|
|
289 | # else |
|
|
290 | # define EV_PID_HASHSIZE 16 |
|
|
291 | # endif |
|
|
292 | #endif |
305 | #endif |
293 | |
306 | |
294 | #ifndef EV_INOTIFY_HASHSIZE |
307 | #ifndef EV_INOTIFY_HASHSIZE |
295 | # if EV_MINIMAL |
308 | # define EV_INOTIFY_HASHSIZE EV_FEATURE_DATA ? 16 : 1 |
296 | # define EV_INOTIFY_HASHSIZE 1 |
|
|
297 | # else |
|
|
298 | # define EV_INOTIFY_HASHSIZE 16 |
|
|
299 | # endif |
|
|
300 | #endif |
309 | #endif |
301 | |
310 | |
302 | #ifndef EV_USE_EVENTFD |
311 | #ifndef EV_USE_EVENTFD |
303 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
312 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
304 | # define EV_USE_EVENTFD 1 |
313 | # define EV_USE_EVENTFD EV_FEATURE_OS |
305 | # else |
314 | # else |
306 | # define EV_USE_EVENTFD 0 |
315 | # define EV_USE_EVENTFD 0 |
307 | # endif |
316 | # endif |
308 | #endif |
317 | #endif |
309 | |
318 | |
310 | #ifndef EV_USE_SIGNALFD |
319 | #ifndef EV_USE_SIGNALFD |
311 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
320 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
312 | # define EV_USE_SIGNALFD 1 |
321 | # define EV_USE_SIGNALFD EV_FEATURE_OS |
313 | # else |
322 | # else |
314 | # define EV_USE_SIGNALFD 0 |
323 | # define EV_USE_SIGNALFD 0 |
315 | # endif |
324 | # endif |
316 | #endif |
325 | #endif |
317 | |
326 | |
… | |
… | |
320 | # define EV_USE_4HEAP 1 |
329 | # define EV_USE_4HEAP 1 |
321 | # define EV_HEAP_CACHE_AT 1 |
330 | # define EV_HEAP_CACHE_AT 1 |
322 | #endif |
331 | #endif |
323 | |
332 | |
324 | #ifndef EV_VERIFY |
333 | #ifndef EV_VERIFY |
325 | # define EV_VERIFY !EV_MINIMAL |
334 | # define EV_VERIFY (EV_FEATURE_API ? 1 : 0) |
326 | #endif |
335 | #endif |
327 | |
336 | |
328 | #ifndef EV_USE_4HEAP |
337 | #ifndef EV_USE_4HEAP |
329 | # define EV_USE_4HEAP !EV_MINIMAL |
338 | # define EV_USE_4HEAP EV_FEATURE_DATA |
330 | #endif |
339 | #endif |
331 | |
340 | |
332 | #ifndef EV_HEAP_CACHE_AT |
341 | #ifndef EV_HEAP_CACHE_AT |
333 | # define EV_HEAP_CACHE_AT !EV_MINIMAL |
342 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
334 | #endif |
343 | #endif |
335 | |
344 | |
336 | /* 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, */ |
337 | /* which makes programs even slower. might work on other unices, too. */ |
346 | /* which makes programs even slower. might work on other unices, too. */ |
338 | #if EV_USE_CLOCK_SYSCALL |
347 | #if EV_USE_CLOCK_SYSCALL |
… | |
… | |
439 | # ifdef __cplusplus |
448 | # ifdef __cplusplus |
440 | } |
449 | } |
441 | # endif |
450 | # endif |
442 | #endif |
451 | #endif |
443 | |
452 | |
444 | |
|
|
445 | /**/ |
453 | /**/ |
446 | |
454 | |
447 | #if EV_VERIFY >= 3 |
455 | #if EV_VERIFY >= 3 |
448 | # define EV_FREQUENT_CHECK ev_loop_verify (EV_A) |
456 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
449 | #else |
457 | #else |
450 | # define EV_FREQUENT_CHECK do { } while (0) |
458 | # define EV_FREQUENT_CHECK do { } while (0) |
451 | #endif |
459 | #endif |
452 | |
460 | |
453 | /* |
461 | /* |
… | |
… | |
461 | #define TIME_EPSILON 0.0001220703125 /* 1/8192 */ |
469 | #define TIME_EPSILON 0.0001220703125 /* 1/8192 */ |
462 | |
470 | |
463 | #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) */ |
464 | #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) */ |
465 | |
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 | |
466 | #if __GNUC__ >= 4 |
477 | #if __GNUC__ >= 4 |
467 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
478 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
468 | # define noinline __attribute__ ((noinline)) |
479 | # define noinline __attribute__ ((noinline)) |
469 | #else |
480 | #else |
470 | # define expect(expr,value) (expr) |
481 | # define expect(expr,value) (expr) |
… | |
… | |
476 | |
487 | |
477 | #define expect_false(expr) expect ((expr) != 0, 0) |
488 | #define expect_false(expr) expect ((expr) != 0, 0) |
478 | #define expect_true(expr) expect ((expr) != 0, 1) |
489 | #define expect_true(expr) expect ((expr) != 0, 1) |
479 | #define inline_size static inline |
490 | #define inline_size static inline |
480 | |
491 | |
481 | #if EV_MINIMAL |
492 | #if EV_FEATURE_CODE |
|
|
493 | # define inline_speed static inline |
|
|
494 | #else |
482 | # define inline_speed static noinline |
495 | # define inline_speed static noinline |
483 | #else |
|
|
484 | # define inline_speed static inline |
|
|
485 | #endif |
496 | #endif |
486 | |
497 | |
487 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
498 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
488 | |
499 | |
489 | #if EV_MINPRI == EV_MAXPRI |
500 | #if EV_MINPRI == EV_MAXPRI |
… | |
… | |
502 | #define ev_active(w) ((W)(w))->active |
513 | #define ev_active(w) ((W)(w))->active |
503 | #define ev_at(w) ((WT)(w))->at |
514 | #define ev_at(w) ((WT)(w))->at |
504 | |
515 | |
505 | #if EV_USE_REALTIME |
516 | #if EV_USE_REALTIME |
506 | /* 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 */ |
507 | /* giving it a reasonably high chance of working on typical architetcures */ |
518 | /* giving it a reasonably high chance of working on typical architectures */ |
508 | 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? */ |
509 | #endif |
520 | #endif |
510 | |
521 | |
511 | #if EV_USE_MONOTONIC |
522 | #if EV_USE_MONOTONIC |
512 | 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? */ |
… | |
… | |
696 | |
707 | |
697 | static int ev_default_loop_ptr; |
708 | static int ev_default_loop_ptr; |
698 | |
709 | |
699 | #endif |
710 | #endif |
700 | |
711 | |
701 | #if EV_MINIMAL < 2 |
712 | #if EV_FEATURE_API |
702 | # 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) |
703 | # 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) |
704 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
715 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
705 | #else |
716 | #else |
706 | # define EV_RELEASE_CB (void)0 |
717 | # define EV_RELEASE_CB (void)0 |
… | |
… | |
760 | if (delay > 0.) |
771 | if (delay > 0.) |
761 | { |
772 | { |
762 | #if EV_USE_NANOSLEEP |
773 | #if EV_USE_NANOSLEEP |
763 | struct timespec ts; |
774 | struct timespec ts; |
764 | |
775 | |
765 | ts.tv_sec = (time_t)delay; |
776 | EV_TS_SET (ts, delay); |
766 | ts.tv_nsec = (long)((delay - (ev_tstamp)(ts.tv_sec)) * 1e9); |
|
|
767 | |
|
|
768 | nanosleep (&ts, 0); |
777 | nanosleep (&ts, 0); |
769 | #elif defined(_WIN32) |
778 | #elif defined(_WIN32) |
770 | Sleep ((unsigned long)(delay * 1e3)); |
779 | Sleep ((unsigned long)(delay * 1e3)); |
771 | #else |
780 | #else |
772 | struct timeval tv; |
781 | struct timeval tv; |
773 | |
782 | |
774 | tv.tv_sec = (time_t)delay; |
|
|
775 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
|
|
776 | |
|
|
777 | /* 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 */ |
778 | /* something not guaranteed by newer posix versions, but guaranteed */ |
784 | /* something not guaranteed by newer posix versions, but guaranteed */ |
779 | /* by older ones */ |
785 | /* by older ones */ |
|
|
786 | EV_TV_SET (tv, delay); |
780 | select (0, 0, 0, 0, &tv); |
787 | select (0, 0, 0, 0, &tv); |
781 | #endif |
788 | #endif |
782 | } |
789 | } |
783 | } |
790 | } |
784 | |
791 | |
785 | /*****************************************************************************/ |
792 | /*****************************************************************************/ |
786 | |
793 | |
787 | #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 */ |
788 | |
795 | |
789 | /* find a suitable new size for the given array, */ |
796 | /* find a suitable new size for the given array, */ |
790 | /* hopefully by rounding to a ncie-to-malloc size */ |
797 | /* hopefully by rounding to a nice-to-malloc size */ |
791 | inline_size int |
798 | inline_size int |
792 | array_nextsize (int elem, int cur, int cnt) |
799 | array_nextsize (int elem, int cur, int cnt) |
793 | { |
800 | { |
794 | int ncur = cur + 1; |
801 | int ncur = cur + 1; |
795 | |
802 | |
… | |
… | |
891 | } |
898 | } |
892 | |
899 | |
893 | /*****************************************************************************/ |
900 | /*****************************************************************************/ |
894 | |
901 | |
895 | inline_speed void |
902 | inline_speed void |
896 | fd_event_nc (EV_P_ int fd, int revents) |
903 | fd_event_nocheck (EV_P_ int fd, int revents) |
897 | { |
904 | { |
898 | ANFD *anfd = anfds + fd; |
905 | ANFD *anfd = anfds + fd; |
899 | ev_io *w; |
906 | ev_io *w; |
900 | |
907 | |
901 | 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) |
… | |
… | |
913 | fd_event (EV_P_ int fd, int revents) |
920 | fd_event (EV_P_ int fd, int revents) |
914 | { |
921 | { |
915 | ANFD *anfd = anfds + fd; |
922 | ANFD *anfd = anfds + fd; |
916 | |
923 | |
917 | if (expect_true (!anfd->reify)) |
924 | if (expect_true (!anfd->reify)) |
918 | fd_event_nc (EV_A_ fd, revents); |
925 | fd_event_nocheck (EV_A_ fd, revents); |
919 | } |
926 | } |
920 | |
927 | |
921 | void |
928 | void |
922 | ev_feed_fd_event (EV_P_ int fd, int revents) |
929 | ev_feed_fd_event (EV_P_ int fd, int revents) |
923 | { |
930 | { |
924 | if (fd >= 0 && fd < anfdmax) |
931 | if (fd >= 0 && fd < anfdmax) |
925 | fd_event_nc (EV_A_ fd, revents); |
932 | fd_event_nocheck (EV_A_ fd, revents); |
926 | } |
933 | } |
927 | |
934 | |
928 | /* make sure the external fd watch events are in-sync */ |
935 | /* make sure the external fd watch events are in-sync */ |
929 | /* with the kernel/libev internal state */ |
936 | /* with the kernel/libev internal state */ |
930 | inline_size void |
937 | inline_size void |
… | |
… | |
1062 | } |
1069 | } |
1063 | |
1070 | |
1064 | /*****************************************************************************/ |
1071 | /*****************************************************************************/ |
1065 | |
1072 | |
1066 | /* |
1073 | /* |
1067 | * the heap functions want a real array index. array index 0 uis guaranteed to not |
1074 | * the heap functions want a real array index. array index 0 is guaranteed to not |
1068 | * be in-use at any time. the first heap entry is at array [HEAP0]. DHEAP gives |
1075 | * be in-use at any time. the first heap entry is at array [HEAP0]. DHEAP gives |
1069 | * the branching factor of the d-tree. |
1076 | * the branching factor of the d-tree. |
1070 | */ |
1077 | */ |
1071 | |
1078 | |
1072 | /* |
1079 | /* |
… | |
… | |
1272 | uint64_t counter = 1; |
1279 | uint64_t counter = 1; |
1273 | write (evfd, &counter, sizeof (uint64_t)); |
1280 | write (evfd, &counter, sizeof (uint64_t)); |
1274 | } |
1281 | } |
1275 | else |
1282 | else |
1276 | #endif |
1283 | #endif |
|
|
1284 | /* win32 people keep sending patches that change this write() to send() */ |
|
|
1285 | /* and then run away. but send() is wrong, it wants a socket handle on win32 */ |
|
|
1286 | /* so when you think this write should be a send instead, please find out */ |
|
|
1287 | /* where your send() is from - it's definitely not the microsoft send, and */ |
|
|
1288 | /* tell me. thank you. */ |
1277 | write (evpipe [1], &dummy, 1); |
1289 | write (evpipe [1], &dummy, 1); |
1278 | |
1290 | |
1279 | errno = old_errno; |
1291 | errno = old_errno; |
1280 | } |
1292 | } |
1281 | } |
1293 | } |
… | |
… | |
1295 | } |
1307 | } |
1296 | else |
1308 | else |
1297 | #endif |
1309 | #endif |
1298 | { |
1310 | { |
1299 | char dummy; |
1311 | char dummy; |
|
|
1312 | /* see discussion in evpipe_write when you think this read should be recv in win32 */ |
1300 | read (evpipe [0], &dummy, 1); |
1313 | read (evpipe [0], &dummy, 1); |
1301 | } |
1314 | } |
1302 | |
1315 | |
1303 | if (sig_pending) |
1316 | if (sig_pending) |
1304 | { |
1317 | { |
… | |
… | |
1403 | child_reap (EV_P_ int chain, int pid, int status) |
1416 | child_reap (EV_P_ int chain, int pid, int status) |
1404 | { |
1417 | { |
1405 | ev_child *w; |
1418 | ev_child *w; |
1406 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1419 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1407 | |
1420 | |
1408 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1421 | for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next) |
1409 | { |
1422 | { |
1410 | if ((w->pid == pid || !w->pid) |
1423 | if ((w->pid == pid || !w->pid) |
1411 | && (!traced || (w->flags & 1))) |
1424 | && (!traced || (w->flags & 1))) |
1412 | { |
1425 | { |
1413 | ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ |
1426 | ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ |
… | |
… | |
1438 | /* make sure we are called again until all children have been reaped */ |
1451 | /* make sure we are called again until all children have been reaped */ |
1439 | /* we need to do it this way so that the callback gets called before we continue */ |
1452 | /* we need to do it this way so that the callback gets called before we continue */ |
1440 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1453 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1441 | |
1454 | |
1442 | child_reap (EV_A_ pid, pid, status); |
1455 | child_reap (EV_A_ pid, pid, status); |
1443 | if (EV_PID_HASHSIZE > 1) |
1456 | if ((EV_PID_HASHSIZE) > 1) |
1444 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
1457 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
1445 | } |
1458 | } |
1446 | |
1459 | |
1447 | #endif |
1460 | #endif |
1448 | |
1461 | |
… | |
… | |
1515 | #ifdef __APPLE__ |
1528 | #ifdef __APPLE__ |
1516 | /* only select works correctly on that "unix-certified" platform */ |
1529 | /* only select works correctly on that "unix-certified" platform */ |
1517 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1530 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1518 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
1531 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
1519 | #endif |
1532 | #endif |
|
|
1533 | #ifdef __FreeBSD__ |
|
|
1534 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
|
|
1535 | #endif |
1520 | |
1536 | |
1521 | return flags; |
1537 | return flags; |
1522 | } |
1538 | } |
1523 | |
1539 | |
1524 | unsigned int |
1540 | unsigned int |
… | |
… | |
1537 | ev_backend (EV_P) |
1553 | ev_backend (EV_P) |
1538 | { |
1554 | { |
1539 | return backend; |
1555 | return backend; |
1540 | } |
1556 | } |
1541 | |
1557 | |
1542 | #if EV_MINIMAL < 2 |
1558 | #if EV_FEATURE_API |
1543 | unsigned int |
1559 | unsigned int |
1544 | ev_loop_count (EV_P) |
1560 | ev_iteration (EV_P) |
1545 | { |
1561 | { |
1546 | return loop_count; |
1562 | return loop_count; |
1547 | } |
1563 | } |
1548 | |
1564 | |
1549 | unsigned int |
1565 | unsigned int |
1550 | ev_loop_depth (EV_P) |
1566 | ev_depth (EV_P) |
1551 | { |
1567 | { |
1552 | return loop_depth; |
1568 | return loop_depth; |
1553 | } |
1569 | } |
1554 | |
1570 | |
1555 | void |
1571 | void |
… | |
… | |
1627 | |
1643 | |
1628 | ev_rt_now = ev_time (); |
1644 | ev_rt_now = ev_time (); |
1629 | mn_now = get_clock (); |
1645 | mn_now = get_clock (); |
1630 | now_floor = mn_now; |
1646 | now_floor = mn_now; |
1631 | rtmn_diff = ev_rt_now - mn_now; |
1647 | rtmn_diff = ev_rt_now - mn_now; |
1632 | #if EV_MINIMAL < 2 |
1648 | #if EV_FEATURE_API |
1633 | invoke_cb = ev_invoke_pending; |
1649 | invoke_cb = ev_invoke_pending; |
1634 | #endif |
1650 | #endif |
1635 | |
1651 | |
1636 | io_blocktime = 0.; |
1652 | io_blocktime = 0.; |
1637 | timeout_blocktime = 0.; |
1653 | timeout_blocktime = 0.; |
… | |
… | |
1798 | { |
1814 | { |
1799 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1815 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1800 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1816 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1801 | } |
1817 | } |
1802 | |
1818 | |
|
|
1819 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1803 | evpipe_init (EV_A); |
1820 | evpipe_init (EV_A); |
1804 | /* now iterate over everything, in case we missed something */ |
1821 | /* now iterate over everything, in case we missed something */ |
1805 | pipecb (EV_A_ &pipe_w, EV_READ); |
1822 | pipecb (EV_A_ &pipe_w, EV_READ); |
|
|
1823 | #endif |
1806 | } |
1824 | } |
1807 | |
1825 | |
1808 | postfork = 0; |
1826 | postfork = 0; |
1809 | } |
1827 | } |
1810 | |
1828 | |
… | |
… | |
1872 | verify_watcher (EV_A_ ws [cnt]); |
1890 | verify_watcher (EV_A_ ws [cnt]); |
1873 | } |
1891 | } |
1874 | } |
1892 | } |
1875 | #endif |
1893 | #endif |
1876 | |
1894 | |
1877 | #if EV_MINIMAL < 2 |
1895 | #if EV_FEATURE_API |
1878 | void |
1896 | void |
1879 | ev_loop_verify (EV_P) |
1897 | ev_verify (EV_P) |
1880 | { |
1898 | { |
1881 | #if EV_VERIFY |
1899 | #if EV_VERIFY |
1882 | int i; |
1900 | int i; |
1883 | WL w; |
1901 | WL w; |
1884 | |
1902 | |
… | |
… | |
1923 | #if EV_ASYNC_ENABLE |
1941 | #if EV_ASYNC_ENABLE |
1924 | assert (asyncmax >= asynccnt); |
1942 | assert (asyncmax >= asynccnt); |
1925 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1943 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1926 | #endif |
1944 | #endif |
1927 | |
1945 | |
|
|
1946 | #if EV_PREPARE_ENABLE |
1928 | assert (preparemax >= preparecnt); |
1947 | assert (preparemax >= preparecnt); |
1929 | array_verify (EV_A_ (W *)prepares, preparecnt); |
1948 | array_verify (EV_A_ (W *)prepares, preparecnt); |
|
|
1949 | #endif |
1930 | |
1950 | |
|
|
1951 | #if EV_CHECK_ENABLE |
1931 | assert (checkmax >= checkcnt); |
1952 | assert (checkmax >= checkcnt); |
1932 | array_verify (EV_A_ (W *)checks, checkcnt); |
1953 | array_verify (EV_A_ (W *)checks, checkcnt); |
|
|
1954 | #endif |
1933 | |
1955 | |
1934 | # if 0 |
1956 | # if 0 |
1935 | #if EV_CHILD_ENABLE |
1957 | #if EV_CHILD_ENABLE |
1936 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1958 | for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next) |
1937 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
1959 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
1938 | #endif |
1960 | #endif |
1939 | # endif |
1961 | # endif |
1940 | #endif |
1962 | #endif |
1941 | } |
1963 | } |
… | |
… | |
2098 | EV_FREQUENT_CHECK; |
2120 | EV_FREQUENT_CHECK; |
2099 | feed_reverse (EV_A_ (W)w); |
2121 | feed_reverse (EV_A_ (W)w); |
2100 | } |
2122 | } |
2101 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2123 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2102 | |
2124 | |
2103 | feed_reverse_done (EV_A_ EV_TIMEOUT); |
2125 | feed_reverse_done (EV_A_ EV_TIMER); |
2104 | } |
2126 | } |
2105 | } |
2127 | } |
2106 | |
2128 | |
2107 | #if EV_PERIODIC_ENABLE |
2129 | #if EV_PERIODIC_ENABLE |
2108 | /* make periodics pending */ |
2130 | /* make periodics pending */ |
… | |
… | |
2161 | feed_reverse_done (EV_A_ EV_PERIODIC); |
2183 | feed_reverse_done (EV_A_ EV_PERIODIC); |
2162 | } |
2184 | } |
2163 | } |
2185 | } |
2164 | |
2186 | |
2165 | /* simply recalculate all periodics */ |
2187 | /* simply recalculate all periodics */ |
2166 | /* TODO: maybe ensure that at leats one event happens when jumping forward? */ |
2188 | /* TODO: maybe ensure that at least one event happens when jumping forward? */ |
2167 | static void noinline |
2189 | static void noinline |
2168 | periodics_reschedule (EV_P) |
2190 | periodics_reschedule (EV_P) |
2169 | { |
2191 | { |
2170 | int i; |
2192 | int i; |
2171 | |
2193 | |
… | |
… | |
2269 | } |
2291 | } |
2270 | |
2292 | |
2271 | void |
2293 | void |
2272 | ev_loop (EV_P_ int flags) |
2294 | ev_loop (EV_P_ int flags) |
2273 | { |
2295 | { |
2274 | #if EV_MINIMAL < 2 |
2296 | #if EV_FEATURE_API |
2275 | ++loop_depth; |
2297 | ++loop_depth; |
2276 | #endif |
2298 | #endif |
2277 | |
2299 | |
2278 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2300 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2279 | |
2301 | |
… | |
… | |
2282 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2304 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2283 | |
2305 | |
2284 | do |
2306 | do |
2285 | { |
2307 | { |
2286 | #if EV_VERIFY >= 2 |
2308 | #if EV_VERIFY >= 2 |
2287 | ev_loop_verify (EV_A); |
2309 | ev_verify (EV_A); |
2288 | #endif |
2310 | #endif |
2289 | |
2311 | |
2290 | #ifndef _WIN32 |
2312 | #ifndef _WIN32 |
2291 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2313 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2292 | if (expect_false (getpid () != curpid)) |
2314 | if (expect_false (getpid () != curpid)) |
… | |
… | |
2304 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2326 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2305 | EV_INVOKE_PENDING; |
2327 | EV_INVOKE_PENDING; |
2306 | } |
2328 | } |
2307 | #endif |
2329 | #endif |
2308 | |
2330 | |
|
|
2331 | #if EV_PREPARE_ENABLE |
2309 | /* queue prepare watchers (and execute them) */ |
2332 | /* queue prepare watchers (and execute them) */ |
2310 | if (expect_false (preparecnt)) |
2333 | if (expect_false (preparecnt)) |
2311 | { |
2334 | { |
2312 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2335 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2313 | EV_INVOKE_PENDING; |
2336 | EV_INVOKE_PENDING; |
2314 | } |
2337 | } |
|
|
2338 | #endif |
2315 | |
2339 | |
2316 | if (expect_false (loop_done)) |
2340 | if (expect_false (loop_done)) |
2317 | break; |
2341 | break; |
2318 | |
2342 | |
2319 | /* we might have forked, so reify kernel state if necessary */ |
2343 | /* we might have forked, so reify kernel state if necessary */ |
… | |
… | |
2370 | waittime -= sleeptime; |
2394 | waittime -= sleeptime; |
2371 | } |
2395 | } |
2372 | } |
2396 | } |
2373 | } |
2397 | } |
2374 | |
2398 | |
2375 | #if EV_MINIMAL < 2 |
2399 | #if EV_FEATURE_API |
2376 | ++loop_count; |
2400 | ++loop_count; |
2377 | #endif |
2401 | #endif |
2378 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2402 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2379 | backend_poll (EV_A_ waittime); |
2403 | backend_poll (EV_A_ waittime); |
2380 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
2404 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
… | |
… | |
2392 | #if EV_IDLE_ENABLE |
2416 | #if EV_IDLE_ENABLE |
2393 | /* queue idle watchers unless other events are pending */ |
2417 | /* queue idle watchers unless other events are pending */ |
2394 | idle_reify (EV_A); |
2418 | idle_reify (EV_A); |
2395 | #endif |
2419 | #endif |
2396 | |
2420 | |
|
|
2421 | #if EV_CHECK_ENABLE |
2397 | /* queue check watchers, to be executed first */ |
2422 | /* queue check watchers, to be executed first */ |
2398 | if (expect_false (checkcnt)) |
2423 | if (expect_false (checkcnt)) |
2399 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
2424 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
|
|
2425 | #endif |
2400 | |
2426 | |
2401 | EV_INVOKE_PENDING; |
2427 | EV_INVOKE_PENDING; |
2402 | } |
2428 | } |
2403 | while (expect_true ( |
2429 | while (expect_true ( |
2404 | activecnt |
2430 | activecnt |
… | |
… | |
2407 | )); |
2433 | )); |
2408 | |
2434 | |
2409 | if (loop_done == EVUNLOOP_ONE) |
2435 | if (loop_done == EVUNLOOP_ONE) |
2410 | loop_done = EVUNLOOP_CANCEL; |
2436 | loop_done = EVUNLOOP_CANCEL; |
2411 | |
2437 | |
2412 | #if EV_MINIMAL < 2 |
2438 | #if EV_FEATURE_API |
2413 | --loop_depth; |
2439 | --loop_depth; |
2414 | #endif |
2440 | #endif |
2415 | } |
2441 | } |
2416 | |
2442 | |
2417 | void |
2443 | void |
… | |
… | |
2867 | return; |
2893 | return; |
2868 | |
2894 | |
2869 | EV_FREQUENT_CHECK; |
2895 | EV_FREQUENT_CHECK; |
2870 | |
2896 | |
2871 | ev_start (EV_A_ (W)w, 1); |
2897 | ev_start (EV_A_ (W)w, 1); |
2872 | wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2898 | wlist_add (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2873 | |
2899 | |
2874 | EV_FREQUENT_CHECK; |
2900 | EV_FREQUENT_CHECK; |
2875 | } |
2901 | } |
2876 | |
2902 | |
2877 | void |
2903 | void |
… | |
… | |
2881 | if (expect_false (!ev_is_active (w))) |
2907 | if (expect_false (!ev_is_active (w))) |
2882 | return; |
2908 | return; |
2883 | |
2909 | |
2884 | EV_FREQUENT_CHECK; |
2910 | EV_FREQUENT_CHECK; |
2885 | |
2911 | |
2886 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2912 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2887 | ev_stop (EV_A_ (W)w); |
2913 | ev_stop (EV_A_ (W)w); |
2888 | |
2914 | |
2889 | EV_FREQUENT_CHECK; |
2915 | EV_FREQUENT_CHECK; |
2890 | } |
2916 | } |
2891 | |
2917 | |
… | |
… | |
2964 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2990 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2965 | } |
2991 | } |
2966 | } |
2992 | } |
2967 | |
2993 | |
2968 | if (w->wd >= 0) |
2994 | if (w->wd >= 0) |
2969 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2995 | wlist_add (&fs_hash [w->wd & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
2970 | |
2996 | |
2971 | /* now re-arm timer, if required */ |
2997 | /* now re-arm timer, if required */ |
2972 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2998 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2973 | ev_timer_again (EV_A_ &w->timer); |
2999 | ev_timer_again (EV_A_ &w->timer); |
2974 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
3000 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
… | |
… | |
2982 | |
3008 | |
2983 | if (wd < 0) |
3009 | if (wd < 0) |
2984 | return; |
3010 | return; |
2985 | |
3011 | |
2986 | w->wd = -2; |
3012 | w->wd = -2; |
2987 | slot = wd & (EV_INOTIFY_HASHSIZE - 1); |
3013 | slot = wd & ((EV_INOTIFY_HASHSIZE) - 1); |
2988 | wlist_del (&fs_hash [slot].head, (WL)w); |
3014 | wlist_del (&fs_hash [slot].head, (WL)w); |
2989 | |
3015 | |
2990 | /* remove this watcher, if others are watching it, they will rearm */ |
3016 | /* remove this watcher, if others are watching it, they will rearm */ |
2991 | inotify_rm_watch (fs_fd, wd); |
3017 | inotify_rm_watch (fs_fd, wd); |
2992 | } |
3018 | } |
… | |
… | |
2994 | static void noinline |
3020 | static void noinline |
2995 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
3021 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
2996 | { |
3022 | { |
2997 | if (slot < 0) |
3023 | if (slot < 0) |
2998 | /* overflow, need to check for all hash slots */ |
3024 | /* overflow, need to check for all hash slots */ |
2999 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3025 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
3000 | infy_wd (EV_A_ slot, wd, ev); |
3026 | infy_wd (EV_A_ slot, wd, ev); |
3001 | else |
3027 | else |
3002 | { |
3028 | { |
3003 | WL w_; |
3029 | WL w_; |
3004 | |
3030 | |
3005 | for (w_ = fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head; w_; ) |
3031 | for (w_ = fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head; w_; ) |
3006 | { |
3032 | { |
3007 | ev_stat *w = (ev_stat *)w_; |
3033 | ev_stat *w = (ev_stat *)w_; |
3008 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
3034 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
3009 | |
3035 | |
3010 | if (w->wd == wd || wd == -1) |
3036 | if (w->wd == wd || wd == -1) |
3011 | { |
3037 | { |
3012 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
3038 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
3013 | { |
3039 | { |
3014 | wlist_del (&fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
3040 | wlist_del (&fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
3015 | w->wd = -1; |
3041 | w->wd = -1; |
3016 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3042 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3017 | } |
3043 | } |
3018 | |
3044 | |
3019 | stat_timer_cb (EV_A_ &w->timer, 0); |
3045 | stat_timer_cb (EV_A_ &w->timer, 0); |
… | |
… | |
3133 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3159 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3134 | ev_io_start (EV_A_ &fs_w); |
3160 | ev_io_start (EV_A_ &fs_w); |
3135 | ev_unref (EV_A); |
3161 | ev_unref (EV_A); |
3136 | } |
3162 | } |
3137 | |
3163 | |
3138 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3164 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
3139 | { |
3165 | { |
3140 | WL w_ = fs_hash [slot].head; |
3166 | WL w_ = fs_hash [slot].head; |
3141 | fs_hash [slot].head = 0; |
3167 | fs_hash [slot].head = 0; |
3142 | |
3168 | |
3143 | while (w_) |
3169 | while (w_) |
… | |
… | |
3318 | |
3344 | |
3319 | EV_FREQUENT_CHECK; |
3345 | EV_FREQUENT_CHECK; |
3320 | } |
3346 | } |
3321 | #endif |
3347 | #endif |
3322 | |
3348 | |
|
|
3349 | #if EV_PREPARE_ENABLE |
3323 | void |
3350 | void |
3324 | ev_prepare_start (EV_P_ ev_prepare *w) |
3351 | ev_prepare_start (EV_P_ ev_prepare *w) |
3325 | { |
3352 | { |
3326 | if (expect_false (ev_is_active (w))) |
3353 | if (expect_false (ev_is_active (w))) |
3327 | return; |
3354 | return; |
… | |
… | |
3353 | |
3380 | |
3354 | ev_stop (EV_A_ (W)w); |
3381 | ev_stop (EV_A_ (W)w); |
3355 | |
3382 | |
3356 | EV_FREQUENT_CHECK; |
3383 | EV_FREQUENT_CHECK; |
3357 | } |
3384 | } |
|
|
3385 | #endif |
3358 | |
3386 | |
|
|
3387 | #if EV_CHECK_ENABLE |
3359 | void |
3388 | void |
3360 | ev_check_start (EV_P_ ev_check *w) |
3389 | ev_check_start (EV_P_ ev_check *w) |
3361 | { |
3390 | { |
3362 | if (expect_false (ev_is_active (w))) |
3391 | if (expect_false (ev_is_active (w))) |
3363 | return; |
3392 | return; |
… | |
… | |
3389 | |
3418 | |
3390 | ev_stop (EV_A_ (W)w); |
3419 | ev_stop (EV_A_ (W)w); |
3391 | |
3420 | |
3392 | EV_FREQUENT_CHECK; |
3421 | EV_FREQUENT_CHECK; |
3393 | } |
3422 | } |
|
|
3423 | #endif |
3394 | |
3424 | |
3395 | #if EV_EMBED_ENABLE |
3425 | #if EV_EMBED_ENABLE |
3396 | void noinline |
3426 | void noinline |
3397 | ev_embed_sweep (EV_P_ ev_embed *w) |
3427 | ev_embed_sweep (EV_P_ ev_embed *w) |
3398 | { |
3428 | { |
… | |
… | |
3630 | { |
3660 | { |
3631 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3661 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3632 | |
3662 | |
3633 | if (expect_false (!once)) |
3663 | if (expect_false (!once)) |
3634 | { |
3664 | { |
3635 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
3665 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
3636 | return; |
3666 | return; |
3637 | } |
3667 | } |
3638 | |
3668 | |
3639 | once->cb = cb; |
3669 | once->cb = cb; |
3640 | once->arg = arg; |
3670 | once->arg = arg; |
… | |
… | |
3727 | if (types & EV_ASYNC) |
3757 | if (types & EV_ASYNC) |
3728 | for (i = asynccnt; i--; ) |
3758 | for (i = asynccnt; i--; ) |
3729 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3759 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3730 | #endif |
3760 | #endif |
3731 | |
3761 | |
|
|
3762 | #if EV_PREPARE_ENABLE |
3732 | if (types & EV_PREPARE) |
3763 | if (types & EV_PREPARE) |
3733 | for (i = preparecnt; i--; ) |
3764 | for (i = preparecnt; i--; ) |
3734 | #if EV_EMBED_ENABLE |
3765 | # if EV_EMBED_ENABLE |
3735 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3766 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3736 | #endif |
3767 | # endif |
3737 | cb (EV_A_ EV_PREPARE, prepares [i]); |
3768 | cb (EV_A_ EV_PREPARE, prepares [i]); |
|
|
3769 | #endif |
3738 | |
3770 | |
|
|
3771 | #if EV_CHECK_ENABLE |
3739 | if (types & EV_CHECK) |
3772 | if (types & EV_CHECK) |
3740 | for (i = checkcnt; i--; ) |
3773 | for (i = checkcnt; i--; ) |
3741 | cb (EV_A_ EV_CHECK, checks [i]); |
3774 | cb (EV_A_ EV_CHECK, checks [i]); |
|
|
3775 | #endif |
3742 | |
3776 | |
|
|
3777 | #if EV_SIGNAL_ENABLE |
3743 | if (types & EV_SIGNAL) |
3778 | if (types & EV_SIGNAL) |
3744 | for (i = 0; i < EV_NSIG - 1; ++i) |
3779 | for (i = 0; i < EV_NSIG - 1; ++i) |
3745 | for (wl = signals [i].head; wl; ) |
3780 | for (wl = signals [i].head; wl; ) |
3746 | { |
3781 | { |
3747 | wn = wl->next; |
3782 | wn = wl->next; |
3748 | cb (EV_A_ EV_SIGNAL, wl); |
3783 | cb (EV_A_ EV_SIGNAL, wl); |
3749 | wl = wn; |
3784 | wl = wn; |
3750 | } |
3785 | } |
|
|
3786 | #endif |
3751 | |
3787 | |
|
|
3788 | #if EV_CHILD_ENABLE |
3752 | if (types & EV_CHILD) |
3789 | if (types & EV_CHILD) |
3753 | for (i = EV_PID_HASHSIZE; i--; ) |
3790 | for (i = (EV_PID_HASHSIZE); i--; ) |
3754 | for (wl = childs [i]; wl; ) |
3791 | for (wl = childs [i]; wl; ) |
3755 | { |
3792 | { |
3756 | wn = wl->next; |
3793 | wn = wl->next; |
3757 | cb (EV_A_ EV_CHILD, wl); |
3794 | cb (EV_A_ EV_CHILD, wl); |
3758 | wl = wn; |
3795 | wl = wn; |
3759 | } |
3796 | } |
|
|
3797 | #endif |
3760 | /* EV_STAT 0x00001000 /* stat data changed */ |
3798 | /* EV_STAT 0x00001000 /* stat data changed */ |
3761 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3799 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3762 | } |
3800 | } |
3763 | #endif |
3801 | #endif |
3764 | |
3802 | |