… | |
… | |
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 |
… | |
… | |
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 | |
… | |
… | |
1515 | #ifdef __APPLE__ |
1507 | #ifdef __APPLE__ |
1516 | /* only select works correctly on that "unix-certified" platform */ |
1508 | /* only select works correctly on that "unix-certified" platform */ |
1517 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1509 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1518 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
1510 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
1519 | #endif |
1511 | #endif |
|
|
1512 | #ifdef __FreeBSD__ |
|
|
1513 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
|
|
1514 | #endif |
1520 | |
1515 | |
1521 | return flags; |
1516 | return flags; |
1522 | } |
1517 | } |
1523 | |
1518 | |
1524 | unsigned int |
1519 | unsigned int |
… | |
… | |
1537 | ev_backend (EV_P) |
1532 | ev_backend (EV_P) |
1538 | { |
1533 | { |
1539 | return backend; |
1534 | return backend; |
1540 | } |
1535 | } |
1541 | |
1536 | |
1542 | #if EV_MINIMAL < 2 |
1537 | #if EV_FEATURE_API |
1543 | unsigned int |
1538 | unsigned int |
1544 | ev_loop_count (EV_P) |
1539 | ev_iteration (EV_P) |
1545 | { |
1540 | { |
1546 | return loop_count; |
1541 | return loop_count; |
1547 | } |
1542 | } |
1548 | |
1543 | |
1549 | unsigned int |
1544 | unsigned int |
1550 | ev_loop_depth (EV_P) |
1545 | ev_depth (EV_P) |
1551 | { |
1546 | { |
1552 | return loop_depth; |
1547 | return loop_depth; |
1553 | } |
1548 | } |
1554 | |
1549 | |
1555 | void |
1550 | void |
… | |
… | |
1627 | |
1622 | |
1628 | ev_rt_now = ev_time (); |
1623 | ev_rt_now = ev_time (); |
1629 | mn_now = get_clock (); |
1624 | mn_now = get_clock (); |
1630 | now_floor = mn_now; |
1625 | now_floor = mn_now; |
1631 | rtmn_diff = ev_rt_now - mn_now; |
1626 | rtmn_diff = ev_rt_now - mn_now; |
1632 | #if EV_MINIMAL < 2 |
1627 | #if EV_FEATURE_API |
1633 | invoke_cb = ev_invoke_pending; |
1628 | invoke_cb = ev_invoke_pending; |
1634 | #endif |
1629 | #endif |
1635 | |
1630 | |
1636 | io_blocktime = 0.; |
1631 | io_blocktime = 0.; |
1637 | timeout_blocktime = 0.; |
1632 | timeout_blocktime = 0.; |
… | |
… | |
1874 | verify_watcher (EV_A_ ws [cnt]); |
1869 | verify_watcher (EV_A_ ws [cnt]); |
1875 | } |
1870 | } |
1876 | } |
1871 | } |
1877 | #endif |
1872 | #endif |
1878 | |
1873 | |
1879 | #if EV_MINIMAL < 2 |
1874 | #if EV_FEATURE_API |
1880 | void |
1875 | void |
1881 | ev_loop_verify (EV_P) |
1876 | ev_verify (EV_P) |
1882 | { |
1877 | { |
1883 | #if EV_VERIFY |
1878 | #if EV_VERIFY |
1884 | int i; |
1879 | int i; |
1885 | WL w; |
1880 | WL w; |
1886 | |
1881 | |
… | |
… | |
1937 | array_verify (EV_A_ (W *)checks, checkcnt); |
1932 | array_verify (EV_A_ (W *)checks, checkcnt); |
1938 | #endif |
1933 | #endif |
1939 | |
1934 | |
1940 | # if 0 |
1935 | # if 0 |
1941 | #if EV_CHILD_ENABLE |
1936 | #if EV_CHILD_ENABLE |
1942 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1937 | for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next) |
1943 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
1938 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
1944 | #endif |
1939 | #endif |
1945 | # endif |
1940 | # endif |
1946 | #endif |
1941 | #endif |
1947 | } |
1942 | } |
… | |
… | |
2104 | EV_FREQUENT_CHECK; |
2099 | EV_FREQUENT_CHECK; |
2105 | feed_reverse (EV_A_ (W)w); |
2100 | feed_reverse (EV_A_ (W)w); |
2106 | } |
2101 | } |
2107 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2102 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2108 | |
2103 | |
2109 | feed_reverse_done (EV_A_ EV_TIMEOUT); |
2104 | feed_reverse_done (EV_A_ EV_TIMER); |
2110 | } |
2105 | } |
2111 | } |
2106 | } |
2112 | |
2107 | |
2113 | #if EV_PERIODIC_ENABLE |
2108 | #if EV_PERIODIC_ENABLE |
2114 | /* make periodics pending */ |
2109 | /* make periodics pending */ |
… | |
… | |
2275 | } |
2270 | } |
2276 | |
2271 | |
2277 | void |
2272 | void |
2278 | ev_loop (EV_P_ int flags) |
2273 | ev_loop (EV_P_ int flags) |
2279 | { |
2274 | { |
2280 | #if EV_MINIMAL < 2 |
2275 | #if EV_FEATURE_API |
2281 | ++loop_depth; |
2276 | ++loop_depth; |
2282 | #endif |
2277 | #endif |
2283 | |
2278 | |
2284 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2279 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2285 | |
2280 | |
… | |
… | |
2288 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2283 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2289 | |
2284 | |
2290 | do |
2285 | do |
2291 | { |
2286 | { |
2292 | #if EV_VERIFY >= 2 |
2287 | #if EV_VERIFY >= 2 |
2293 | ev_loop_verify (EV_A); |
2288 | ev_verify (EV_A); |
2294 | #endif |
2289 | #endif |
2295 | |
2290 | |
2296 | #ifndef _WIN32 |
2291 | #ifndef _WIN32 |
2297 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2292 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2298 | if (expect_false (getpid () != curpid)) |
2293 | if (expect_false (getpid () != curpid)) |
… | |
… | |
2378 | waittime -= sleeptime; |
2373 | waittime -= sleeptime; |
2379 | } |
2374 | } |
2380 | } |
2375 | } |
2381 | } |
2376 | } |
2382 | |
2377 | |
2383 | #if EV_MINIMAL < 2 |
2378 | #if EV_FEATURE_API |
2384 | ++loop_count; |
2379 | ++loop_count; |
2385 | #endif |
2380 | #endif |
2386 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2381 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2387 | backend_poll (EV_A_ waittime); |
2382 | backend_poll (EV_A_ waittime); |
2388 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
2383 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
… | |
… | |
2417 | )); |
2412 | )); |
2418 | |
2413 | |
2419 | if (loop_done == EVUNLOOP_ONE) |
2414 | if (loop_done == EVUNLOOP_ONE) |
2420 | loop_done = EVUNLOOP_CANCEL; |
2415 | loop_done = EVUNLOOP_CANCEL; |
2421 | |
2416 | |
2422 | #if EV_MINIMAL < 2 |
2417 | #if EV_FEATURE_API |
2423 | --loop_depth; |
2418 | --loop_depth; |
2424 | #endif |
2419 | #endif |
2425 | } |
2420 | } |
2426 | |
2421 | |
2427 | void |
2422 | void |
… | |
… | |
2877 | return; |
2872 | return; |
2878 | |
2873 | |
2879 | EV_FREQUENT_CHECK; |
2874 | EV_FREQUENT_CHECK; |
2880 | |
2875 | |
2881 | ev_start (EV_A_ (W)w, 1); |
2876 | ev_start (EV_A_ (W)w, 1); |
2882 | wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2877 | wlist_add (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2883 | |
2878 | |
2884 | EV_FREQUENT_CHECK; |
2879 | EV_FREQUENT_CHECK; |
2885 | } |
2880 | } |
2886 | |
2881 | |
2887 | void |
2882 | void |
… | |
… | |
2891 | if (expect_false (!ev_is_active (w))) |
2886 | if (expect_false (!ev_is_active (w))) |
2892 | return; |
2887 | return; |
2893 | |
2888 | |
2894 | EV_FREQUENT_CHECK; |
2889 | EV_FREQUENT_CHECK; |
2895 | |
2890 | |
2896 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2891 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2897 | ev_stop (EV_A_ (W)w); |
2892 | ev_stop (EV_A_ (W)w); |
2898 | |
2893 | |
2899 | EV_FREQUENT_CHECK; |
2894 | EV_FREQUENT_CHECK; |
2900 | } |
2895 | } |
2901 | |
2896 | |
… | |
… | |
2974 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2969 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2975 | } |
2970 | } |
2976 | } |
2971 | } |
2977 | |
2972 | |
2978 | if (w->wd >= 0) |
2973 | if (w->wd >= 0) |
2979 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2974 | wlist_add (&fs_hash [w->wd & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
2980 | |
2975 | |
2981 | /* now re-arm timer, if required */ |
2976 | /* now re-arm timer, if required */ |
2982 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2977 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2983 | ev_timer_again (EV_A_ &w->timer); |
2978 | ev_timer_again (EV_A_ &w->timer); |
2984 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
2979 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
… | |
… | |
2992 | |
2987 | |
2993 | if (wd < 0) |
2988 | if (wd < 0) |
2994 | return; |
2989 | return; |
2995 | |
2990 | |
2996 | w->wd = -2; |
2991 | w->wd = -2; |
2997 | slot = wd & (EV_INOTIFY_HASHSIZE - 1); |
2992 | slot = wd & ((EV_INOTIFY_HASHSIZE) - 1); |
2998 | wlist_del (&fs_hash [slot].head, (WL)w); |
2993 | wlist_del (&fs_hash [slot].head, (WL)w); |
2999 | |
2994 | |
3000 | /* remove this watcher, if others are watching it, they will rearm */ |
2995 | /* remove this watcher, if others are watching it, they will rearm */ |
3001 | inotify_rm_watch (fs_fd, wd); |
2996 | inotify_rm_watch (fs_fd, wd); |
3002 | } |
2997 | } |
… | |
… | |
3004 | static void noinline |
2999 | static void noinline |
3005 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
3000 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
3006 | { |
3001 | { |
3007 | if (slot < 0) |
3002 | if (slot < 0) |
3008 | /* overflow, need to check for all hash slots */ |
3003 | /* overflow, need to check for all hash slots */ |
3009 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3004 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
3010 | infy_wd (EV_A_ slot, wd, ev); |
3005 | infy_wd (EV_A_ slot, wd, ev); |
3011 | else |
3006 | else |
3012 | { |
3007 | { |
3013 | WL w_; |
3008 | WL w_; |
3014 | |
3009 | |
3015 | for (w_ = fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head; w_; ) |
3010 | for (w_ = fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head; w_; ) |
3016 | { |
3011 | { |
3017 | ev_stat *w = (ev_stat *)w_; |
3012 | ev_stat *w = (ev_stat *)w_; |
3018 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
3013 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
3019 | |
3014 | |
3020 | if (w->wd == wd || wd == -1) |
3015 | if (w->wd == wd || wd == -1) |
3021 | { |
3016 | { |
3022 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
3017 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
3023 | { |
3018 | { |
3024 | wlist_del (&fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
3019 | wlist_del (&fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
3025 | w->wd = -1; |
3020 | w->wd = -1; |
3026 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3021 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3027 | } |
3022 | } |
3028 | |
3023 | |
3029 | stat_timer_cb (EV_A_ &w->timer, 0); |
3024 | stat_timer_cb (EV_A_ &w->timer, 0); |
… | |
… | |
3143 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3138 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3144 | ev_io_start (EV_A_ &fs_w); |
3139 | ev_io_start (EV_A_ &fs_w); |
3145 | ev_unref (EV_A); |
3140 | ev_unref (EV_A); |
3146 | } |
3141 | } |
3147 | |
3142 | |
3148 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3143 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
3149 | { |
3144 | { |
3150 | WL w_ = fs_hash [slot].head; |
3145 | WL w_ = fs_hash [slot].head; |
3151 | fs_hash [slot].head = 0; |
3146 | fs_hash [slot].head = 0; |
3152 | |
3147 | |
3153 | while (w_) |
3148 | while (w_) |
… | |
… | |
3644 | { |
3639 | { |
3645 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3640 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3646 | |
3641 | |
3647 | if (expect_false (!once)) |
3642 | if (expect_false (!once)) |
3648 | { |
3643 | { |
3649 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
3644 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
3650 | return; |
3645 | return; |
3651 | } |
3646 | } |
3652 | |
3647 | |
3653 | once->cb = cb; |
3648 | once->cb = cb; |
3654 | once->arg = arg; |
3649 | once->arg = arg; |
… | |
… | |
3769 | } |
3764 | } |
3770 | #endif |
3765 | #endif |
3771 | |
3766 | |
3772 | #if EV_CHILD_ENABLE |
3767 | #if EV_CHILD_ENABLE |
3773 | if (types & EV_CHILD) |
3768 | if (types & EV_CHILD) |
3774 | for (i = EV_PID_HASHSIZE; i--; ) |
3769 | for (i = (EV_PID_HASHSIZE); i--; ) |
3775 | for (wl = childs [i]; wl; ) |
3770 | for (wl = childs [i]; wl; ) |
3776 | { |
3771 | { |
3777 | wn = wl->next; |
3772 | wn = wl->next; |
3778 | cb (EV_A_ EV_CHILD, wl); |
3773 | cb (EV_A_ EV_CHILD, wl); |
3779 | wl = wn; |
3774 | wl = wn; |