… | |
… | |
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 | |
… | |
… | |
207 | #elif defined (MAXSIG) |
207 | #elif defined (MAXSIG) |
208 | # define EV_NSIG (MAXSIG+1) |
208 | # define EV_NSIG (MAXSIG+1) |
209 | #elif defined (MAX_SIG) |
209 | #elif defined (MAX_SIG) |
210 | # define EV_NSIG (MAX_SIG+1) |
210 | # define EV_NSIG (MAX_SIG+1) |
211 | #elif defined (SIGARRAYSIZE) |
211 | #elif defined (SIGARRAYSIZE) |
212 | # define EV_NSIG SIGARRAYSIZE /* Assume ary[SIGARRAYSIZE] */ |
212 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
213 | #elif defined (_sys_nsig) |
213 | #elif defined (_sys_nsig) |
214 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
214 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
215 | #else |
215 | #else |
216 | # error "unable to find value for NSIG, please report" |
216 | # error "unable to find value for NSIG, please report" |
217 | /* to make it compile regardless, just remove the above line */ |
217 | /* to make it compile regardless, just remove the above line, */ |
|
|
218 | /* but consider reporting it, too! :) */ |
218 | # define EV_NSIG 65 |
219 | # define EV_NSIG 65 |
219 | #endif |
220 | #endif |
220 | |
221 | |
221 | #ifndef EV_USE_CLOCK_SYSCALL |
222 | #ifndef EV_USE_CLOCK_SYSCALL |
222 | # if __linux && __GLIBC__ >= 2 |
223 | # if __linux && __GLIBC__ >= 2 |
223 | # define EV_USE_CLOCK_SYSCALL 1 |
224 | # define EV_USE_CLOCK_SYSCALL EV_FEATURE_OS |
224 | # else |
225 | # else |
225 | # define EV_USE_CLOCK_SYSCALL 0 |
226 | # define EV_USE_CLOCK_SYSCALL 0 |
226 | # endif |
227 | # endif |
227 | #endif |
228 | #endif |
228 | |
229 | |
229 | #ifndef EV_USE_MONOTONIC |
230 | #ifndef EV_USE_MONOTONIC |
230 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
231 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
231 | # define EV_USE_MONOTONIC 1 |
232 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
232 | # else |
233 | # else |
233 | # define EV_USE_MONOTONIC 0 |
234 | # define EV_USE_MONOTONIC 0 |
234 | # endif |
235 | # endif |
235 | #endif |
236 | #endif |
236 | |
237 | |
… | |
… | |
238 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
239 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
239 | #endif |
240 | #endif |
240 | |
241 | |
241 | #ifndef EV_USE_NANOSLEEP |
242 | #ifndef EV_USE_NANOSLEEP |
242 | # if _POSIX_C_SOURCE >= 199309L |
243 | # if _POSIX_C_SOURCE >= 199309L |
243 | # define EV_USE_NANOSLEEP 1 |
244 | # define EV_USE_NANOSLEEP EV_FEATURE_OS |
244 | # else |
245 | # else |
245 | # define EV_USE_NANOSLEEP 0 |
246 | # define EV_USE_NANOSLEEP 0 |
246 | # endif |
247 | # endif |
247 | #endif |
248 | #endif |
248 | |
249 | |
249 | #ifndef EV_USE_SELECT |
250 | #ifndef EV_USE_SELECT |
250 | # define EV_USE_SELECT 1 |
251 | # define EV_USE_SELECT EV_FEATURE_BACKENDS |
251 | #endif |
252 | #endif |
252 | |
253 | |
253 | #ifndef EV_USE_POLL |
254 | #ifndef EV_USE_POLL |
254 | # ifdef _WIN32 |
255 | # ifdef _WIN32 |
255 | # define EV_USE_POLL 0 |
256 | # define EV_USE_POLL 0 |
256 | # else |
257 | # else |
257 | # define EV_USE_POLL 1 |
258 | # define EV_USE_POLL EV_FEATURE_BACKENDS |
258 | # endif |
259 | # endif |
259 | #endif |
260 | #endif |
260 | |
261 | |
261 | #ifndef EV_USE_EPOLL |
262 | #ifndef EV_USE_EPOLL |
262 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
263 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
263 | # define EV_USE_EPOLL 1 |
264 | # define EV_USE_EPOLL EV_FEATURE_BACKENDS |
264 | # else |
265 | # else |
265 | # define EV_USE_EPOLL 0 |
266 | # define EV_USE_EPOLL 0 |
266 | # endif |
267 | # endif |
267 | #endif |
268 | #endif |
268 | |
269 | |
… | |
… | |
274 | # define EV_USE_PORT 0 |
275 | # define EV_USE_PORT 0 |
275 | #endif |
276 | #endif |
276 | |
277 | |
277 | #ifndef EV_USE_INOTIFY |
278 | #ifndef EV_USE_INOTIFY |
278 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
279 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
279 | # define EV_USE_INOTIFY 1 |
280 | # define EV_USE_INOTIFY EV_FEATURE_OS |
280 | # else |
281 | # else |
281 | # define EV_USE_INOTIFY 0 |
282 | # define EV_USE_INOTIFY 0 |
282 | # endif |
283 | # endif |
283 | #endif |
284 | #endif |
284 | |
285 | |
285 | #ifndef EV_PID_HASHSIZE |
286 | #ifndef EV_PID_HASHSIZE |
286 | # if EV_MINIMAL |
287 | # define EV_PID_HASHSIZE EV_FEATURE_DATA ? 16 : 1 |
287 | # define EV_PID_HASHSIZE 1 |
|
|
288 | # else |
|
|
289 | # define EV_PID_HASHSIZE 16 |
|
|
290 | # endif |
|
|
291 | #endif |
288 | #endif |
292 | |
289 | |
293 | #ifndef EV_INOTIFY_HASHSIZE |
290 | #ifndef EV_INOTIFY_HASHSIZE |
294 | # if EV_MINIMAL |
291 | # define EV_INOTIFY_HASHSIZE EV_FEATURE_DATA ? 16 : 1 |
295 | # define EV_INOTIFY_HASHSIZE 1 |
|
|
296 | # else |
|
|
297 | # define EV_INOTIFY_HASHSIZE 16 |
|
|
298 | # endif |
|
|
299 | #endif |
292 | #endif |
300 | |
293 | |
301 | #ifndef EV_USE_EVENTFD |
294 | #ifndef EV_USE_EVENTFD |
302 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
295 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
303 | # define EV_USE_EVENTFD 1 |
296 | # define EV_USE_EVENTFD EV_FEATURE_OS |
304 | # else |
297 | # else |
305 | # define EV_USE_EVENTFD 0 |
298 | # define EV_USE_EVENTFD 0 |
306 | # endif |
299 | # endif |
307 | #endif |
300 | #endif |
308 | |
301 | |
309 | #ifndef EV_USE_SIGNALFD |
302 | #ifndef EV_USE_SIGNALFD |
310 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
303 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
311 | # define EV_USE_SIGNALFD 1 |
304 | # define EV_USE_SIGNALFD EV_FEATURE_OS |
312 | # else |
305 | # else |
313 | # define EV_USE_SIGNALFD 0 |
306 | # define EV_USE_SIGNALFD 0 |
314 | # endif |
307 | # endif |
315 | #endif |
308 | #endif |
316 | |
309 | |
… | |
… | |
319 | # define EV_USE_4HEAP 1 |
312 | # define EV_USE_4HEAP 1 |
320 | # define EV_HEAP_CACHE_AT 1 |
313 | # define EV_HEAP_CACHE_AT 1 |
321 | #endif |
314 | #endif |
322 | |
315 | |
323 | #ifndef EV_VERIFY |
316 | #ifndef EV_VERIFY |
324 | # define EV_VERIFY !EV_MINIMAL |
317 | # define EV_VERIFY (EV_FEATURE_API ? 1 : 0) |
325 | #endif |
318 | #endif |
326 | |
319 | |
327 | #ifndef EV_USE_4HEAP |
320 | #ifndef EV_USE_4HEAP |
328 | # define EV_USE_4HEAP !EV_MINIMAL |
321 | # define EV_USE_4HEAP EV_FEATURE_DATA |
329 | #endif |
322 | #endif |
330 | |
323 | |
331 | #ifndef EV_HEAP_CACHE_AT |
324 | #ifndef EV_HEAP_CACHE_AT |
332 | # define EV_HEAP_CACHE_AT !EV_MINIMAL |
325 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
333 | #endif |
326 | #endif |
334 | |
327 | |
335 | /* 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, */ |
336 | /* which makes programs even slower. might work on other unices, too. */ |
329 | /* which makes programs even slower. might work on other unices, too. */ |
337 | #if EV_USE_CLOCK_SYSCALL |
330 | #if EV_USE_CLOCK_SYSCALL |
… | |
… | |
442 | |
435 | |
443 | |
436 | |
444 | /**/ |
437 | /**/ |
445 | |
438 | |
446 | #if EV_VERIFY >= 3 |
439 | #if EV_VERIFY >= 3 |
447 | # define EV_FREQUENT_CHECK ev_loop_verify (EV_A) |
440 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
448 | #else |
441 | #else |
449 | # define EV_FREQUENT_CHECK do { } while (0) |
442 | # define EV_FREQUENT_CHECK do { } while (0) |
450 | #endif |
443 | #endif |
451 | |
444 | |
452 | /* |
445 | /* |
… | |
… | |
475 | |
468 | |
476 | #define expect_false(expr) expect ((expr) != 0, 0) |
469 | #define expect_false(expr) expect ((expr) != 0, 0) |
477 | #define expect_true(expr) expect ((expr) != 0, 1) |
470 | #define expect_true(expr) expect ((expr) != 0, 1) |
478 | #define inline_size static inline |
471 | #define inline_size static inline |
479 | |
472 | |
480 | #if EV_MINIMAL |
473 | #if EV_FEATURE_CODE |
|
|
474 | # define inline_speed static inline |
|
|
475 | #else |
481 | # define inline_speed static noinline |
476 | # define inline_speed static noinline |
482 | #else |
|
|
483 | # define inline_speed static inline |
|
|
484 | #endif |
477 | #endif |
485 | |
478 | |
486 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
479 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
487 | |
480 | |
488 | #if EV_MINPRI == EV_MAXPRI |
481 | #if EV_MINPRI == EV_MAXPRI |
… | |
… | |
568 | } |
561 | } |
569 | |
562 | |
570 | static void * |
563 | static void * |
571 | ev_realloc_emul (void *ptr, long size) |
564 | ev_realloc_emul (void *ptr, long size) |
572 | { |
565 | { |
|
|
566 | #if __GLIBC__ |
|
|
567 | return realloc (ptr, size); |
|
|
568 | #else |
573 | /* some systems, notably openbsd and darwin, fail to properly |
569 | /* some systems, notably openbsd and darwin, fail to properly |
574 | * implement realloc (x, 0) (as required by both ansi c-98 and |
570 | * implement realloc (x, 0) (as required by both ansi c-89 and |
575 | * the single unix specification, so work around them here. |
571 | * the single unix specification, so work around them here. |
576 | */ |
572 | */ |
|
|
573 | |
577 | if (size) |
574 | if (size) |
578 | return realloc (ptr, size); |
575 | return realloc (ptr, size); |
579 | |
576 | |
580 | free (ptr); |
577 | free (ptr); |
581 | return 0; |
578 | return 0; |
|
|
579 | #endif |
582 | } |
580 | } |
583 | |
581 | |
584 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
582 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
585 | |
583 | |
586 | void |
584 | void |
… | |
… | |
690 | |
688 | |
691 | static int ev_default_loop_ptr; |
689 | static int ev_default_loop_ptr; |
692 | |
690 | |
693 | #endif |
691 | #endif |
694 | |
692 | |
695 | #if EV_MINIMAL < 2 |
693 | #if EV_FEATURE_API |
696 | # 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) |
697 | # 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) |
698 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
696 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
699 | #else |
697 | #else |
700 | # define EV_RELEASE_CB (void)0 |
698 | # define EV_RELEASE_CB (void)0 |
… | |
… | |
885 | } |
883 | } |
886 | |
884 | |
887 | /*****************************************************************************/ |
885 | /*****************************************************************************/ |
888 | |
886 | |
889 | inline_speed void |
887 | inline_speed void |
890 | fd_event_nc (EV_P_ int fd, int revents) |
888 | fd_event_nocheck (EV_P_ int fd, int revents) |
891 | { |
889 | { |
892 | ANFD *anfd = anfds + fd; |
890 | ANFD *anfd = anfds + fd; |
893 | ev_io *w; |
891 | ev_io *w; |
894 | |
892 | |
895 | 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) |
… | |
… | |
907 | fd_event (EV_P_ int fd, int revents) |
905 | fd_event (EV_P_ int fd, int revents) |
908 | { |
906 | { |
909 | ANFD *anfd = anfds + fd; |
907 | ANFD *anfd = anfds + fd; |
910 | |
908 | |
911 | if (expect_true (!anfd->reify)) |
909 | if (expect_true (!anfd->reify)) |
912 | fd_event_nc (EV_A_ fd, revents); |
910 | fd_event_nocheck (EV_A_ fd, revents); |
913 | } |
911 | } |
914 | |
912 | |
915 | void |
913 | void |
916 | ev_feed_fd_event (EV_P_ int fd, int revents) |
914 | ev_feed_fd_event (EV_P_ int fd, int revents) |
917 | { |
915 | { |
918 | if (fd >= 0 && fd < anfdmax) |
916 | if (fd >= 0 && fd < anfdmax) |
919 | fd_event_nc (EV_A_ fd, revents); |
917 | fd_event_nocheck (EV_A_ fd, revents); |
920 | } |
918 | } |
921 | |
919 | |
922 | /* make sure the external fd watch events are in-sync */ |
920 | /* make sure the external fd watch events are in-sync */ |
923 | /* with the kernel/libev internal state */ |
921 | /* with the kernel/libev internal state */ |
924 | inline_size void |
922 | inline_size void |
… | |
… | |
987 | ev_io_stop (EV_A_ w); |
985 | ev_io_stop (EV_A_ w); |
988 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
986 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
989 | } |
987 | } |
990 | } |
988 | } |
991 | |
989 | |
992 | /* check whether the given fd is atcually valid, for error recovery */ |
990 | /* check whether the given fd is actually valid, for error recovery */ |
993 | inline_size int |
991 | inline_size int |
994 | fd_valid (int fd) |
992 | fd_valid (int fd) |
995 | { |
993 | { |
996 | #ifdef _WIN32 |
994 | #ifdef _WIN32 |
997 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
995 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
… | |
… | |
1037 | { |
1035 | { |
1038 | anfds [fd].events = 0; |
1036 | anfds [fd].events = 0; |
1039 | anfds [fd].emask = 0; |
1037 | anfds [fd].emask = 0; |
1040 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1038 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1041 | } |
1039 | } |
|
|
1040 | } |
|
|
1041 | |
|
|
1042 | /* used to prepare libev internal fd's */ |
|
|
1043 | /* this is not fork-safe */ |
|
|
1044 | inline_speed void |
|
|
1045 | fd_intern (int fd) |
|
|
1046 | { |
|
|
1047 | #ifdef _WIN32 |
|
|
1048 | unsigned long arg = 1; |
|
|
1049 | ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg); |
|
|
1050 | #else |
|
|
1051 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1052 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1053 | #endif |
1042 | } |
1054 | } |
1043 | |
1055 | |
1044 | /*****************************************************************************/ |
1056 | /*****************************************************************************/ |
1045 | |
1057 | |
1046 | /* |
1058 | /* |
… | |
… | |
1200 | |
1212 | |
1201 | static ANSIG signals [EV_NSIG - 1]; |
1213 | static ANSIG signals [EV_NSIG - 1]; |
1202 | |
1214 | |
1203 | /*****************************************************************************/ |
1215 | /*****************************************************************************/ |
1204 | |
1216 | |
1205 | /* used to prepare libev internal fd's */ |
1217 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1206 | /* this is not fork-safe */ |
|
|
1207 | inline_speed void |
|
|
1208 | fd_intern (int fd) |
|
|
1209 | { |
|
|
1210 | #ifdef _WIN32 |
|
|
1211 | unsigned long arg = 1; |
|
|
1212 | ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg); |
|
|
1213 | #else |
|
|
1214 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1215 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1216 | #endif |
|
|
1217 | } |
|
|
1218 | |
1218 | |
1219 | static void noinline |
1219 | static void noinline |
1220 | evpipe_init (EV_P) |
1220 | evpipe_init (EV_P) |
1221 | { |
1221 | { |
1222 | if (!ev_is_active (&pipe_w)) |
1222 | if (!ev_is_active (&pipe_w)) |
1223 | { |
1223 | { |
1224 | #if EV_USE_EVENTFD |
1224 | # if EV_USE_EVENTFD |
1225 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1225 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1226 | if (evfd < 0 && errno == EINVAL) |
1226 | if (evfd < 0 && errno == EINVAL) |
1227 | evfd = eventfd (0, 0); |
1227 | evfd = eventfd (0, 0); |
1228 | |
1228 | |
1229 | if (evfd >= 0) |
1229 | if (evfd >= 0) |
… | |
… | |
1231 | evpipe [0] = -1; |
1231 | evpipe [0] = -1; |
1232 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1232 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1233 | ev_io_set (&pipe_w, evfd, EV_READ); |
1233 | ev_io_set (&pipe_w, evfd, EV_READ); |
1234 | } |
1234 | } |
1235 | else |
1235 | else |
1236 | #endif |
1236 | # endif |
1237 | { |
1237 | { |
1238 | while (pipe (evpipe)) |
1238 | while (pipe (evpipe)) |
1239 | ev_syserr ("(libev) error creating signal/async pipe"); |
1239 | ev_syserr ("(libev) error creating signal/async pipe"); |
1240 | |
1240 | |
1241 | fd_intern (evpipe [0]); |
1241 | fd_intern (evpipe [0]); |
… | |
… | |
1252 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1252 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1253 | { |
1253 | { |
1254 | if (!*flag) |
1254 | if (!*flag) |
1255 | { |
1255 | { |
1256 | int old_errno = errno; /* save errno because write might clobber it */ |
1256 | int old_errno = errno; /* save errno because write might clobber it */ |
|
|
1257 | char dummy; |
1257 | |
1258 | |
1258 | *flag = 1; |
1259 | *flag = 1; |
1259 | |
1260 | |
1260 | #if EV_USE_EVENTFD |
1261 | #if EV_USE_EVENTFD |
1261 | if (evfd >= 0) |
1262 | if (evfd >= 0) |
… | |
… | |
1263 | uint64_t counter = 1; |
1264 | uint64_t counter = 1; |
1264 | write (evfd, &counter, sizeof (uint64_t)); |
1265 | write (evfd, &counter, sizeof (uint64_t)); |
1265 | } |
1266 | } |
1266 | else |
1267 | else |
1267 | #endif |
1268 | #endif |
1268 | write (evpipe [1], &old_errno, 1); |
1269 | write (evpipe [1], &dummy, 1); |
1269 | |
1270 | |
1270 | errno = old_errno; |
1271 | errno = old_errno; |
1271 | } |
1272 | } |
1272 | } |
1273 | } |
1273 | |
1274 | |
… | |
… | |
1374 | break; |
1375 | break; |
1375 | } |
1376 | } |
1376 | } |
1377 | } |
1377 | #endif |
1378 | #endif |
1378 | |
1379 | |
|
|
1380 | #endif |
|
|
1381 | |
1379 | /*****************************************************************************/ |
1382 | /*****************************************************************************/ |
1380 | |
1383 | |
|
|
1384 | #if EV_CHILD_ENABLE |
1381 | static WL childs [EV_PID_HASHSIZE]; |
1385 | static WL childs [EV_PID_HASHSIZE]; |
1382 | |
|
|
1383 | #ifndef _WIN32 |
|
|
1384 | |
1386 | |
1385 | static ev_signal childev; |
1387 | static ev_signal childev; |
1386 | |
1388 | |
1387 | #ifndef WIFCONTINUED |
1389 | #ifndef WIFCONTINUED |
1388 | # define WIFCONTINUED(status) 0 |
1390 | # define WIFCONTINUED(status) 0 |
… | |
… | |
1393 | child_reap (EV_P_ int chain, int pid, int status) |
1395 | child_reap (EV_P_ int chain, int pid, int status) |
1394 | { |
1396 | { |
1395 | ev_child *w; |
1397 | ev_child *w; |
1396 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1398 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1397 | |
1399 | |
1398 | 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) |
1399 | { |
1401 | { |
1400 | if ((w->pid == pid || !w->pid) |
1402 | if ((w->pid == pid || !w->pid) |
1401 | && (!traced || (w->flags & 1))) |
1403 | && (!traced || (w->flags & 1))) |
1402 | { |
1404 | { |
1403 | 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 */ |
… | |
… | |
1428 | /* 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 */ |
1429 | /* 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 */ |
1430 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1432 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1431 | |
1433 | |
1432 | child_reap (EV_A_ pid, pid, status); |
1434 | child_reap (EV_A_ pid, pid, status); |
1433 | if (EV_PID_HASHSIZE > 1) |
1435 | if ((EV_PID_HASHSIZE) > 1) |
1434 | 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 */ |
1435 | } |
1437 | } |
1436 | |
1438 | |
1437 | #endif |
1439 | #endif |
1438 | |
1440 | |
… | |
… | |
1505 | #ifdef __APPLE__ |
1507 | #ifdef __APPLE__ |
1506 | /* only select works correctly on that "unix-certified" platform */ |
1508 | /* only select works correctly on that "unix-certified" platform */ |
1507 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1509 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1508 | 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 */ |
1509 | #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 |
1510 | |
1515 | |
1511 | return flags; |
1516 | return flags; |
1512 | } |
1517 | } |
1513 | |
1518 | |
1514 | unsigned int |
1519 | unsigned int |
… | |
… | |
1527 | ev_backend (EV_P) |
1532 | ev_backend (EV_P) |
1528 | { |
1533 | { |
1529 | return backend; |
1534 | return backend; |
1530 | } |
1535 | } |
1531 | |
1536 | |
1532 | #if EV_MINIMAL < 2 |
1537 | #if EV_FEATURE_API |
1533 | unsigned int |
1538 | unsigned int |
1534 | ev_loop_count (EV_P) |
1539 | ev_iteration (EV_P) |
1535 | { |
1540 | { |
1536 | return loop_count; |
1541 | return loop_count; |
1537 | } |
1542 | } |
1538 | |
1543 | |
1539 | unsigned int |
1544 | unsigned int |
1540 | ev_loop_depth (EV_P) |
1545 | ev_depth (EV_P) |
1541 | { |
1546 | { |
1542 | return loop_depth; |
1547 | return loop_depth; |
1543 | } |
1548 | } |
1544 | |
1549 | |
1545 | void |
1550 | void |
… | |
… | |
1617 | |
1622 | |
1618 | ev_rt_now = ev_time (); |
1623 | ev_rt_now = ev_time (); |
1619 | mn_now = get_clock (); |
1624 | mn_now = get_clock (); |
1620 | now_floor = mn_now; |
1625 | now_floor = mn_now; |
1621 | rtmn_diff = ev_rt_now - mn_now; |
1626 | rtmn_diff = ev_rt_now - mn_now; |
1622 | #if EV_MINIMAL < 2 |
1627 | #if EV_FEATURE_API |
1623 | invoke_cb = ev_invoke_pending; |
1628 | invoke_cb = ev_invoke_pending; |
1624 | #endif |
1629 | #endif |
1625 | |
1630 | |
1626 | io_blocktime = 0.; |
1631 | io_blocktime = 0.; |
1627 | timeout_blocktime = 0.; |
1632 | timeout_blocktime = 0.; |
… | |
… | |
1657 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1662 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1658 | #endif |
1663 | #endif |
1659 | |
1664 | |
1660 | ev_prepare_init (&pending_w, pendingcb); |
1665 | ev_prepare_init (&pending_w, pendingcb); |
1661 | |
1666 | |
|
|
1667 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1662 | ev_init (&pipe_w, pipecb); |
1668 | ev_init (&pipe_w, pipecb); |
1663 | ev_set_priority (&pipe_w, EV_MAXPRI); |
1669 | ev_set_priority (&pipe_w, EV_MAXPRI); |
|
|
1670 | #endif |
1664 | } |
1671 | } |
1665 | } |
1672 | } |
1666 | |
1673 | |
1667 | /* free up a loop structure */ |
1674 | /* free up a loop structure */ |
1668 | static void noinline |
1675 | static void noinline |
… | |
… | |
1786 | { |
1793 | { |
1787 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1794 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1788 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1795 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1789 | } |
1796 | } |
1790 | |
1797 | |
|
|
1798 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1791 | evpipe_init (EV_A); |
1799 | evpipe_init (EV_A); |
1792 | /* now iterate over everything, in case we missed something */ |
1800 | /* now iterate over everything, in case we missed something */ |
1793 | pipecb (EV_A_ &pipe_w, EV_READ); |
1801 | pipecb (EV_A_ &pipe_w, EV_READ); |
|
|
1802 | #endif |
1794 | } |
1803 | } |
1795 | |
1804 | |
1796 | postfork = 0; |
1805 | postfork = 0; |
1797 | } |
1806 | } |
1798 | |
1807 | |
… | |
… | |
1860 | verify_watcher (EV_A_ ws [cnt]); |
1869 | verify_watcher (EV_A_ ws [cnt]); |
1861 | } |
1870 | } |
1862 | } |
1871 | } |
1863 | #endif |
1872 | #endif |
1864 | |
1873 | |
1865 | #if EV_MINIMAL < 2 |
1874 | #if EV_FEATURE_API |
1866 | void |
1875 | void |
1867 | ev_loop_verify (EV_P) |
1876 | ev_verify (EV_P) |
1868 | { |
1877 | { |
1869 | #if EV_VERIFY |
1878 | #if EV_VERIFY |
1870 | int i; |
1879 | int i; |
1871 | WL w; |
1880 | WL w; |
1872 | |
1881 | |
… | |
… | |
1911 | #if EV_ASYNC_ENABLE |
1920 | #if EV_ASYNC_ENABLE |
1912 | assert (asyncmax >= asynccnt); |
1921 | assert (asyncmax >= asynccnt); |
1913 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1922 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1914 | #endif |
1923 | #endif |
1915 | |
1924 | |
|
|
1925 | #if EV_PREPARE_ENABLE |
1916 | assert (preparemax >= preparecnt); |
1926 | assert (preparemax >= preparecnt); |
1917 | array_verify (EV_A_ (W *)prepares, preparecnt); |
1927 | array_verify (EV_A_ (W *)prepares, preparecnt); |
|
|
1928 | #endif |
1918 | |
1929 | |
|
|
1930 | #if EV_CHECK_ENABLE |
1919 | assert (checkmax >= checkcnt); |
1931 | assert (checkmax >= checkcnt); |
1920 | array_verify (EV_A_ (W *)checks, checkcnt); |
1932 | array_verify (EV_A_ (W *)checks, checkcnt); |
|
|
1933 | #endif |
1921 | |
1934 | |
1922 | # if 0 |
1935 | # if 0 |
|
|
1936 | #if EV_CHILD_ENABLE |
1923 | 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) |
1924 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
1938 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
|
|
1939 | #endif |
1925 | # endif |
1940 | # endif |
1926 | #endif |
1941 | #endif |
1927 | } |
1942 | } |
1928 | #endif |
1943 | #endif |
1929 | |
1944 | |
… | |
… | |
1945 | |
1960 | |
1946 | loop_init (EV_A_ flags); |
1961 | loop_init (EV_A_ flags); |
1947 | |
1962 | |
1948 | if (ev_backend (EV_A)) |
1963 | if (ev_backend (EV_A)) |
1949 | { |
1964 | { |
1950 | #ifndef _WIN32 |
1965 | #if EV_CHILD_ENABLE |
1951 | ev_signal_init (&childev, childcb, SIGCHLD); |
1966 | ev_signal_init (&childev, childcb, SIGCHLD); |
1952 | ev_set_priority (&childev, EV_MAXPRI); |
1967 | ev_set_priority (&childev, EV_MAXPRI); |
1953 | ev_signal_start (EV_A_ &childev); |
1968 | ev_signal_start (EV_A_ &childev); |
1954 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1969 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1955 | #endif |
1970 | #endif |
… | |
… | |
1968 | EV_P = ev_default_loop_ptr; |
1983 | EV_P = ev_default_loop_ptr; |
1969 | #endif |
1984 | #endif |
1970 | |
1985 | |
1971 | ev_default_loop_ptr = 0; |
1986 | ev_default_loop_ptr = 0; |
1972 | |
1987 | |
1973 | #ifndef _WIN32 |
1988 | #if EV_CHILD_ENABLE |
1974 | ev_ref (EV_A); /* child watcher */ |
1989 | ev_ref (EV_A); /* child watcher */ |
1975 | ev_signal_stop (EV_A_ &childev); |
1990 | ev_signal_stop (EV_A_ &childev); |
1976 | #endif |
1991 | #endif |
1977 | |
1992 | |
1978 | loop_destroy (EV_A); |
1993 | loop_destroy (EV_A); |
… | |
… | |
2084 | EV_FREQUENT_CHECK; |
2099 | EV_FREQUENT_CHECK; |
2085 | feed_reverse (EV_A_ (W)w); |
2100 | feed_reverse (EV_A_ (W)w); |
2086 | } |
2101 | } |
2087 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2102 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2088 | |
2103 | |
2089 | feed_reverse_done (EV_A_ EV_TIMEOUT); |
2104 | feed_reverse_done (EV_A_ EV_TIMER); |
2090 | } |
2105 | } |
2091 | } |
2106 | } |
2092 | |
2107 | |
2093 | #if EV_PERIODIC_ENABLE |
2108 | #if EV_PERIODIC_ENABLE |
2094 | /* make periodics pending */ |
2109 | /* make periodics pending */ |
… | |
… | |
2255 | } |
2270 | } |
2256 | |
2271 | |
2257 | void |
2272 | void |
2258 | ev_loop (EV_P_ int flags) |
2273 | ev_loop (EV_P_ int flags) |
2259 | { |
2274 | { |
2260 | #if EV_MINIMAL < 2 |
2275 | #if EV_FEATURE_API |
2261 | ++loop_depth; |
2276 | ++loop_depth; |
2262 | #endif |
2277 | #endif |
2263 | |
2278 | |
2264 | 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)); |
2265 | |
2280 | |
… | |
… | |
2268 | 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 */ |
2269 | |
2284 | |
2270 | do |
2285 | do |
2271 | { |
2286 | { |
2272 | #if EV_VERIFY >= 2 |
2287 | #if EV_VERIFY >= 2 |
2273 | ev_loop_verify (EV_A); |
2288 | ev_verify (EV_A); |
2274 | #endif |
2289 | #endif |
2275 | |
2290 | |
2276 | #ifndef _WIN32 |
2291 | #ifndef _WIN32 |
2277 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2292 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2278 | if (expect_false (getpid () != curpid)) |
2293 | if (expect_false (getpid () != curpid)) |
… | |
… | |
2290 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2305 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2291 | EV_INVOKE_PENDING; |
2306 | EV_INVOKE_PENDING; |
2292 | } |
2307 | } |
2293 | #endif |
2308 | #endif |
2294 | |
2309 | |
|
|
2310 | #if EV_PREPARE_ENABLE |
2295 | /* queue prepare watchers (and execute them) */ |
2311 | /* queue prepare watchers (and execute them) */ |
2296 | if (expect_false (preparecnt)) |
2312 | if (expect_false (preparecnt)) |
2297 | { |
2313 | { |
2298 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2314 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2299 | EV_INVOKE_PENDING; |
2315 | EV_INVOKE_PENDING; |
2300 | } |
2316 | } |
|
|
2317 | #endif |
2301 | |
2318 | |
2302 | if (expect_false (loop_done)) |
2319 | if (expect_false (loop_done)) |
2303 | break; |
2320 | break; |
2304 | |
2321 | |
2305 | /* we might have forked, so reify kernel state if necessary */ |
2322 | /* we might have forked, so reify kernel state if necessary */ |
… | |
… | |
2356 | waittime -= sleeptime; |
2373 | waittime -= sleeptime; |
2357 | } |
2374 | } |
2358 | } |
2375 | } |
2359 | } |
2376 | } |
2360 | |
2377 | |
2361 | #if EV_MINIMAL < 2 |
2378 | #if EV_FEATURE_API |
2362 | ++loop_count; |
2379 | ++loop_count; |
2363 | #endif |
2380 | #endif |
2364 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2381 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2365 | backend_poll (EV_A_ waittime); |
2382 | backend_poll (EV_A_ waittime); |
2366 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
2383 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
… | |
… | |
2378 | #if EV_IDLE_ENABLE |
2395 | #if EV_IDLE_ENABLE |
2379 | /* queue idle watchers unless other events are pending */ |
2396 | /* queue idle watchers unless other events are pending */ |
2380 | idle_reify (EV_A); |
2397 | idle_reify (EV_A); |
2381 | #endif |
2398 | #endif |
2382 | |
2399 | |
|
|
2400 | #if EV_CHECK_ENABLE |
2383 | /* queue check watchers, to be executed first */ |
2401 | /* queue check watchers, to be executed first */ |
2384 | if (expect_false (checkcnt)) |
2402 | if (expect_false (checkcnt)) |
2385 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
2403 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
|
|
2404 | #endif |
2386 | |
2405 | |
2387 | EV_INVOKE_PENDING; |
2406 | EV_INVOKE_PENDING; |
2388 | } |
2407 | } |
2389 | while (expect_true ( |
2408 | while (expect_true ( |
2390 | activecnt |
2409 | activecnt |
… | |
… | |
2393 | )); |
2412 | )); |
2394 | |
2413 | |
2395 | if (loop_done == EVUNLOOP_ONE) |
2414 | if (loop_done == EVUNLOOP_ONE) |
2396 | loop_done = EVUNLOOP_CANCEL; |
2415 | loop_done = EVUNLOOP_CANCEL; |
2397 | |
2416 | |
2398 | #if EV_MINIMAL < 2 |
2417 | #if EV_FEATURE_API |
2399 | --loop_depth; |
2418 | --loop_depth; |
2400 | #endif |
2419 | #endif |
2401 | } |
2420 | } |
2402 | |
2421 | |
2403 | void |
2422 | void |
… | |
… | |
2720 | |
2739 | |
2721 | #ifndef SA_RESTART |
2740 | #ifndef SA_RESTART |
2722 | # define SA_RESTART 0 |
2741 | # define SA_RESTART 0 |
2723 | #endif |
2742 | #endif |
2724 | |
2743 | |
|
|
2744 | #if EV_SIGNAL_ENABLE |
|
|
2745 | |
2725 | void noinline |
2746 | void noinline |
2726 | ev_signal_start (EV_P_ ev_signal *w) |
2747 | ev_signal_start (EV_P_ ev_signal *w) |
2727 | { |
2748 | { |
2728 | if (expect_false (ev_is_active (w))) |
2749 | if (expect_false (ev_is_active (w))) |
2729 | return; |
2750 | return; |
… | |
… | |
2835 | } |
2856 | } |
2836 | |
2857 | |
2837 | EV_FREQUENT_CHECK; |
2858 | EV_FREQUENT_CHECK; |
2838 | } |
2859 | } |
2839 | |
2860 | |
|
|
2861 | #endif |
|
|
2862 | |
|
|
2863 | #if EV_CHILD_ENABLE |
|
|
2864 | |
2840 | void |
2865 | void |
2841 | ev_child_start (EV_P_ ev_child *w) |
2866 | ev_child_start (EV_P_ ev_child *w) |
2842 | { |
2867 | { |
2843 | #if EV_MULTIPLICITY |
2868 | #if EV_MULTIPLICITY |
2844 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
2869 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
… | |
… | |
2847 | return; |
2872 | return; |
2848 | |
2873 | |
2849 | EV_FREQUENT_CHECK; |
2874 | EV_FREQUENT_CHECK; |
2850 | |
2875 | |
2851 | ev_start (EV_A_ (W)w, 1); |
2876 | ev_start (EV_A_ (W)w, 1); |
2852 | wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2877 | wlist_add (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2853 | |
2878 | |
2854 | EV_FREQUENT_CHECK; |
2879 | EV_FREQUENT_CHECK; |
2855 | } |
2880 | } |
2856 | |
2881 | |
2857 | void |
2882 | void |
… | |
… | |
2861 | if (expect_false (!ev_is_active (w))) |
2886 | if (expect_false (!ev_is_active (w))) |
2862 | return; |
2887 | return; |
2863 | |
2888 | |
2864 | EV_FREQUENT_CHECK; |
2889 | EV_FREQUENT_CHECK; |
2865 | |
2890 | |
2866 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2891 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2867 | ev_stop (EV_A_ (W)w); |
2892 | ev_stop (EV_A_ (W)w); |
2868 | |
2893 | |
2869 | EV_FREQUENT_CHECK; |
2894 | EV_FREQUENT_CHECK; |
2870 | } |
2895 | } |
|
|
2896 | |
|
|
2897 | #endif |
2871 | |
2898 | |
2872 | #if EV_STAT_ENABLE |
2899 | #if EV_STAT_ENABLE |
2873 | |
2900 | |
2874 | # ifdef _WIN32 |
2901 | # ifdef _WIN32 |
2875 | # undef lstat |
2902 | # undef lstat |
… | |
… | |
2942 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2969 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2943 | } |
2970 | } |
2944 | } |
2971 | } |
2945 | |
2972 | |
2946 | if (w->wd >= 0) |
2973 | if (w->wd >= 0) |
2947 | 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); |
2948 | |
2975 | |
2949 | /* now re-arm timer, if required */ |
2976 | /* now re-arm timer, if required */ |
2950 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2977 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2951 | ev_timer_again (EV_A_ &w->timer); |
2978 | ev_timer_again (EV_A_ &w->timer); |
2952 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
2979 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
… | |
… | |
2960 | |
2987 | |
2961 | if (wd < 0) |
2988 | if (wd < 0) |
2962 | return; |
2989 | return; |
2963 | |
2990 | |
2964 | w->wd = -2; |
2991 | w->wd = -2; |
2965 | slot = wd & (EV_INOTIFY_HASHSIZE - 1); |
2992 | slot = wd & ((EV_INOTIFY_HASHSIZE) - 1); |
2966 | wlist_del (&fs_hash [slot].head, (WL)w); |
2993 | wlist_del (&fs_hash [slot].head, (WL)w); |
2967 | |
2994 | |
2968 | /* remove this watcher, if others are watching it, they will rearm */ |
2995 | /* remove this watcher, if others are watching it, they will rearm */ |
2969 | inotify_rm_watch (fs_fd, wd); |
2996 | inotify_rm_watch (fs_fd, wd); |
2970 | } |
2997 | } |
… | |
… | |
2972 | static void noinline |
2999 | static void noinline |
2973 | 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) |
2974 | { |
3001 | { |
2975 | if (slot < 0) |
3002 | if (slot < 0) |
2976 | /* overflow, need to check for all hash slots */ |
3003 | /* overflow, need to check for all hash slots */ |
2977 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3004 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
2978 | infy_wd (EV_A_ slot, wd, ev); |
3005 | infy_wd (EV_A_ slot, wd, ev); |
2979 | else |
3006 | else |
2980 | { |
3007 | { |
2981 | WL w_; |
3008 | WL w_; |
2982 | |
3009 | |
2983 | for (w_ = fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head; w_; ) |
3010 | for (w_ = fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head; w_; ) |
2984 | { |
3011 | { |
2985 | ev_stat *w = (ev_stat *)w_; |
3012 | ev_stat *w = (ev_stat *)w_; |
2986 | 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 */ |
2987 | |
3014 | |
2988 | if (w->wd == wd || wd == -1) |
3015 | if (w->wd == wd || wd == -1) |
2989 | { |
3016 | { |
2990 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
3017 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
2991 | { |
3018 | { |
2992 | 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); |
2993 | w->wd = -1; |
3020 | w->wd = -1; |
2994 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3021 | infy_add (EV_A_ w); /* re-add, no matter what */ |
2995 | } |
3022 | } |
2996 | |
3023 | |
2997 | stat_timer_cb (EV_A_ &w->timer, 0); |
3024 | stat_timer_cb (EV_A_ &w->timer, 0); |
… | |
… | |
3111 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3138 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3112 | ev_io_start (EV_A_ &fs_w); |
3139 | ev_io_start (EV_A_ &fs_w); |
3113 | ev_unref (EV_A); |
3140 | ev_unref (EV_A); |
3114 | } |
3141 | } |
3115 | |
3142 | |
3116 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3143 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
3117 | { |
3144 | { |
3118 | WL w_ = fs_hash [slot].head; |
3145 | WL w_ = fs_hash [slot].head; |
3119 | fs_hash [slot].head = 0; |
3146 | fs_hash [slot].head = 0; |
3120 | |
3147 | |
3121 | while (w_) |
3148 | while (w_) |
… | |
… | |
3296 | |
3323 | |
3297 | EV_FREQUENT_CHECK; |
3324 | EV_FREQUENT_CHECK; |
3298 | } |
3325 | } |
3299 | #endif |
3326 | #endif |
3300 | |
3327 | |
|
|
3328 | #if EV_PREPARE_ENABLE |
3301 | void |
3329 | void |
3302 | ev_prepare_start (EV_P_ ev_prepare *w) |
3330 | ev_prepare_start (EV_P_ ev_prepare *w) |
3303 | { |
3331 | { |
3304 | if (expect_false (ev_is_active (w))) |
3332 | if (expect_false (ev_is_active (w))) |
3305 | return; |
3333 | return; |
… | |
… | |
3331 | |
3359 | |
3332 | ev_stop (EV_A_ (W)w); |
3360 | ev_stop (EV_A_ (W)w); |
3333 | |
3361 | |
3334 | EV_FREQUENT_CHECK; |
3362 | EV_FREQUENT_CHECK; |
3335 | } |
3363 | } |
|
|
3364 | #endif |
3336 | |
3365 | |
|
|
3366 | #if EV_CHECK_ENABLE |
3337 | void |
3367 | void |
3338 | ev_check_start (EV_P_ ev_check *w) |
3368 | ev_check_start (EV_P_ ev_check *w) |
3339 | { |
3369 | { |
3340 | if (expect_false (ev_is_active (w))) |
3370 | if (expect_false (ev_is_active (w))) |
3341 | return; |
3371 | return; |
… | |
… | |
3367 | |
3397 | |
3368 | ev_stop (EV_A_ (W)w); |
3398 | ev_stop (EV_A_ (W)w); |
3369 | |
3399 | |
3370 | EV_FREQUENT_CHECK; |
3400 | EV_FREQUENT_CHECK; |
3371 | } |
3401 | } |
|
|
3402 | #endif |
3372 | |
3403 | |
3373 | #if EV_EMBED_ENABLE |
3404 | #if EV_EMBED_ENABLE |
3374 | void noinline |
3405 | void noinline |
3375 | ev_embed_sweep (EV_P_ ev_embed *w) |
3406 | ev_embed_sweep (EV_P_ ev_embed *w) |
3376 | { |
3407 | { |
… | |
… | |
3608 | { |
3639 | { |
3609 | 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)); |
3610 | |
3641 | |
3611 | if (expect_false (!once)) |
3642 | if (expect_false (!once)) |
3612 | { |
3643 | { |
3613 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
3644 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
3614 | return; |
3645 | return; |
3615 | } |
3646 | } |
3616 | |
3647 | |
3617 | once->cb = cb; |
3648 | once->cb = cb; |
3618 | once->arg = arg; |
3649 | once->arg = arg; |
… | |
… | |
3705 | if (types & EV_ASYNC) |
3736 | if (types & EV_ASYNC) |
3706 | for (i = asynccnt; i--; ) |
3737 | for (i = asynccnt; i--; ) |
3707 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3738 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3708 | #endif |
3739 | #endif |
3709 | |
3740 | |
|
|
3741 | #if EV_PREPARE_ENABLE |
3710 | if (types & EV_PREPARE) |
3742 | if (types & EV_PREPARE) |
3711 | for (i = preparecnt; i--; ) |
3743 | for (i = preparecnt; i--; ) |
3712 | #if EV_EMBED_ENABLE |
3744 | # if EV_EMBED_ENABLE |
3713 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3745 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3714 | #endif |
3746 | # endif |
3715 | cb (EV_A_ EV_PREPARE, prepares [i]); |
3747 | cb (EV_A_ EV_PREPARE, prepares [i]); |
|
|
3748 | #endif |
3716 | |
3749 | |
|
|
3750 | #if EV_CHECK_ENABLE |
3717 | if (types & EV_CHECK) |
3751 | if (types & EV_CHECK) |
3718 | for (i = checkcnt; i--; ) |
3752 | for (i = checkcnt; i--; ) |
3719 | cb (EV_A_ EV_CHECK, checks [i]); |
3753 | cb (EV_A_ EV_CHECK, checks [i]); |
|
|
3754 | #endif |
3720 | |
3755 | |
|
|
3756 | #if EV_SIGNAL_ENABLE |
3721 | if (types & EV_SIGNAL) |
3757 | if (types & EV_SIGNAL) |
3722 | for (i = 0; i < EV_NSIG - 1; ++i) |
3758 | for (i = 0; i < EV_NSIG - 1; ++i) |
3723 | for (wl = signals [i].head; wl; ) |
3759 | for (wl = signals [i].head; wl; ) |
3724 | { |
3760 | { |
3725 | wn = wl->next; |
3761 | wn = wl->next; |
3726 | cb (EV_A_ EV_SIGNAL, wl); |
3762 | cb (EV_A_ EV_SIGNAL, wl); |
3727 | wl = wn; |
3763 | wl = wn; |
3728 | } |
3764 | } |
|
|
3765 | #endif |
3729 | |
3766 | |
|
|
3767 | #if EV_CHILD_ENABLE |
3730 | if (types & EV_CHILD) |
3768 | if (types & EV_CHILD) |
3731 | for (i = EV_PID_HASHSIZE; i--; ) |
3769 | for (i = (EV_PID_HASHSIZE); i--; ) |
3732 | for (wl = childs [i]; wl; ) |
3770 | for (wl = childs [i]; wl; ) |
3733 | { |
3771 | { |
3734 | wn = wl->next; |
3772 | wn = wl->next; |
3735 | cb (EV_A_ EV_CHILD, wl); |
3773 | cb (EV_A_ EV_CHILD, wl); |
3736 | wl = wn; |
3774 | wl = wn; |
3737 | } |
3775 | } |
|
|
3776 | #endif |
3738 | /* EV_STAT 0x00001000 /* stat data changed */ |
3777 | /* EV_STAT 0x00001000 /* stat data changed */ |
3739 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3778 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3740 | } |
3779 | } |
3741 | #endif |
3780 | #endif |
3742 | |
3781 | |