… | |
… | |
77 | # ifndef EV_USE_REALTIME |
77 | # ifndef EV_USE_REALTIME |
78 | # define EV_USE_REALTIME 0 |
78 | # define EV_USE_REALTIME 0 |
79 | # endif |
79 | # endif |
80 | # endif |
80 | # endif |
81 | |
81 | |
|
|
82 | # if HAVE_NANOSLEEP |
82 | # ifndef EV_USE_NANOSLEEP |
83 | # ifndef EV_USE_NANOSLEEP |
83 | # if HAVE_NANOSLEEP |
|
|
84 | # define EV_USE_NANOSLEEP 1 |
84 | # define EV_USE_NANOSLEEP EV_FEATURE_OS |
|
|
85 | # endif |
85 | # else |
86 | # else |
|
|
87 | # undef EV_USE_NANOSLEEP |
86 | # define EV_USE_NANOSLEEP 0 |
88 | # define EV_USE_NANOSLEEP 0 |
|
|
89 | # endif |
|
|
90 | |
|
|
91 | # if HAVE_SELECT && HAVE_SYS_SELECT_H |
|
|
92 | # ifndef EV_USE_SELECT |
|
|
93 | # define EV_USE_SELECT EV_FEATURE_BACKENDS |
87 | # endif |
94 | # endif |
88 | # endif |
|
|
89 | |
|
|
90 | # ifndef EV_USE_SELECT |
|
|
91 | # if HAVE_SELECT && HAVE_SYS_SELECT_H |
|
|
92 | # define EV_USE_SELECT 1 |
|
|
93 | # else |
95 | # else |
|
|
96 | # undef EV_USE_SELECT |
94 | # define EV_USE_SELECT 0 |
97 | # define EV_USE_SELECT 0 |
|
|
98 | # endif |
|
|
99 | |
|
|
100 | # if HAVE_POLL && HAVE_POLL_H |
|
|
101 | # ifndef EV_USE_POLL |
|
|
102 | # define EV_USE_POLL EV_FEATURE_BACKENDS |
95 | # endif |
103 | # endif |
96 | # endif |
|
|
97 | |
|
|
98 | # ifndef EV_USE_POLL |
|
|
99 | # if HAVE_POLL && HAVE_POLL_H |
|
|
100 | # define EV_USE_POLL 1 |
|
|
101 | # else |
104 | # else |
|
|
105 | # undef EV_USE_POLL |
102 | # define EV_USE_POLL 0 |
106 | # define EV_USE_POLL 0 |
|
|
107 | # endif |
|
|
108 | |
|
|
109 | # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H |
|
|
110 | # ifndef EV_USE_EPOLL |
|
|
111 | # define EV_USE_EPOLL EV_FEATURE_BACKENDS |
103 | # endif |
112 | # endif |
|
|
113 | # else |
|
|
114 | # undef EV_USE_EPOLL |
|
|
115 | # define EV_USE_EPOLL 0 |
104 | # endif |
116 | # endif |
105 | |
117 | |
|
|
118 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
106 | # ifndef EV_USE_EPOLL |
119 | # ifndef EV_USE_KQUEUE |
107 | # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H |
120 | # define EV_USE_KQUEUE EV_FEATURE_BACKENDS |
108 | # define EV_USE_EPOLL 1 |
|
|
109 | # else |
|
|
110 | # define EV_USE_EPOLL 0 |
|
|
111 | # endif |
121 | # endif |
|
|
122 | # else |
|
|
123 | # undef EV_USE_KQUEUE |
|
|
124 | # define EV_USE_KQUEUE 0 |
112 | # endif |
125 | # endif |
113 | |
126 | |
114 | # ifndef EV_USE_KQUEUE |
127 | # if HAVE_PORT_H && HAVE_PORT_CREATE |
115 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
128 | # ifndef EV_USE_PORT |
116 | # define EV_USE_KQUEUE 1 |
129 | # define EV_USE_PORT EV_FEATURE_BACKENDS |
117 | # else |
|
|
118 | # define EV_USE_KQUEUE 0 |
|
|
119 | # endif |
130 | # endif |
120 | # endif |
|
|
121 | |
|
|
122 | # ifndef EV_USE_PORT |
|
|
123 | # if HAVE_PORT_H && HAVE_PORT_CREATE |
|
|
124 | # define EV_USE_PORT 1 |
|
|
125 | # else |
131 | # else |
|
|
132 | # undef EV_USE_PORT |
126 | # define EV_USE_PORT 0 |
133 | # define EV_USE_PORT 0 |
|
|
134 | # endif |
|
|
135 | |
|
|
136 | # if HAVE_INOTIFY_INIT && HAVE_SYS_INOTIFY_H |
|
|
137 | # ifndef EV_USE_INOTIFY |
|
|
138 | # define EV_USE_INOTIFY EV_FEATURE_OS |
127 | # endif |
139 | # endif |
128 | # endif |
|
|
129 | |
|
|
130 | # ifndef EV_USE_INOTIFY |
|
|
131 | # if HAVE_INOTIFY_INIT && HAVE_SYS_INOTIFY_H |
|
|
132 | # define EV_USE_INOTIFY 1 |
|
|
133 | # else |
140 | # else |
|
|
141 | # undef EV_USE_INOTIFY |
134 | # define EV_USE_INOTIFY 0 |
142 | # define EV_USE_INOTIFY 0 |
|
|
143 | # endif |
|
|
144 | |
|
|
145 | # if HAVE_SIGNALFD && HAVE_SYS_SIGNALFD_H |
|
|
146 | # ifndef EV_USE_SIGNALFD |
|
|
147 | # define EV_USE_SIGNALFD EV_FEATURE_OS |
135 | # endif |
148 | # endif |
136 | # endif |
|
|
137 | |
|
|
138 | # ifndef EV_USE_SIGNALFD |
|
|
139 | # if HAVE_SIGNALFD && HAVE_SYS_SIGNALFD_H |
|
|
140 | # define EV_USE_SIGNALFD 1 |
|
|
141 | # else |
149 | # else |
|
|
150 | # undef EV_USE_SIGNALFD |
142 | # define EV_USE_SIGNALFD 0 |
151 | # define EV_USE_SIGNALFD 0 |
|
|
152 | # endif |
|
|
153 | |
|
|
154 | # if HAVE_EVENTFD |
|
|
155 | # ifndef EV_USE_EVENTFD |
|
|
156 | # define EV_USE_EVENTFD EV_FEATURE_OS |
143 | # endif |
157 | # endif |
144 | # endif |
|
|
145 | |
|
|
146 | # ifndef EV_USE_EVENTFD |
|
|
147 | # if HAVE_EVENTFD |
|
|
148 | # define EV_USE_EVENTFD 1 |
|
|
149 | # else |
158 | # else |
|
|
159 | # undef EV_USE_EVENTFD |
150 | # define EV_USE_EVENTFD 0 |
160 | # define EV_USE_EVENTFD 0 |
151 | # endif |
|
|
152 | # endif |
161 | # endif |
153 | |
162 | |
154 | #endif |
163 | #endif |
155 | |
164 | |
156 | #include <math.h> |
165 | #include <math.h> |
… | |
… | |
207 | #elif defined (MAXSIG) |
216 | #elif defined (MAXSIG) |
208 | # define EV_NSIG (MAXSIG+1) |
217 | # define EV_NSIG (MAXSIG+1) |
209 | #elif defined (MAX_SIG) |
218 | #elif defined (MAX_SIG) |
210 | # define EV_NSIG (MAX_SIG+1) |
219 | # define EV_NSIG (MAX_SIG+1) |
211 | #elif defined (SIGARRAYSIZE) |
220 | #elif defined (SIGARRAYSIZE) |
212 | # define EV_NSIG SIGARRAYSIZE /* Assume ary[SIGARRAYSIZE] */ |
221 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
213 | #elif defined (_sys_nsig) |
222 | #elif defined (_sys_nsig) |
214 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
223 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
215 | #else |
224 | #else |
216 | # error "unable to find value for NSIG, please report" |
225 | # error "unable to find value for NSIG, please report" |
217 | /* to make it compile regardless, just remove the above line */ |
226 | /* to make it compile regardless, just remove the above line, */ |
|
|
227 | /* but consider reporting it, too! :) */ |
218 | # define EV_NSIG 65 |
228 | # define EV_NSIG 65 |
219 | #endif |
229 | #endif |
220 | |
230 | |
221 | #ifndef EV_USE_CLOCK_SYSCALL |
231 | #ifndef EV_USE_CLOCK_SYSCALL |
222 | # if __linux && __GLIBC__ >= 2 |
232 | # if __linux && __GLIBC__ >= 2 |
223 | # define EV_USE_CLOCK_SYSCALL 1 |
233 | # define EV_USE_CLOCK_SYSCALL EV_FEATURE_OS |
224 | # else |
234 | # else |
225 | # define EV_USE_CLOCK_SYSCALL 0 |
235 | # define EV_USE_CLOCK_SYSCALL 0 |
226 | # endif |
236 | # endif |
227 | #endif |
237 | #endif |
228 | |
238 | |
229 | #ifndef EV_USE_MONOTONIC |
239 | #ifndef EV_USE_MONOTONIC |
230 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
240 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
231 | # define EV_USE_MONOTONIC 1 |
241 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
232 | # else |
242 | # else |
233 | # define EV_USE_MONOTONIC 0 |
243 | # define EV_USE_MONOTONIC 0 |
234 | # endif |
244 | # endif |
235 | #endif |
245 | #endif |
236 | |
246 | |
… | |
… | |
238 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
248 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
239 | #endif |
249 | #endif |
240 | |
250 | |
241 | #ifndef EV_USE_NANOSLEEP |
251 | #ifndef EV_USE_NANOSLEEP |
242 | # if _POSIX_C_SOURCE >= 199309L |
252 | # if _POSIX_C_SOURCE >= 199309L |
243 | # define EV_USE_NANOSLEEP 1 |
253 | # define EV_USE_NANOSLEEP EV_FEATURE_OS |
244 | # else |
254 | # else |
245 | # define EV_USE_NANOSLEEP 0 |
255 | # define EV_USE_NANOSLEEP 0 |
246 | # endif |
256 | # endif |
247 | #endif |
257 | #endif |
248 | |
258 | |
249 | #ifndef EV_USE_SELECT |
259 | #ifndef EV_USE_SELECT |
250 | # define EV_USE_SELECT 1 |
260 | # define EV_USE_SELECT EV_FEATURE_BACKENDS |
251 | #endif |
261 | #endif |
252 | |
262 | |
253 | #ifndef EV_USE_POLL |
263 | #ifndef EV_USE_POLL |
254 | # ifdef _WIN32 |
264 | # ifdef _WIN32 |
255 | # define EV_USE_POLL 0 |
265 | # define EV_USE_POLL 0 |
256 | # else |
266 | # else |
257 | # define EV_USE_POLL 1 |
267 | # define EV_USE_POLL EV_FEATURE_BACKENDS |
258 | # endif |
268 | # endif |
259 | #endif |
269 | #endif |
260 | |
270 | |
261 | #ifndef EV_USE_EPOLL |
271 | #ifndef EV_USE_EPOLL |
262 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
272 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
263 | # define EV_USE_EPOLL 1 |
273 | # define EV_USE_EPOLL EV_FEATURE_BACKENDS |
264 | # else |
274 | # else |
265 | # define EV_USE_EPOLL 0 |
275 | # define EV_USE_EPOLL 0 |
266 | # endif |
276 | # endif |
267 | #endif |
277 | #endif |
268 | |
278 | |
… | |
… | |
274 | # define EV_USE_PORT 0 |
284 | # define EV_USE_PORT 0 |
275 | #endif |
285 | #endif |
276 | |
286 | |
277 | #ifndef EV_USE_INOTIFY |
287 | #ifndef EV_USE_INOTIFY |
278 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
288 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
279 | # define EV_USE_INOTIFY 1 |
289 | # define EV_USE_INOTIFY EV_FEATURE_OS |
280 | # else |
290 | # else |
281 | # define EV_USE_INOTIFY 0 |
291 | # define EV_USE_INOTIFY 0 |
282 | # endif |
292 | # endif |
283 | #endif |
293 | #endif |
284 | |
294 | |
285 | #ifndef EV_PID_HASHSIZE |
295 | #ifndef EV_PID_HASHSIZE |
286 | # if EV_MINIMAL |
296 | # 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 |
297 | #endif |
292 | |
298 | |
293 | #ifndef EV_INOTIFY_HASHSIZE |
299 | #ifndef EV_INOTIFY_HASHSIZE |
294 | # if EV_MINIMAL |
300 | # 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 |
301 | #endif |
300 | |
302 | |
301 | #ifndef EV_USE_EVENTFD |
303 | #ifndef EV_USE_EVENTFD |
302 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
304 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
303 | # define EV_USE_EVENTFD 1 |
305 | # define EV_USE_EVENTFD EV_FEATURE_OS |
304 | # else |
306 | # else |
305 | # define EV_USE_EVENTFD 0 |
307 | # define EV_USE_EVENTFD 0 |
306 | # endif |
308 | # endif |
307 | #endif |
309 | #endif |
308 | |
310 | |
309 | #ifndef EV_USE_SIGNALFD |
311 | #ifndef EV_USE_SIGNALFD |
310 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
312 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
311 | # define EV_USE_SIGNALFD 1 |
313 | # define EV_USE_SIGNALFD EV_FEATURE_OS |
312 | # else |
314 | # else |
313 | # define EV_USE_SIGNALFD 0 |
315 | # define EV_USE_SIGNALFD 0 |
314 | # endif |
316 | # endif |
315 | #endif |
317 | #endif |
316 | |
318 | |
… | |
… | |
319 | # define EV_USE_4HEAP 1 |
321 | # define EV_USE_4HEAP 1 |
320 | # define EV_HEAP_CACHE_AT 1 |
322 | # define EV_HEAP_CACHE_AT 1 |
321 | #endif |
323 | #endif |
322 | |
324 | |
323 | #ifndef EV_VERIFY |
325 | #ifndef EV_VERIFY |
324 | # define EV_VERIFY !EV_MINIMAL |
326 | # define EV_VERIFY (EV_FEATURE_API ? 1 : 0) |
325 | #endif |
327 | #endif |
326 | |
328 | |
327 | #ifndef EV_USE_4HEAP |
329 | #ifndef EV_USE_4HEAP |
328 | # define EV_USE_4HEAP !EV_MINIMAL |
330 | # define EV_USE_4HEAP EV_FEATURE_DATA |
329 | #endif |
331 | #endif |
330 | |
332 | |
331 | #ifndef EV_HEAP_CACHE_AT |
333 | #ifndef EV_HEAP_CACHE_AT |
332 | # define EV_HEAP_CACHE_AT !EV_MINIMAL |
334 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
333 | #endif |
335 | #endif |
334 | |
336 | |
335 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
337 | /* 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. */ |
338 | /* which makes programs even slower. might work on other unices, too. */ |
337 | #if EV_USE_CLOCK_SYSCALL |
339 | #if EV_USE_CLOCK_SYSCALL |
… | |
… | |
442 | |
444 | |
443 | |
445 | |
444 | /**/ |
446 | /**/ |
445 | |
447 | |
446 | #if EV_VERIFY >= 3 |
448 | #if EV_VERIFY >= 3 |
447 | # define EV_FREQUENT_CHECK ev_loop_verify (EV_A) |
449 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
448 | #else |
450 | #else |
449 | # define EV_FREQUENT_CHECK do { } while (0) |
451 | # define EV_FREQUENT_CHECK do { } while (0) |
450 | #endif |
452 | #endif |
451 | |
453 | |
452 | /* |
454 | /* |
… | |
… | |
475 | |
477 | |
476 | #define expect_false(expr) expect ((expr) != 0, 0) |
478 | #define expect_false(expr) expect ((expr) != 0, 0) |
477 | #define expect_true(expr) expect ((expr) != 0, 1) |
479 | #define expect_true(expr) expect ((expr) != 0, 1) |
478 | #define inline_size static inline |
480 | #define inline_size static inline |
479 | |
481 | |
480 | #if EV_MINIMAL |
482 | #if EV_FEATURE_CODE |
|
|
483 | # define inline_speed static inline |
|
|
484 | #else |
481 | # define inline_speed static noinline |
485 | # define inline_speed static noinline |
482 | #else |
|
|
483 | # define inline_speed static inline |
|
|
484 | #endif |
486 | #endif |
485 | |
487 | |
486 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
488 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
487 | |
489 | |
488 | #if EV_MINPRI == EV_MAXPRI |
490 | #if EV_MINPRI == EV_MAXPRI |
… | |
… | |
695 | |
697 | |
696 | static int ev_default_loop_ptr; |
698 | static int ev_default_loop_ptr; |
697 | |
699 | |
698 | #endif |
700 | #endif |
699 | |
701 | |
700 | #if EV_MINIMAL < 2 |
702 | #if EV_FEATURE_API |
701 | # define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) |
703 | # define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) |
702 | # define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A) |
704 | # define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A) |
703 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
705 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
704 | #else |
706 | #else |
705 | # define EV_RELEASE_CB (void)0 |
707 | # define EV_RELEASE_CB (void)0 |
… | |
… | |
890 | } |
892 | } |
891 | |
893 | |
892 | /*****************************************************************************/ |
894 | /*****************************************************************************/ |
893 | |
895 | |
894 | inline_speed void |
896 | inline_speed void |
895 | fd_event_nc (EV_P_ int fd, int revents) |
897 | fd_event_nocheck (EV_P_ int fd, int revents) |
896 | { |
898 | { |
897 | ANFD *anfd = anfds + fd; |
899 | ANFD *anfd = anfds + fd; |
898 | ev_io *w; |
900 | ev_io *w; |
899 | |
901 | |
900 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
902 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
… | |
… | |
912 | fd_event (EV_P_ int fd, int revents) |
914 | fd_event (EV_P_ int fd, int revents) |
913 | { |
915 | { |
914 | ANFD *anfd = anfds + fd; |
916 | ANFD *anfd = anfds + fd; |
915 | |
917 | |
916 | if (expect_true (!anfd->reify)) |
918 | if (expect_true (!anfd->reify)) |
917 | fd_event_nc (EV_A_ fd, revents); |
919 | fd_event_nocheck (EV_A_ fd, revents); |
918 | } |
920 | } |
919 | |
921 | |
920 | void |
922 | void |
921 | ev_feed_fd_event (EV_P_ int fd, int revents) |
923 | ev_feed_fd_event (EV_P_ int fd, int revents) |
922 | { |
924 | { |
923 | if (fd >= 0 && fd < anfdmax) |
925 | if (fd >= 0 && fd < anfdmax) |
924 | fd_event_nc (EV_A_ fd, revents); |
926 | fd_event_nocheck (EV_A_ fd, revents); |
925 | } |
927 | } |
926 | |
928 | |
927 | /* make sure the external fd watch events are in-sync */ |
929 | /* make sure the external fd watch events are in-sync */ |
928 | /* with the kernel/libev internal state */ |
930 | /* with the kernel/libev internal state */ |
929 | inline_size void |
931 | inline_size void |
… | |
… | |
992 | ev_io_stop (EV_A_ w); |
994 | ev_io_stop (EV_A_ w); |
993 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
995 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
994 | } |
996 | } |
995 | } |
997 | } |
996 | |
998 | |
997 | /* check whether the given fd is atcually valid, for error recovery */ |
999 | /* check whether the given fd is actually valid, for error recovery */ |
998 | inline_size int |
1000 | inline_size int |
999 | fd_valid (int fd) |
1001 | fd_valid (int fd) |
1000 | { |
1002 | { |
1001 | #ifdef _WIN32 |
1003 | #ifdef _WIN32 |
1002 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
1004 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
… | |
… | |
1042 | { |
1044 | { |
1043 | anfds [fd].events = 0; |
1045 | anfds [fd].events = 0; |
1044 | anfds [fd].emask = 0; |
1046 | anfds [fd].emask = 0; |
1045 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1047 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1046 | } |
1048 | } |
|
|
1049 | } |
|
|
1050 | |
|
|
1051 | /* used to prepare libev internal fd's */ |
|
|
1052 | /* this is not fork-safe */ |
|
|
1053 | inline_speed void |
|
|
1054 | fd_intern (int fd) |
|
|
1055 | { |
|
|
1056 | #ifdef _WIN32 |
|
|
1057 | unsigned long arg = 1; |
|
|
1058 | ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg); |
|
|
1059 | #else |
|
|
1060 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1061 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1062 | #endif |
1047 | } |
1063 | } |
1048 | |
1064 | |
1049 | /*****************************************************************************/ |
1065 | /*****************************************************************************/ |
1050 | |
1066 | |
1051 | /* |
1067 | /* |
… | |
… | |
1205 | |
1221 | |
1206 | static ANSIG signals [EV_NSIG - 1]; |
1222 | static ANSIG signals [EV_NSIG - 1]; |
1207 | |
1223 | |
1208 | /*****************************************************************************/ |
1224 | /*****************************************************************************/ |
1209 | |
1225 | |
1210 | /* used to prepare libev internal fd's */ |
1226 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1211 | /* this is not fork-safe */ |
|
|
1212 | inline_speed void |
|
|
1213 | fd_intern (int fd) |
|
|
1214 | { |
|
|
1215 | #ifdef _WIN32 |
|
|
1216 | unsigned long arg = 1; |
|
|
1217 | ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg); |
|
|
1218 | #else |
|
|
1219 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1220 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1221 | #endif |
|
|
1222 | } |
|
|
1223 | |
1227 | |
1224 | static void noinline |
1228 | static void noinline |
1225 | evpipe_init (EV_P) |
1229 | evpipe_init (EV_P) |
1226 | { |
1230 | { |
1227 | if (!ev_is_active (&pipe_w)) |
1231 | if (!ev_is_active (&pipe_w)) |
1228 | { |
1232 | { |
1229 | #if EV_USE_EVENTFD |
1233 | # if EV_USE_EVENTFD |
1230 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1234 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1231 | if (evfd < 0 && errno == EINVAL) |
1235 | if (evfd < 0 && errno == EINVAL) |
1232 | evfd = eventfd (0, 0); |
1236 | evfd = eventfd (0, 0); |
1233 | |
1237 | |
1234 | if (evfd >= 0) |
1238 | if (evfd >= 0) |
… | |
… | |
1236 | evpipe [0] = -1; |
1240 | evpipe [0] = -1; |
1237 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1241 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1238 | ev_io_set (&pipe_w, evfd, EV_READ); |
1242 | ev_io_set (&pipe_w, evfd, EV_READ); |
1239 | } |
1243 | } |
1240 | else |
1244 | else |
1241 | #endif |
1245 | # endif |
1242 | { |
1246 | { |
1243 | while (pipe (evpipe)) |
1247 | while (pipe (evpipe)) |
1244 | ev_syserr ("(libev) error creating signal/async pipe"); |
1248 | ev_syserr ("(libev) error creating signal/async pipe"); |
1245 | |
1249 | |
1246 | fd_intern (evpipe [0]); |
1250 | fd_intern (evpipe [0]); |
… | |
… | |
1257 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1261 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1258 | { |
1262 | { |
1259 | if (!*flag) |
1263 | if (!*flag) |
1260 | { |
1264 | { |
1261 | int old_errno = errno; /* save errno because write might clobber it */ |
1265 | int old_errno = errno; /* save errno because write might clobber it */ |
|
|
1266 | char dummy; |
1262 | |
1267 | |
1263 | *flag = 1; |
1268 | *flag = 1; |
1264 | |
1269 | |
1265 | #if EV_USE_EVENTFD |
1270 | #if EV_USE_EVENTFD |
1266 | if (evfd >= 0) |
1271 | if (evfd >= 0) |
… | |
… | |
1268 | uint64_t counter = 1; |
1273 | uint64_t counter = 1; |
1269 | write (evfd, &counter, sizeof (uint64_t)); |
1274 | write (evfd, &counter, sizeof (uint64_t)); |
1270 | } |
1275 | } |
1271 | else |
1276 | else |
1272 | #endif |
1277 | #endif |
1273 | write (evpipe [1], &old_errno, 1); |
1278 | write (evpipe [1], &dummy, 1); |
1274 | |
1279 | |
1275 | errno = old_errno; |
1280 | errno = old_errno; |
1276 | } |
1281 | } |
1277 | } |
1282 | } |
1278 | |
1283 | |
… | |
… | |
1379 | break; |
1384 | break; |
1380 | } |
1385 | } |
1381 | } |
1386 | } |
1382 | #endif |
1387 | #endif |
1383 | |
1388 | |
|
|
1389 | #endif |
|
|
1390 | |
1384 | /*****************************************************************************/ |
1391 | /*****************************************************************************/ |
1385 | |
1392 | |
|
|
1393 | #if EV_CHILD_ENABLE |
1386 | static WL childs [EV_PID_HASHSIZE]; |
1394 | static WL childs [EV_PID_HASHSIZE]; |
1387 | |
|
|
1388 | #ifndef _WIN32 |
|
|
1389 | |
1395 | |
1390 | static ev_signal childev; |
1396 | static ev_signal childev; |
1391 | |
1397 | |
1392 | #ifndef WIFCONTINUED |
1398 | #ifndef WIFCONTINUED |
1393 | # define WIFCONTINUED(status) 0 |
1399 | # define WIFCONTINUED(status) 0 |
… | |
… | |
1398 | child_reap (EV_P_ int chain, int pid, int status) |
1404 | child_reap (EV_P_ int chain, int pid, int status) |
1399 | { |
1405 | { |
1400 | ev_child *w; |
1406 | ev_child *w; |
1401 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1407 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1402 | |
1408 | |
1403 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1409 | for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next) |
1404 | { |
1410 | { |
1405 | if ((w->pid == pid || !w->pid) |
1411 | if ((w->pid == pid || !w->pid) |
1406 | && (!traced || (w->flags & 1))) |
1412 | && (!traced || (w->flags & 1))) |
1407 | { |
1413 | { |
1408 | ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ |
1414 | ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ |
… | |
… | |
1433 | /* make sure we are called again until all children have been reaped */ |
1439 | /* make sure we are called again until all children have been reaped */ |
1434 | /* we need to do it this way so that the callback gets called before we continue */ |
1440 | /* we need to do it this way so that the callback gets called before we continue */ |
1435 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1441 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1436 | |
1442 | |
1437 | child_reap (EV_A_ pid, pid, status); |
1443 | child_reap (EV_A_ pid, pid, status); |
1438 | if (EV_PID_HASHSIZE > 1) |
1444 | if ((EV_PID_HASHSIZE) > 1) |
1439 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
1445 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
1440 | } |
1446 | } |
1441 | |
1447 | |
1442 | #endif |
1448 | #endif |
1443 | |
1449 | |
… | |
… | |
1510 | #ifdef __APPLE__ |
1516 | #ifdef __APPLE__ |
1511 | /* only select works correctly on that "unix-certified" platform */ |
1517 | /* only select works correctly on that "unix-certified" platform */ |
1512 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1518 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
1513 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
1519 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
1514 | #endif |
1520 | #endif |
|
|
1521 | #ifdef __FreeBSD__ |
|
|
1522 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
|
|
1523 | #endif |
1515 | |
1524 | |
1516 | return flags; |
1525 | return flags; |
1517 | } |
1526 | } |
1518 | |
1527 | |
1519 | unsigned int |
1528 | unsigned int |
… | |
… | |
1532 | ev_backend (EV_P) |
1541 | ev_backend (EV_P) |
1533 | { |
1542 | { |
1534 | return backend; |
1543 | return backend; |
1535 | } |
1544 | } |
1536 | |
1545 | |
1537 | #if EV_MINIMAL < 2 |
1546 | #if EV_FEATURE_API |
1538 | unsigned int |
1547 | unsigned int |
1539 | ev_loop_count (EV_P) |
1548 | ev_iteration (EV_P) |
1540 | { |
1549 | { |
1541 | return loop_count; |
1550 | return loop_count; |
1542 | } |
1551 | } |
1543 | |
1552 | |
1544 | unsigned int |
1553 | unsigned int |
1545 | ev_loop_depth (EV_P) |
1554 | ev_depth (EV_P) |
1546 | { |
1555 | { |
1547 | return loop_depth; |
1556 | return loop_depth; |
1548 | } |
1557 | } |
1549 | |
1558 | |
1550 | void |
1559 | void |
… | |
… | |
1622 | |
1631 | |
1623 | ev_rt_now = ev_time (); |
1632 | ev_rt_now = ev_time (); |
1624 | mn_now = get_clock (); |
1633 | mn_now = get_clock (); |
1625 | now_floor = mn_now; |
1634 | now_floor = mn_now; |
1626 | rtmn_diff = ev_rt_now - mn_now; |
1635 | rtmn_diff = ev_rt_now - mn_now; |
1627 | #if EV_MINIMAL < 2 |
1636 | #if EV_FEATURE_API |
1628 | invoke_cb = ev_invoke_pending; |
1637 | invoke_cb = ev_invoke_pending; |
1629 | #endif |
1638 | #endif |
1630 | |
1639 | |
1631 | io_blocktime = 0.; |
1640 | io_blocktime = 0.; |
1632 | timeout_blocktime = 0.; |
1641 | timeout_blocktime = 0.; |
… | |
… | |
1662 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1671 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1663 | #endif |
1672 | #endif |
1664 | |
1673 | |
1665 | ev_prepare_init (&pending_w, pendingcb); |
1674 | ev_prepare_init (&pending_w, pendingcb); |
1666 | |
1675 | |
|
|
1676 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1667 | ev_init (&pipe_w, pipecb); |
1677 | ev_init (&pipe_w, pipecb); |
1668 | ev_set_priority (&pipe_w, EV_MAXPRI); |
1678 | ev_set_priority (&pipe_w, EV_MAXPRI); |
|
|
1679 | #endif |
1669 | } |
1680 | } |
1670 | } |
1681 | } |
1671 | |
1682 | |
1672 | /* free up a loop structure */ |
1683 | /* free up a loop structure */ |
1673 | static void noinline |
1684 | static void noinline |
… | |
… | |
1791 | { |
1802 | { |
1792 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1803 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1793 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1804 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1794 | } |
1805 | } |
1795 | |
1806 | |
|
|
1807 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1796 | evpipe_init (EV_A); |
1808 | evpipe_init (EV_A); |
1797 | /* now iterate over everything, in case we missed something */ |
1809 | /* now iterate over everything, in case we missed something */ |
1798 | pipecb (EV_A_ &pipe_w, EV_READ); |
1810 | pipecb (EV_A_ &pipe_w, EV_READ); |
|
|
1811 | #endif |
1799 | } |
1812 | } |
1800 | |
1813 | |
1801 | postfork = 0; |
1814 | postfork = 0; |
1802 | } |
1815 | } |
1803 | |
1816 | |
… | |
… | |
1865 | verify_watcher (EV_A_ ws [cnt]); |
1878 | verify_watcher (EV_A_ ws [cnt]); |
1866 | } |
1879 | } |
1867 | } |
1880 | } |
1868 | #endif |
1881 | #endif |
1869 | |
1882 | |
1870 | #if EV_MINIMAL < 2 |
1883 | #if EV_FEATURE_API |
1871 | void |
1884 | void |
1872 | ev_loop_verify (EV_P) |
1885 | ev_verify (EV_P) |
1873 | { |
1886 | { |
1874 | #if EV_VERIFY |
1887 | #if EV_VERIFY |
1875 | int i; |
1888 | int i; |
1876 | WL w; |
1889 | WL w; |
1877 | |
1890 | |
… | |
… | |
1916 | #if EV_ASYNC_ENABLE |
1929 | #if EV_ASYNC_ENABLE |
1917 | assert (asyncmax >= asynccnt); |
1930 | assert (asyncmax >= asynccnt); |
1918 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1931 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1919 | #endif |
1932 | #endif |
1920 | |
1933 | |
|
|
1934 | #if EV_PREPARE_ENABLE |
1921 | assert (preparemax >= preparecnt); |
1935 | assert (preparemax >= preparecnt); |
1922 | array_verify (EV_A_ (W *)prepares, preparecnt); |
1936 | array_verify (EV_A_ (W *)prepares, preparecnt); |
|
|
1937 | #endif |
1923 | |
1938 | |
|
|
1939 | #if EV_CHECK_ENABLE |
1924 | assert (checkmax >= checkcnt); |
1940 | assert (checkmax >= checkcnt); |
1925 | array_verify (EV_A_ (W *)checks, checkcnt); |
1941 | array_verify (EV_A_ (W *)checks, checkcnt); |
|
|
1942 | #endif |
1926 | |
1943 | |
1927 | # if 0 |
1944 | # if 0 |
|
|
1945 | #if EV_CHILD_ENABLE |
1928 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1946 | for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next) |
1929 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
1947 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
|
|
1948 | #endif |
1930 | # endif |
1949 | # endif |
1931 | #endif |
1950 | #endif |
1932 | } |
1951 | } |
1933 | #endif |
1952 | #endif |
1934 | |
1953 | |
… | |
… | |
1950 | |
1969 | |
1951 | loop_init (EV_A_ flags); |
1970 | loop_init (EV_A_ flags); |
1952 | |
1971 | |
1953 | if (ev_backend (EV_A)) |
1972 | if (ev_backend (EV_A)) |
1954 | { |
1973 | { |
1955 | #ifndef _WIN32 |
1974 | #if EV_CHILD_ENABLE |
1956 | ev_signal_init (&childev, childcb, SIGCHLD); |
1975 | ev_signal_init (&childev, childcb, SIGCHLD); |
1957 | ev_set_priority (&childev, EV_MAXPRI); |
1976 | ev_set_priority (&childev, EV_MAXPRI); |
1958 | ev_signal_start (EV_A_ &childev); |
1977 | ev_signal_start (EV_A_ &childev); |
1959 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1978 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1960 | #endif |
1979 | #endif |
… | |
… | |
1973 | EV_P = ev_default_loop_ptr; |
1992 | EV_P = ev_default_loop_ptr; |
1974 | #endif |
1993 | #endif |
1975 | |
1994 | |
1976 | ev_default_loop_ptr = 0; |
1995 | ev_default_loop_ptr = 0; |
1977 | |
1996 | |
1978 | #ifndef _WIN32 |
1997 | #if EV_CHILD_ENABLE |
1979 | ev_ref (EV_A); /* child watcher */ |
1998 | ev_ref (EV_A); /* child watcher */ |
1980 | ev_signal_stop (EV_A_ &childev); |
1999 | ev_signal_stop (EV_A_ &childev); |
1981 | #endif |
2000 | #endif |
1982 | |
2001 | |
1983 | loop_destroy (EV_A); |
2002 | loop_destroy (EV_A); |
… | |
… | |
2089 | EV_FREQUENT_CHECK; |
2108 | EV_FREQUENT_CHECK; |
2090 | feed_reverse (EV_A_ (W)w); |
2109 | feed_reverse (EV_A_ (W)w); |
2091 | } |
2110 | } |
2092 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2111 | while (timercnt && ANHE_at (timers [HEAP0]) < mn_now); |
2093 | |
2112 | |
2094 | feed_reverse_done (EV_A_ EV_TIMEOUT); |
2113 | feed_reverse_done (EV_A_ EV_TIMER); |
2095 | } |
2114 | } |
2096 | } |
2115 | } |
2097 | |
2116 | |
2098 | #if EV_PERIODIC_ENABLE |
2117 | #if EV_PERIODIC_ENABLE |
2099 | /* make periodics pending */ |
2118 | /* make periodics pending */ |
… | |
… | |
2260 | } |
2279 | } |
2261 | |
2280 | |
2262 | void |
2281 | void |
2263 | ev_loop (EV_P_ int flags) |
2282 | ev_loop (EV_P_ int flags) |
2264 | { |
2283 | { |
2265 | #if EV_MINIMAL < 2 |
2284 | #if EV_FEATURE_API |
2266 | ++loop_depth; |
2285 | ++loop_depth; |
2267 | #endif |
2286 | #endif |
2268 | |
2287 | |
2269 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2288 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2270 | |
2289 | |
… | |
… | |
2273 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2292 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
2274 | |
2293 | |
2275 | do |
2294 | do |
2276 | { |
2295 | { |
2277 | #if EV_VERIFY >= 2 |
2296 | #if EV_VERIFY >= 2 |
2278 | ev_loop_verify (EV_A); |
2297 | ev_verify (EV_A); |
2279 | #endif |
2298 | #endif |
2280 | |
2299 | |
2281 | #ifndef _WIN32 |
2300 | #ifndef _WIN32 |
2282 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2301 | if (expect_false (curpid)) /* penalise the forking check even more */ |
2283 | if (expect_false (getpid () != curpid)) |
2302 | if (expect_false (getpid () != curpid)) |
… | |
… | |
2295 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2314 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2296 | EV_INVOKE_PENDING; |
2315 | EV_INVOKE_PENDING; |
2297 | } |
2316 | } |
2298 | #endif |
2317 | #endif |
2299 | |
2318 | |
|
|
2319 | #if EV_PREPARE_ENABLE |
2300 | /* queue prepare watchers (and execute them) */ |
2320 | /* queue prepare watchers (and execute them) */ |
2301 | if (expect_false (preparecnt)) |
2321 | if (expect_false (preparecnt)) |
2302 | { |
2322 | { |
2303 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2323 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2304 | EV_INVOKE_PENDING; |
2324 | EV_INVOKE_PENDING; |
2305 | } |
2325 | } |
|
|
2326 | #endif |
2306 | |
2327 | |
2307 | if (expect_false (loop_done)) |
2328 | if (expect_false (loop_done)) |
2308 | break; |
2329 | break; |
2309 | |
2330 | |
2310 | /* we might have forked, so reify kernel state if necessary */ |
2331 | /* we might have forked, so reify kernel state if necessary */ |
… | |
… | |
2361 | waittime -= sleeptime; |
2382 | waittime -= sleeptime; |
2362 | } |
2383 | } |
2363 | } |
2384 | } |
2364 | } |
2385 | } |
2365 | |
2386 | |
2366 | #if EV_MINIMAL < 2 |
2387 | #if EV_FEATURE_API |
2367 | ++loop_count; |
2388 | ++loop_count; |
2368 | #endif |
2389 | #endif |
2369 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2390 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2370 | backend_poll (EV_A_ waittime); |
2391 | backend_poll (EV_A_ waittime); |
2371 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
2392 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
… | |
… | |
2383 | #if EV_IDLE_ENABLE |
2404 | #if EV_IDLE_ENABLE |
2384 | /* queue idle watchers unless other events are pending */ |
2405 | /* queue idle watchers unless other events are pending */ |
2385 | idle_reify (EV_A); |
2406 | idle_reify (EV_A); |
2386 | #endif |
2407 | #endif |
2387 | |
2408 | |
|
|
2409 | #if EV_CHECK_ENABLE |
2388 | /* queue check watchers, to be executed first */ |
2410 | /* queue check watchers, to be executed first */ |
2389 | if (expect_false (checkcnt)) |
2411 | if (expect_false (checkcnt)) |
2390 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
2412 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
|
|
2413 | #endif |
2391 | |
2414 | |
2392 | EV_INVOKE_PENDING; |
2415 | EV_INVOKE_PENDING; |
2393 | } |
2416 | } |
2394 | while (expect_true ( |
2417 | while (expect_true ( |
2395 | activecnt |
2418 | activecnt |
… | |
… | |
2398 | )); |
2421 | )); |
2399 | |
2422 | |
2400 | if (loop_done == EVUNLOOP_ONE) |
2423 | if (loop_done == EVUNLOOP_ONE) |
2401 | loop_done = EVUNLOOP_CANCEL; |
2424 | loop_done = EVUNLOOP_CANCEL; |
2402 | |
2425 | |
2403 | #if EV_MINIMAL < 2 |
2426 | #if EV_FEATURE_API |
2404 | --loop_depth; |
2427 | --loop_depth; |
2405 | #endif |
2428 | #endif |
2406 | } |
2429 | } |
2407 | |
2430 | |
2408 | void |
2431 | void |
… | |
… | |
2725 | |
2748 | |
2726 | #ifndef SA_RESTART |
2749 | #ifndef SA_RESTART |
2727 | # define SA_RESTART 0 |
2750 | # define SA_RESTART 0 |
2728 | #endif |
2751 | #endif |
2729 | |
2752 | |
|
|
2753 | #if EV_SIGNAL_ENABLE |
|
|
2754 | |
2730 | void noinline |
2755 | void noinline |
2731 | ev_signal_start (EV_P_ ev_signal *w) |
2756 | ev_signal_start (EV_P_ ev_signal *w) |
2732 | { |
2757 | { |
2733 | if (expect_false (ev_is_active (w))) |
2758 | if (expect_false (ev_is_active (w))) |
2734 | return; |
2759 | return; |
… | |
… | |
2840 | } |
2865 | } |
2841 | |
2866 | |
2842 | EV_FREQUENT_CHECK; |
2867 | EV_FREQUENT_CHECK; |
2843 | } |
2868 | } |
2844 | |
2869 | |
|
|
2870 | #endif |
|
|
2871 | |
|
|
2872 | #if EV_CHILD_ENABLE |
|
|
2873 | |
2845 | void |
2874 | void |
2846 | ev_child_start (EV_P_ ev_child *w) |
2875 | ev_child_start (EV_P_ ev_child *w) |
2847 | { |
2876 | { |
2848 | #if EV_MULTIPLICITY |
2877 | #if EV_MULTIPLICITY |
2849 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
2878 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
… | |
… | |
2852 | return; |
2881 | return; |
2853 | |
2882 | |
2854 | EV_FREQUENT_CHECK; |
2883 | EV_FREQUENT_CHECK; |
2855 | |
2884 | |
2856 | ev_start (EV_A_ (W)w, 1); |
2885 | ev_start (EV_A_ (W)w, 1); |
2857 | wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2886 | wlist_add (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2858 | |
2887 | |
2859 | EV_FREQUENT_CHECK; |
2888 | EV_FREQUENT_CHECK; |
2860 | } |
2889 | } |
2861 | |
2890 | |
2862 | void |
2891 | void |
… | |
… | |
2866 | if (expect_false (!ev_is_active (w))) |
2895 | if (expect_false (!ev_is_active (w))) |
2867 | return; |
2896 | return; |
2868 | |
2897 | |
2869 | EV_FREQUENT_CHECK; |
2898 | EV_FREQUENT_CHECK; |
2870 | |
2899 | |
2871 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2900 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2872 | ev_stop (EV_A_ (W)w); |
2901 | ev_stop (EV_A_ (W)w); |
2873 | |
2902 | |
2874 | EV_FREQUENT_CHECK; |
2903 | EV_FREQUENT_CHECK; |
2875 | } |
2904 | } |
|
|
2905 | |
|
|
2906 | #endif |
2876 | |
2907 | |
2877 | #if EV_STAT_ENABLE |
2908 | #if EV_STAT_ENABLE |
2878 | |
2909 | |
2879 | # ifdef _WIN32 |
2910 | # ifdef _WIN32 |
2880 | # undef lstat |
2911 | # undef lstat |
… | |
… | |
2947 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2978 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2948 | } |
2979 | } |
2949 | } |
2980 | } |
2950 | |
2981 | |
2951 | if (w->wd >= 0) |
2982 | if (w->wd >= 0) |
2952 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2983 | wlist_add (&fs_hash [w->wd & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
2953 | |
2984 | |
2954 | /* now re-arm timer, if required */ |
2985 | /* now re-arm timer, if required */ |
2955 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2986 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2956 | ev_timer_again (EV_A_ &w->timer); |
2987 | ev_timer_again (EV_A_ &w->timer); |
2957 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
2988 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
… | |
… | |
2965 | |
2996 | |
2966 | if (wd < 0) |
2997 | if (wd < 0) |
2967 | return; |
2998 | return; |
2968 | |
2999 | |
2969 | w->wd = -2; |
3000 | w->wd = -2; |
2970 | slot = wd & (EV_INOTIFY_HASHSIZE - 1); |
3001 | slot = wd & ((EV_INOTIFY_HASHSIZE) - 1); |
2971 | wlist_del (&fs_hash [slot].head, (WL)w); |
3002 | wlist_del (&fs_hash [slot].head, (WL)w); |
2972 | |
3003 | |
2973 | /* remove this watcher, if others are watching it, they will rearm */ |
3004 | /* remove this watcher, if others are watching it, they will rearm */ |
2974 | inotify_rm_watch (fs_fd, wd); |
3005 | inotify_rm_watch (fs_fd, wd); |
2975 | } |
3006 | } |
… | |
… | |
2977 | static void noinline |
3008 | static void noinline |
2978 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
3009 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
2979 | { |
3010 | { |
2980 | if (slot < 0) |
3011 | if (slot < 0) |
2981 | /* overflow, need to check for all hash slots */ |
3012 | /* overflow, need to check for all hash slots */ |
2982 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3013 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
2983 | infy_wd (EV_A_ slot, wd, ev); |
3014 | infy_wd (EV_A_ slot, wd, ev); |
2984 | else |
3015 | else |
2985 | { |
3016 | { |
2986 | WL w_; |
3017 | WL w_; |
2987 | |
3018 | |
2988 | for (w_ = fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head; w_; ) |
3019 | for (w_ = fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head; w_; ) |
2989 | { |
3020 | { |
2990 | ev_stat *w = (ev_stat *)w_; |
3021 | ev_stat *w = (ev_stat *)w_; |
2991 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
3022 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
2992 | |
3023 | |
2993 | if (w->wd == wd || wd == -1) |
3024 | if (w->wd == wd || wd == -1) |
2994 | { |
3025 | { |
2995 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
3026 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
2996 | { |
3027 | { |
2997 | wlist_del (&fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
3028 | wlist_del (&fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
2998 | w->wd = -1; |
3029 | w->wd = -1; |
2999 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3030 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3000 | } |
3031 | } |
3001 | |
3032 | |
3002 | stat_timer_cb (EV_A_ &w->timer, 0); |
3033 | stat_timer_cb (EV_A_ &w->timer, 0); |
… | |
… | |
3116 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3147 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3117 | ev_io_start (EV_A_ &fs_w); |
3148 | ev_io_start (EV_A_ &fs_w); |
3118 | ev_unref (EV_A); |
3149 | ev_unref (EV_A); |
3119 | } |
3150 | } |
3120 | |
3151 | |
3121 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3152 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
3122 | { |
3153 | { |
3123 | WL w_ = fs_hash [slot].head; |
3154 | WL w_ = fs_hash [slot].head; |
3124 | fs_hash [slot].head = 0; |
3155 | fs_hash [slot].head = 0; |
3125 | |
3156 | |
3126 | while (w_) |
3157 | while (w_) |
… | |
… | |
3301 | |
3332 | |
3302 | EV_FREQUENT_CHECK; |
3333 | EV_FREQUENT_CHECK; |
3303 | } |
3334 | } |
3304 | #endif |
3335 | #endif |
3305 | |
3336 | |
|
|
3337 | #if EV_PREPARE_ENABLE |
3306 | void |
3338 | void |
3307 | ev_prepare_start (EV_P_ ev_prepare *w) |
3339 | ev_prepare_start (EV_P_ ev_prepare *w) |
3308 | { |
3340 | { |
3309 | if (expect_false (ev_is_active (w))) |
3341 | if (expect_false (ev_is_active (w))) |
3310 | return; |
3342 | return; |
… | |
… | |
3336 | |
3368 | |
3337 | ev_stop (EV_A_ (W)w); |
3369 | ev_stop (EV_A_ (W)w); |
3338 | |
3370 | |
3339 | EV_FREQUENT_CHECK; |
3371 | EV_FREQUENT_CHECK; |
3340 | } |
3372 | } |
|
|
3373 | #endif |
3341 | |
3374 | |
|
|
3375 | #if EV_CHECK_ENABLE |
3342 | void |
3376 | void |
3343 | ev_check_start (EV_P_ ev_check *w) |
3377 | ev_check_start (EV_P_ ev_check *w) |
3344 | { |
3378 | { |
3345 | if (expect_false (ev_is_active (w))) |
3379 | if (expect_false (ev_is_active (w))) |
3346 | return; |
3380 | return; |
… | |
… | |
3372 | |
3406 | |
3373 | ev_stop (EV_A_ (W)w); |
3407 | ev_stop (EV_A_ (W)w); |
3374 | |
3408 | |
3375 | EV_FREQUENT_CHECK; |
3409 | EV_FREQUENT_CHECK; |
3376 | } |
3410 | } |
|
|
3411 | #endif |
3377 | |
3412 | |
3378 | #if EV_EMBED_ENABLE |
3413 | #if EV_EMBED_ENABLE |
3379 | void noinline |
3414 | void noinline |
3380 | ev_embed_sweep (EV_P_ ev_embed *w) |
3415 | ev_embed_sweep (EV_P_ ev_embed *w) |
3381 | { |
3416 | { |
… | |
… | |
3613 | { |
3648 | { |
3614 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3649 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
3615 | |
3650 | |
3616 | if (expect_false (!once)) |
3651 | if (expect_false (!once)) |
3617 | { |
3652 | { |
3618 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
3653 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
3619 | return; |
3654 | return; |
3620 | } |
3655 | } |
3621 | |
3656 | |
3622 | once->cb = cb; |
3657 | once->cb = cb; |
3623 | once->arg = arg; |
3658 | once->arg = arg; |
… | |
… | |
3710 | if (types & EV_ASYNC) |
3745 | if (types & EV_ASYNC) |
3711 | for (i = asynccnt; i--; ) |
3746 | for (i = asynccnt; i--; ) |
3712 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3747 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3713 | #endif |
3748 | #endif |
3714 | |
3749 | |
|
|
3750 | #if EV_PREPARE_ENABLE |
3715 | if (types & EV_PREPARE) |
3751 | if (types & EV_PREPARE) |
3716 | for (i = preparecnt; i--; ) |
3752 | for (i = preparecnt; i--; ) |
3717 | #if EV_EMBED_ENABLE |
3753 | # if EV_EMBED_ENABLE |
3718 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3754 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3719 | #endif |
3755 | # endif |
3720 | cb (EV_A_ EV_PREPARE, prepares [i]); |
3756 | cb (EV_A_ EV_PREPARE, prepares [i]); |
|
|
3757 | #endif |
3721 | |
3758 | |
|
|
3759 | #if EV_CHECK_ENABLE |
3722 | if (types & EV_CHECK) |
3760 | if (types & EV_CHECK) |
3723 | for (i = checkcnt; i--; ) |
3761 | for (i = checkcnt; i--; ) |
3724 | cb (EV_A_ EV_CHECK, checks [i]); |
3762 | cb (EV_A_ EV_CHECK, checks [i]); |
|
|
3763 | #endif |
3725 | |
3764 | |
|
|
3765 | #if EV_SIGNAL_ENABLE |
3726 | if (types & EV_SIGNAL) |
3766 | if (types & EV_SIGNAL) |
3727 | for (i = 0; i < EV_NSIG - 1; ++i) |
3767 | for (i = 0; i < EV_NSIG - 1; ++i) |
3728 | for (wl = signals [i].head; wl; ) |
3768 | for (wl = signals [i].head; wl; ) |
3729 | { |
3769 | { |
3730 | wn = wl->next; |
3770 | wn = wl->next; |
3731 | cb (EV_A_ EV_SIGNAL, wl); |
3771 | cb (EV_A_ EV_SIGNAL, wl); |
3732 | wl = wn; |
3772 | wl = wn; |
3733 | } |
3773 | } |
|
|
3774 | #endif |
3734 | |
3775 | |
|
|
3776 | #if EV_CHILD_ENABLE |
3735 | if (types & EV_CHILD) |
3777 | if (types & EV_CHILD) |
3736 | for (i = EV_PID_HASHSIZE; i--; ) |
3778 | for (i = (EV_PID_HASHSIZE); i--; ) |
3737 | for (wl = childs [i]; wl; ) |
3779 | for (wl = childs [i]; wl; ) |
3738 | { |
3780 | { |
3739 | wn = wl->next; |
3781 | wn = wl->next; |
3740 | cb (EV_A_ EV_CHILD, wl); |
3782 | cb (EV_A_ EV_CHILD, wl); |
3741 | wl = wn; |
3783 | wl = wn; |
3742 | } |
3784 | } |
|
|
3785 | #endif |
3743 | /* EV_STAT 0x00001000 /* stat data changed */ |
3786 | /* EV_STAT 0x00001000 /* stat data changed */ |
3744 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3787 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3745 | } |
3788 | } |
3746 | #endif |
3789 | #endif |
3747 | |
3790 | |