… | |
… | |
79 | # endif |
79 | # endif |
80 | # endif |
80 | # endif |
81 | |
81 | |
82 | # ifndef EV_USE_NANOSLEEP |
82 | # ifndef EV_USE_NANOSLEEP |
83 | # if HAVE_NANOSLEEP |
83 | # if HAVE_NANOSLEEP |
84 | # define EV_USE_NANOSLEEP 1 |
84 | # define EV_USE_NANOSLEEP EV_FEATURE_OS |
85 | # else |
85 | # else |
86 | # define EV_USE_NANOSLEEP 0 |
86 | # define EV_USE_NANOSLEEP 0 |
87 | # endif |
87 | # endif |
88 | # endif |
88 | # endif |
89 | |
89 | |
90 | # ifndef EV_USE_SELECT |
90 | # ifndef EV_USE_SELECT |
91 | # if HAVE_SELECT && HAVE_SYS_SELECT_H |
91 | # if HAVE_SELECT && HAVE_SYS_SELECT_H |
92 | # define EV_USE_SELECT 1 |
92 | # define EV_USE_SELECT EV_FEATURE_BACKENDS |
93 | # else |
93 | # else |
94 | # define EV_USE_SELECT 0 |
94 | # define EV_USE_SELECT 0 |
95 | # endif |
95 | # endif |
96 | # endif |
96 | # endif |
97 | |
97 | |
98 | # ifndef EV_USE_POLL |
98 | # ifndef EV_USE_POLL |
99 | # if HAVE_POLL && HAVE_POLL_H |
99 | # if HAVE_POLL && HAVE_POLL_H |
100 | # define EV_USE_POLL 1 |
100 | # define EV_USE_POLL EV_FEATURE_BACKENDS |
101 | # else |
101 | # else |
102 | # define EV_USE_POLL 0 |
102 | # define EV_USE_POLL 0 |
103 | # endif |
103 | # endif |
104 | # endif |
104 | # endif |
105 | |
105 | |
106 | # ifndef EV_USE_EPOLL |
106 | # ifndef EV_USE_EPOLL |
107 | # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H |
107 | # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H |
108 | # define EV_USE_EPOLL 1 |
108 | # define EV_USE_EPOLL EV_FEATURE_BACKENDS |
109 | # else |
109 | # else |
110 | # define EV_USE_EPOLL 0 |
110 | # define EV_USE_EPOLL 0 |
111 | # endif |
111 | # endif |
112 | # endif |
112 | # endif |
113 | |
113 | |
114 | # ifndef EV_USE_KQUEUE |
114 | # ifndef EV_USE_KQUEUE |
115 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
115 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
116 | # define EV_USE_KQUEUE 1 |
116 | # define EV_USE_KQUEUE EV_FEATURE_BACKENDS |
117 | # else |
117 | # else |
118 | # define EV_USE_KQUEUE 0 |
118 | # define EV_USE_KQUEUE 0 |
119 | # endif |
119 | # endif |
120 | # endif |
120 | # endif |
121 | |
121 | |
122 | # ifndef EV_USE_PORT |
122 | # ifndef EV_USE_PORT |
123 | # if HAVE_PORT_H && HAVE_PORT_CREATE |
123 | # if HAVE_PORT_H && HAVE_PORT_CREATE |
124 | # define EV_USE_PORT 1 |
124 | # define EV_USE_PORT EV_FEATURE_BACKENDS |
125 | # else |
125 | # else |
126 | # define EV_USE_PORT 0 |
126 | # define EV_USE_PORT 0 |
127 | # endif |
127 | # endif |
128 | # endif |
128 | # endif |
129 | |
129 | |
130 | # ifndef EV_USE_INOTIFY |
130 | # ifndef EV_USE_INOTIFY |
131 | # if HAVE_INOTIFY_INIT && HAVE_SYS_INOTIFY_H |
131 | # if HAVE_INOTIFY_INIT && HAVE_SYS_INOTIFY_H |
132 | # define EV_USE_INOTIFY 1 |
132 | # define EV_USE_INOTIFY EV_FEATURE_OS |
133 | # else |
133 | # else |
134 | # define EV_USE_INOTIFY 0 |
134 | # define EV_USE_INOTIFY 0 |
135 | # endif |
135 | # endif |
136 | # endif |
136 | # endif |
137 | |
137 | |
138 | # ifndef EV_USE_SIGNALFD |
138 | # ifndef EV_USE_SIGNALFD |
139 | # if HAVE_SIGNALFD && HAVE_SYS_SIGNALFD_H |
139 | # if HAVE_SIGNALFD && HAVE_SYS_SIGNALFD_H |
140 | # define EV_USE_SIGNALFD 1 |
140 | # define EV_USE_SIGNALFD EV_FEATURE_OS |
141 | # else |
141 | # else |
142 | # define EV_USE_SIGNALFD 0 |
142 | # define EV_USE_SIGNALFD 0 |
143 | # endif |
143 | # endif |
144 | # endif |
144 | # endif |
145 | |
145 | |
146 | # ifndef EV_USE_EVENTFD |
146 | # ifndef EV_USE_EVENTFD |
147 | # if HAVE_EVENTFD |
147 | # if HAVE_EVENTFD |
148 | # define EV_USE_EVENTFD 1 |
148 | # define EV_USE_EVENTFD EV_FEATURE_OS |
149 | # else |
149 | # else |
150 | # define EV_USE_EVENTFD 0 |
150 | # define EV_USE_EVENTFD 0 |
151 | # endif |
151 | # endif |
152 | # endif |
152 | # endif |
153 | |
153 | |
… | |
… | |
219 | # define EV_NSIG 65 |
219 | # define EV_NSIG 65 |
220 | #endif |
220 | #endif |
221 | |
221 | |
222 | #ifndef EV_USE_CLOCK_SYSCALL |
222 | #ifndef EV_USE_CLOCK_SYSCALL |
223 | # if __linux && __GLIBC__ >= 2 |
223 | # if __linux && __GLIBC__ >= 2 |
224 | # define EV_USE_CLOCK_SYSCALL 1 |
224 | # define EV_USE_CLOCK_SYSCALL EV_FEATURE_OS |
225 | # else |
225 | # else |
226 | # define EV_USE_CLOCK_SYSCALL 0 |
226 | # define EV_USE_CLOCK_SYSCALL 0 |
227 | # endif |
227 | # endif |
228 | #endif |
228 | #endif |
229 | |
229 | |
230 | #ifndef EV_USE_MONOTONIC |
230 | #ifndef EV_USE_MONOTONIC |
231 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
231 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
232 | # define EV_USE_MONOTONIC 1 |
232 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
233 | # else |
233 | # else |
234 | # define EV_USE_MONOTONIC 0 |
234 | # define EV_USE_MONOTONIC 0 |
235 | # endif |
235 | # endif |
236 | #endif |
236 | #endif |
237 | |
237 | |
… | |
… | |
239 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
239 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
240 | #endif |
240 | #endif |
241 | |
241 | |
242 | #ifndef EV_USE_NANOSLEEP |
242 | #ifndef EV_USE_NANOSLEEP |
243 | # if _POSIX_C_SOURCE >= 199309L |
243 | # if _POSIX_C_SOURCE >= 199309L |
244 | # define EV_USE_NANOSLEEP 1 |
244 | # define EV_USE_NANOSLEEP EV_FEATURE_OS |
245 | # else |
245 | # else |
246 | # define EV_USE_NANOSLEEP 0 |
246 | # define EV_USE_NANOSLEEP 0 |
247 | # endif |
247 | # endif |
248 | #endif |
248 | #endif |
249 | |
249 | |
250 | #ifndef EV_USE_SELECT |
250 | #ifndef EV_USE_SELECT |
251 | # define EV_USE_SELECT 1 |
251 | # define EV_USE_SELECT EV_FEATURE_BACKENDS |
252 | #endif |
252 | #endif |
253 | |
253 | |
254 | #ifndef EV_USE_POLL |
254 | #ifndef EV_USE_POLL |
255 | # ifdef _WIN32 |
255 | # ifdef _WIN32 |
256 | # define EV_USE_POLL 0 |
256 | # define EV_USE_POLL 0 |
257 | # else |
257 | # else |
258 | # define EV_USE_POLL 1 |
258 | # define EV_USE_POLL EV_FEATURE_BACKENDS |
259 | # endif |
259 | # endif |
260 | #endif |
260 | #endif |
261 | |
261 | |
262 | #ifndef EV_USE_EPOLL |
262 | #ifndef EV_USE_EPOLL |
263 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
263 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
264 | # define EV_USE_EPOLL 1 |
264 | # define EV_USE_EPOLL EV_FEATURE_BACKENDS |
265 | # else |
265 | # else |
266 | # define EV_USE_EPOLL 0 |
266 | # define EV_USE_EPOLL 0 |
267 | # endif |
267 | # endif |
268 | #endif |
268 | #endif |
269 | |
269 | |
… | |
… | |
275 | # define EV_USE_PORT 0 |
275 | # define EV_USE_PORT 0 |
276 | #endif |
276 | #endif |
277 | |
277 | |
278 | #ifndef EV_USE_INOTIFY |
278 | #ifndef EV_USE_INOTIFY |
279 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
279 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
280 | # define EV_USE_INOTIFY 1 |
280 | # define EV_USE_INOTIFY EV_FEATURE_OS |
281 | # else |
281 | # else |
282 | # define EV_USE_INOTIFY 0 |
282 | # define EV_USE_INOTIFY 0 |
283 | # endif |
283 | # endif |
284 | #endif |
284 | #endif |
285 | |
285 | |
286 | #ifndef EV_PID_HASHSIZE |
286 | #ifndef EV_PID_HASHSIZE |
287 | # if EV_MINIMAL |
287 | # 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 |
288 | #endif |
293 | |
289 | |
294 | #ifndef EV_INOTIFY_HASHSIZE |
290 | #ifndef EV_INOTIFY_HASHSIZE |
295 | # if EV_MINIMAL |
291 | # 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 |
292 | #endif |
301 | |
293 | |
302 | #ifndef EV_USE_EVENTFD |
294 | #ifndef EV_USE_EVENTFD |
303 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
295 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
304 | # define EV_USE_EVENTFD 1 |
296 | # define EV_USE_EVENTFD EV_FEATURE_OS |
305 | # else |
297 | # else |
306 | # define EV_USE_EVENTFD 0 |
298 | # define EV_USE_EVENTFD 0 |
307 | # endif |
299 | # endif |
308 | #endif |
300 | #endif |
309 | |
301 | |
310 | #ifndef EV_USE_SIGNALFD |
302 | #ifndef EV_USE_SIGNALFD |
311 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
303 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
312 | # define EV_USE_SIGNALFD 1 |
304 | # define EV_USE_SIGNALFD EV_FEATURE_OS |
313 | # else |
305 | # else |
314 | # define EV_USE_SIGNALFD 0 |
306 | # define EV_USE_SIGNALFD 0 |
315 | # endif |
307 | # endif |
316 | #endif |
308 | #endif |
317 | |
309 | |
… | |
… | |
320 | # define EV_USE_4HEAP 1 |
312 | # define EV_USE_4HEAP 1 |
321 | # define EV_HEAP_CACHE_AT 1 |
313 | # define EV_HEAP_CACHE_AT 1 |
322 | #endif |
314 | #endif |
323 | |
315 | |
324 | #ifndef EV_VERIFY |
316 | #ifndef EV_VERIFY |
325 | # define EV_VERIFY !EV_MINIMAL |
317 | # define EV_VERIFY (EV_FEATURE_API ? 1 : 0) |
326 | #endif |
318 | #endif |
327 | |
319 | |
328 | #ifndef EV_USE_4HEAP |
320 | #ifndef EV_USE_4HEAP |
329 | # define EV_USE_4HEAP !EV_MINIMAL |
321 | # define EV_USE_4HEAP EV_FEATURE_DATA |
330 | #endif |
322 | #endif |
331 | |
323 | |
332 | #ifndef EV_HEAP_CACHE_AT |
324 | #ifndef EV_HEAP_CACHE_AT |
333 | # define EV_HEAP_CACHE_AT !EV_MINIMAL |
325 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
334 | #endif |
326 | #endif |
335 | |
327 | |
336 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
328 | /* 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. */ |
329 | /* which makes programs even slower. might work on other unices, too. */ |
338 | #if EV_USE_CLOCK_SYSCALL |
330 | #if EV_USE_CLOCK_SYSCALL |
… | |
… | |
443 | |
435 | |
444 | |
436 | |
445 | /**/ |
437 | /**/ |
446 | |
438 | |
447 | #if EV_VERIFY >= 3 |
439 | #if EV_VERIFY >= 3 |
448 | # define EV_FREQUENT_CHECK ev_loop_verify (EV_A) |
440 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
449 | #else |
441 | #else |
450 | # define EV_FREQUENT_CHECK do { } while (0) |
442 | # define EV_FREQUENT_CHECK do { } while (0) |
451 | #endif |
443 | #endif |
452 | |
444 | |
453 | /* |
445 | /* |
… | |
… | |
476 | |
468 | |
477 | #define expect_false(expr) expect ((expr) != 0, 0) |
469 | #define expect_false(expr) expect ((expr) != 0, 0) |
478 | #define expect_true(expr) expect ((expr) != 0, 1) |
470 | #define expect_true(expr) expect ((expr) != 0, 1) |
479 | #define inline_size static inline |
471 | #define inline_size static inline |
480 | |
472 | |
481 | #if EV_MINIMAL |
473 | #if EV_FEATURE_CODE |
|
|
474 | # define inline_speed static inline |
|
|
475 | #else |
482 | # define inline_speed static noinline |
476 | # define inline_speed static noinline |
483 | #else |
|
|
484 | # define inline_speed static inline |
|
|
485 | #endif |
477 | #endif |
486 | |
478 | |
487 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
479 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
488 | |
480 | |
489 | #if EV_MINPRI == EV_MAXPRI |
481 | #if EV_MINPRI == EV_MAXPRI |
… | |
… | |
696 | |
688 | |
697 | static int ev_default_loop_ptr; |
689 | static int ev_default_loop_ptr; |
698 | |
690 | |
699 | #endif |
691 | #endif |
700 | |
692 | |
701 | #if EV_MINIMAL < 2 |
693 | #if EV_FEATURE_API |
702 | # define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) |
694 | # 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) |
695 | # define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A) |
704 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
696 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
705 | #else |
697 | #else |
706 | # define EV_RELEASE_CB (void)0 |
698 | # define EV_RELEASE_CB (void)0 |
… | |
… | |
891 | } |
883 | } |
892 | |
884 | |
893 | /*****************************************************************************/ |
885 | /*****************************************************************************/ |
894 | |
886 | |
895 | inline_speed void |
887 | inline_speed void |
896 | fd_event_nc (EV_P_ int fd, int revents) |
888 | fd_event_nocheck (EV_P_ int fd, int revents) |
897 | { |
889 | { |
898 | ANFD *anfd = anfds + fd; |
890 | ANFD *anfd = anfds + fd; |
899 | ev_io *w; |
891 | ev_io *w; |
900 | |
892 | |
901 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
893 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
… | |
… | |
913 | fd_event (EV_P_ int fd, int revents) |
905 | fd_event (EV_P_ int fd, int revents) |
914 | { |
906 | { |
915 | ANFD *anfd = anfds + fd; |
907 | ANFD *anfd = anfds + fd; |
916 | |
908 | |
917 | if (expect_true (!anfd->reify)) |
909 | if (expect_true (!anfd->reify)) |
918 | fd_event_nc (EV_A_ fd, revents); |
910 | fd_event_nocheck (EV_A_ fd, revents); |
919 | } |
911 | } |
920 | |
912 | |
921 | void |
913 | void |
922 | ev_feed_fd_event (EV_P_ int fd, int revents) |
914 | ev_feed_fd_event (EV_P_ int fd, int revents) |
923 | { |
915 | { |
924 | if (fd >= 0 && fd < anfdmax) |
916 | if (fd >= 0 && fd < anfdmax) |
925 | fd_event_nc (EV_A_ fd, revents); |
917 | fd_event_nocheck (EV_A_ fd, revents); |
926 | } |
918 | } |
927 | |
919 | |
928 | /* make sure the external fd watch events are in-sync */ |
920 | /* make sure the external fd watch events are in-sync */ |
929 | /* with the kernel/libev internal state */ |
921 | /* with the kernel/libev internal state */ |
930 | inline_size void |
922 | inline_size void |
… | |
… | |
1403 | child_reap (EV_P_ int chain, int pid, int status) |
1395 | child_reap (EV_P_ int chain, int pid, int status) |
1404 | { |
1396 | { |
1405 | ev_child *w; |
1397 | ev_child *w; |
1406 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1398 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1407 | |
1399 | |
1408 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1400 | for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next) |
1409 | { |
1401 | { |
1410 | if ((w->pid == pid || !w->pid) |
1402 | if ((w->pid == pid || !w->pid) |
1411 | && (!traced || (w->flags & 1))) |
1403 | && (!traced || (w->flags & 1))) |
1412 | { |
1404 | { |
1413 | ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ |
1405 | 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 */ |
1430 | /* 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 */ |
1431 | /* 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); |
1432 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1441 | |
1433 | |
1442 | child_reap (EV_A_ pid, pid, status); |
1434 | child_reap (EV_A_ pid, pid, status); |
1443 | if (EV_PID_HASHSIZE > 1) |
1435 | if ((EV_PID_HASHSIZE) > 1) |
1444 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
1436 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
1445 | } |
1437 | } |
1446 | |
1438 | |
1447 | #endif |
1439 | #endif |
1448 | |
1440 | |
… | |
… | |
1537 | ev_backend (EV_P) |
1529 | ev_backend (EV_P) |
1538 | { |
1530 | { |
1539 | return backend; |
1531 | return backend; |
1540 | } |
1532 | } |
1541 | |
1533 | |
1542 | #if EV_MINIMAL < 2 |
1534 | #if EV_FEATURE_API |
1543 | unsigned int |
1535 | unsigned int |
1544 | ev_loop_count (EV_P) |
1536 | ev_iteration (EV_P) |
1545 | { |
1537 | { |
1546 | return loop_count; |
1538 | return loop_count; |
1547 | } |
1539 | } |
1548 | |
1540 | |
1549 | unsigned int |
1541 | unsigned int |
1550 | ev_loop_depth (EV_P) |
1542 | ev_depth (EV_P) |
1551 | { |
1543 | { |
1552 | return loop_depth; |
1544 | return loop_depth; |
1553 | } |
1545 | } |
1554 | |
1546 | |
1555 | void |
1547 | void |
… | |
… | |
1627 | |
1619 | |
1628 | ev_rt_now = ev_time (); |
1620 | ev_rt_now = ev_time (); |
1629 | mn_now = get_clock (); |
1621 | mn_now = get_clock (); |
1630 | now_floor = mn_now; |
1622 | now_floor = mn_now; |
1631 | rtmn_diff = ev_rt_now - mn_now; |
1623 | rtmn_diff = ev_rt_now - mn_now; |
1632 | #if EV_MINIMAL < 2 |
1624 | #if EV_FEATURE_API |
1633 | invoke_cb = ev_invoke_pending; |
1625 | invoke_cb = ev_invoke_pending; |
1634 | #endif |
1626 | #endif |
1635 | |
1627 | |
1636 | io_blocktime = 0.; |
1628 | io_blocktime = 0.; |
1637 | timeout_blocktime = 0.; |
1629 | timeout_blocktime = 0.; |
… | |
… | |
1798 | { |
1790 | { |
1799 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1791 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1800 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1792 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1801 | } |
1793 | } |
1802 | |
1794 | |
|
|
1795 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1803 | evpipe_init (EV_A); |
1796 | evpipe_init (EV_A); |
1804 | /* now iterate over everything, in case we missed something */ |
1797 | /* now iterate over everything, in case we missed something */ |
1805 | pipecb (EV_A_ &pipe_w, EV_READ); |
1798 | pipecb (EV_A_ &pipe_w, EV_READ); |
|
|
1799 | #endif |
1806 | } |
1800 | } |
1807 | |
1801 | |
1808 | postfork = 0; |
1802 | postfork = 0; |
1809 | } |
1803 | } |
1810 | |
1804 | |
… | |
… | |
1872 | verify_watcher (EV_A_ ws [cnt]); |
1866 | verify_watcher (EV_A_ ws [cnt]); |
1873 | } |
1867 | } |
1874 | } |
1868 | } |
1875 | #endif |
1869 | #endif |
1876 | |
1870 | |
1877 | #if EV_MINIMAL < 2 |
1871 | #if EV_FEATURE_API |
1878 | void |
1872 | void |
1879 | ev_loop_verify (EV_P) |
1873 | ev_verify (EV_P) |
1880 | { |
1874 | { |
1881 | #if EV_VERIFY |
1875 | #if EV_VERIFY |
1882 | int i; |
1876 | int i; |
1883 | WL w; |
1877 | WL w; |
1884 | |
1878 | |
… | |
… | |
1923 | #if EV_ASYNC_ENABLE |
1917 | #if EV_ASYNC_ENABLE |
1924 | assert (asyncmax >= asynccnt); |
1918 | assert (asyncmax >= asynccnt); |
1925 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1919 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1926 | #endif |
1920 | #endif |
1927 | |
1921 | |
|
|
1922 | #if EV_PREPARE_ENABLE |
1928 | assert (preparemax >= preparecnt); |
1923 | assert (preparemax >= preparecnt); |
1929 | array_verify (EV_A_ (W *)prepares, preparecnt); |
1924 | array_verify (EV_A_ (W *)prepares, preparecnt); |
|
|
1925 | #endif |
1930 | |
1926 | |
|
|
1927 | #if EV_CHECK_ENABLE |
1931 | assert (checkmax >= checkcnt); |
1928 | assert (checkmax >= checkcnt); |
1932 | array_verify (EV_A_ (W *)checks, checkcnt); |
1929 | array_verify (EV_A_ (W *)checks, checkcnt); |
|
|
1930 | #endif |
1933 | |
1931 | |
1934 | # if 0 |
1932 | # if 0 |
1935 | #if EV_CHILD_ENABLE |
1933 | #if EV_CHILD_ENABLE |
1936 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1934 | 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) |
1935 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
1938 | #endif |
1936 | #endif |
1939 | # endif |
1937 | # endif |
1940 | #endif |
1938 | #endif |
1941 | } |
1939 | } |
… | |
… | |
2269 | } |
2267 | } |
2270 | |
2268 | |
2271 | void |
2269 | void |
2272 | ev_loop (EV_P_ int flags) |
2270 | ev_loop (EV_P_ int flags) |
2273 | { |
2271 | { |
2274 | #if EV_MINIMAL < 2 |
2272 | #if EV_FEATURE_API |
2275 | ++loop_depth; |
2273 | ++loop_depth; |
2276 | #endif |
2274 | #endif |
2277 | |
2275 | |
2278 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2276 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2279 | |
2277 | |
… | |
… | |
2282 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2280 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2283 | |
2281 | |
2284 | do |
2282 | do |
2285 | { |
2283 | { |
2286 | #if EV_VERIFY >= 2 |
2284 | #if EV_VERIFY >= 2 |
2287 | ev_loop_verify (EV_A); |
2285 | ev_verify (EV_A); |
2288 | #endif |
2286 | #endif |
2289 | |
2287 | |
2290 | #ifndef _WIN32 |
2288 | #ifndef _WIN32 |
2291 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2289 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2292 | if (expect_false (getpid () != curpid)) |
2290 | if (expect_false (getpid () != curpid)) |
… | |
… | |
2304 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2302 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2305 | EV_INVOKE_PENDING; |
2303 | EV_INVOKE_PENDING; |
2306 | } |
2304 | } |
2307 | #endif |
2305 | #endif |
2308 | |
2306 | |
|
|
2307 | #if EV_PREPARE_ENABLE |
2309 | /* queue prepare watchers (and execute them) */ |
2308 | /* queue prepare watchers (and execute them) */ |
2310 | if (expect_false (preparecnt)) |
2309 | if (expect_false (preparecnt)) |
2311 | { |
2310 | { |
2312 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2311 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2313 | EV_INVOKE_PENDING; |
2312 | EV_INVOKE_PENDING; |
2314 | } |
2313 | } |
|
|
2314 | #endif |
2315 | |
2315 | |
2316 | if (expect_false (loop_done)) |
2316 | if (expect_false (loop_done)) |
2317 | break; |
2317 | break; |
2318 | |
2318 | |
2319 | /* we might have forked, so reify kernel state if necessary */ |
2319 | /* we might have forked, so reify kernel state if necessary */ |
… | |
… | |
2370 | waittime -= sleeptime; |
2370 | waittime -= sleeptime; |
2371 | } |
2371 | } |
2372 | } |
2372 | } |
2373 | } |
2373 | } |
2374 | |
2374 | |
2375 | #if EV_MINIMAL < 2 |
2375 | #if EV_FEATURE_API |
2376 | ++loop_count; |
2376 | ++loop_count; |
2377 | #endif |
2377 | #endif |
2378 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2378 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2379 | backend_poll (EV_A_ waittime); |
2379 | backend_poll (EV_A_ waittime); |
2380 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
2380 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
… | |
… | |
2392 | #if EV_IDLE_ENABLE |
2392 | #if EV_IDLE_ENABLE |
2393 | /* queue idle watchers unless other events are pending */ |
2393 | /* queue idle watchers unless other events are pending */ |
2394 | idle_reify (EV_A); |
2394 | idle_reify (EV_A); |
2395 | #endif |
2395 | #endif |
2396 | |
2396 | |
|
|
2397 | #if EV_CHECK_ENABLE |
2397 | /* queue check watchers, to be executed first */ |
2398 | /* queue check watchers, to be executed first */ |
2398 | if (expect_false (checkcnt)) |
2399 | if (expect_false (checkcnt)) |
2399 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
2400 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
|
|
2401 | #endif |
2400 | |
2402 | |
2401 | EV_INVOKE_PENDING; |
2403 | EV_INVOKE_PENDING; |
2402 | } |
2404 | } |
2403 | while (expect_true ( |
2405 | while (expect_true ( |
2404 | activecnt |
2406 | activecnt |
… | |
… | |
2407 | )); |
2409 | )); |
2408 | |
2410 | |
2409 | if (loop_done == EVUNLOOP_ONE) |
2411 | if (loop_done == EVUNLOOP_ONE) |
2410 | loop_done = EVUNLOOP_CANCEL; |
2412 | loop_done = EVUNLOOP_CANCEL; |
2411 | |
2413 | |
2412 | #if EV_MINIMAL < 2 |
2414 | #if EV_FEATURE_API |
2413 | --loop_depth; |
2415 | --loop_depth; |
2414 | #endif |
2416 | #endif |
2415 | } |
2417 | } |
2416 | |
2418 | |
2417 | void |
2419 | void |
… | |
… | |
2867 | return; |
2869 | return; |
2868 | |
2870 | |
2869 | EV_FREQUENT_CHECK; |
2871 | EV_FREQUENT_CHECK; |
2870 | |
2872 | |
2871 | ev_start (EV_A_ (W)w, 1); |
2873 | ev_start (EV_A_ (W)w, 1); |
2872 | wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2874 | wlist_add (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2873 | |
2875 | |
2874 | EV_FREQUENT_CHECK; |
2876 | EV_FREQUENT_CHECK; |
2875 | } |
2877 | } |
2876 | |
2878 | |
2877 | void |
2879 | void |
… | |
… | |
2881 | if (expect_false (!ev_is_active (w))) |
2883 | if (expect_false (!ev_is_active (w))) |
2882 | return; |
2884 | return; |
2883 | |
2885 | |
2884 | EV_FREQUENT_CHECK; |
2886 | EV_FREQUENT_CHECK; |
2885 | |
2887 | |
2886 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2888 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2887 | ev_stop (EV_A_ (W)w); |
2889 | ev_stop (EV_A_ (W)w); |
2888 | |
2890 | |
2889 | EV_FREQUENT_CHECK; |
2891 | EV_FREQUENT_CHECK; |
2890 | } |
2892 | } |
2891 | |
2893 | |
… | |
… | |
2964 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2966 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2965 | } |
2967 | } |
2966 | } |
2968 | } |
2967 | |
2969 | |
2968 | if (w->wd >= 0) |
2970 | if (w->wd >= 0) |
2969 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2971 | wlist_add (&fs_hash [w->wd & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
2970 | |
2972 | |
2971 | /* now re-arm timer, if required */ |
2973 | /* now re-arm timer, if required */ |
2972 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2974 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2973 | ev_timer_again (EV_A_ &w->timer); |
2975 | ev_timer_again (EV_A_ &w->timer); |
2974 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
2976 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
… | |
… | |
2982 | |
2984 | |
2983 | if (wd < 0) |
2985 | if (wd < 0) |
2984 | return; |
2986 | return; |
2985 | |
2987 | |
2986 | w->wd = -2; |
2988 | w->wd = -2; |
2987 | slot = wd & (EV_INOTIFY_HASHSIZE - 1); |
2989 | slot = wd & ((EV_INOTIFY_HASHSIZE) - 1); |
2988 | wlist_del (&fs_hash [slot].head, (WL)w); |
2990 | wlist_del (&fs_hash [slot].head, (WL)w); |
2989 | |
2991 | |
2990 | /* remove this watcher, if others are watching it, they will rearm */ |
2992 | /* remove this watcher, if others are watching it, they will rearm */ |
2991 | inotify_rm_watch (fs_fd, wd); |
2993 | inotify_rm_watch (fs_fd, wd); |
2992 | } |
2994 | } |
… | |
… | |
2994 | static void noinline |
2996 | static void noinline |
2995 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
2997 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
2996 | { |
2998 | { |
2997 | if (slot < 0) |
2999 | if (slot < 0) |
2998 | /* overflow, need to check for all hash slots */ |
3000 | /* overflow, need to check for all hash slots */ |
2999 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3001 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
3000 | infy_wd (EV_A_ slot, wd, ev); |
3002 | infy_wd (EV_A_ slot, wd, ev); |
3001 | else |
3003 | else |
3002 | { |
3004 | { |
3003 | WL w_; |
3005 | WL w_; |
3004 | |
3006 | |
3005 | for (w_ = fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head; w_; ) |
3007 | for (w_ = fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head; w_; ) |
3006 | { |
3008 | { |
3007 | ev_stat *w = (ev_stat *)w_; |
3009 | ev_stat *w = (ev_stat *)w_; |
3008 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
3010 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
3009 | |
3011 | |
3010 | if (w->wd == wd || wd == -1) |
3012 | if (w->wd == wd || wd == -1) |
3011 | { |
3013 | { |
3012 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
3014 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
3013 | { |
3015 | { |
3014 | wlist_del (&fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
3016 | wlist_del (&fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
3015 | w->wd = -1; |
3017 | w->wd = -1; |
3016 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3018 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3017 | } |
3019 | } |
3018 | |
3020 | |
3019 | stat_timer_cb (EV_A_ &w->timer, 0); |
3021 | stat_timer_cb (EV_A_ &w->timer, 0); |
… | |
… | |
3133 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3135 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3134 | ev_io_start (EV_A_ &fs_w); |
3136 | ev_io_start (EV_A_ &fs_w); |
3135 | ev_unref (EV_A); |
3137 | ev_unref (EV_A); |
3136 | } |
3138 | } |
3137 | |
3139 | |
3138 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3140 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
3139 | { |
3141 | { |
3140 | WL w_ = fs_hash [slot].head; |
3142 | WL w_ = fs_hash [slot].head; |
3141 | fs_hash [slot].head = 0; |
3143 | fs_hash [slot].head = 0; |
3142 | |
3144 | |
3143 | while (w_) |
3145 | while (w_) |
… | |
… | |
3318 | |
3320 | |
3319 | EV_FREQUENT_CHECK; |
3321 | EV_FREQUENT_CHECK; |
3320 | } |
3322 | } |
3321 | #endif |
3323 | #endif |
3322 | |
3324 | |
|
|
3325 | #if EV_PREPARE_ENABLE |
3323 | void |
3326 | void |
3324 | ev_prepare_start (EV_P_ ev_prepare *w) |
3327 | ev_prepare_start (EV_P_ ev_prepare *w) |
3325 | { |
3328 | { |
3326 | if (expect_false (ev_is_active (w))) |
3329 | if (expect_false (ev_is_active (w))) |
3327 | return; |
3330 | return; |
… | |
… | |
3353 | |
3356 | |
3354 | ev_stop (EV_A_ (W)w); |
3357 | ev_stop (EV_A_ (W)w); |
3355 | |
3358 | |
3356 | EV_FREQUENT_CHECK; |
3359 | EV_FREQUENT_CHECK; |
3357 | } |
3360 | } |
|
|
3361 | #endif |
3358 | |
3362 | |
|
|
3363 | #if EV_CHECK_ENABLE |
3359 | void |
3364 | void |
3360 | ev_check_start (EV_P_ ev_check *w) |
3365 | ev_check_start (EV_P_ ev_check *w) |
3361 | { |
3366 | { |
3362 | if (expect_false (ev_is_active (w))) |
3367 | if (expect_false (ev_is_active (w))) |
3363 | return; |
3368 | return; |
… | |
… | |
3389 | |
3394 | |
3390 | ev_stop (EV_A_ (W)w); |
3395 | ev_stop (EV_A_ (W)w); |
3391 | |
3396 | |
3392 | EV_FREQUENT_CHECK; |
3397 | EV_FREQUENT_CHECK; |
3393 | } |
3398 | } |
|
|
3399 | #endif |
3394 | |
3400 | |
3395 | #if EV_EMBED_ENABLE |
3401 | #if EV_EMBED_ENABLE |
3396 | void noinline |
3402 | void noinline |
3397 | ev_embed_sweep (EV_P_ ev_embed *w) |
3403 | ev_embed_sweep (EV_P_ ev_embed *w) |
3398 | { |
3404 | { |
… | |
… | |
3727 | if (types & EV_ASYNC) |
3733 | if (types & EV_ASYNC) |
3728 | for (i = asynccnt; i--; ) |
3734 | for (i = asynccnt; i--; ) |
3729 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3735 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3730 | #endif |
3736 | #endif |
3731 | |
3737 | |
|
|
3738 | #if EV_PREPARE_ENABLE |
3732 | if (types & EV_PREPARE) |
3739 | if (types & EV_PREPARE) |
3733 | for (i = preparecnt; i--; ) |
3740 | for (i = preparecnt; i--; ) |
3734 | #if EV_EMBED_ENABLE |
3741 | # if EV_EMBED_ENABLE |
3735 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3742 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3736 | #endif |
3743 | # endif |
3737 | cb (EV_A_ EV_PREPARE, prepares [i]); |
3744 | cb (EV_A_ EV_PREPARE, prepares [i]); |
|
|
3745 | #endif |
3738 | |
3746 | |
|
|
3747 | #if EV_CHECK_ENABLE |
3739 | if (types & EV_CHECK) |
3748 | if (types & EV_CHECK) |
3740 | for (i = checkcnt; i--; ) |
3749 | for (i = checkcnt; i--; ) |
3741 | cb (EV_A_ EV_CHECK, checks [i]); |
3750 | cb (EV_A_ EV_CHECK, checks [i]); |
|
|
3751 | #endif |
3742 | |
3752 | |
|
|
3753 | #if EV_SIGNAL_ENABLE |
3743 | if (types & EV_SIGNAL) |
3754 | if (types & EV_SIGNAL) |
3744 | for (i = 0; i < EV_NSIG - 1; ++i) |
3755 | for (i = 0; i < EV_NSIG - 1; ++i) |
3745 | for (wl = signals [i].head; wl; ) |
3756 | for (wl = signals [i].head; wl; ) |
3746 | { |
3757 | { |
3747 | wn = wl->next; |
3758 | wn = wl->next; |
3748 | cb (EV_A_ EV_SIGNAL, wl); |
3759 | cb (EV_A_ EV_SIGNAL, wl); |
3749 | wl = wn; |
3760 | wl = wn; |
3750 | } |
3761 | } |
|
|
3762 | #endif |
3751 | |
3763 | |
|
|
3764 | #if EV_CHILD_ENABLE |
3752 | if (types & EV_CHILD) |
3765 | if (types & EV_CHILD) |
3753 | for (i = EV_PID_HASHSIZE; i--; ) |
3766 | for (i = (EV_PID_HASHSIZE); i--; ) |
3754 | for (wl = childs [i]; wl; ) |
3767 | for (wl = childs [i]; wl; ) |
3755 | { |
3768 | { |
3756 | wn = wl->next; |
3769 | wn = wl->next; |
3757 | cb (EV_A_ EV_CHILD, wl); |
3770 | cb (EV_A_ EV_CHILD, wl); |
3758 | wl = wn; |
3771 | wl = wn; |
3759 | } |
3772 | } |
|
|
3773 | #endif |
3760 | /* EV_STAT 0x00001000 /* stat data changed */ |
3774 | /* EV_STAT 0x00001000 /* stat data changed */ |
3761 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3775 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3762 | } |
3776 | } |
3763 | #endif |
3777 | #endif |
3764 | |
3778 | |