… | |
… | |
184 | # define WIN32_LEAN_AND_MEAN |
184 | # define WIN32_LEAN_AND_MEAN |
185 | # include <windows.h> |
185 | # include <windows.h> |
186 | # ifndef EV_SELECT_IS_WINSOCKET |
186 | # ifndef EV_SELECT_IS_WINSOCKET |
187 | # define EV_SELECT_IS_WINSOCKET 1 |
187 | # define EV_SELECT_IS_WINSOCKET 1 |
188 | # endif |
188 | # endif |
|
|
189 | # undef EV_AVOID_STDIO |
189 | #endif |
190 | #endif |
190 | |
191 | |
191 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
192 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
192 | |
193 | |
193 | /* try to deduce the maximum number of signals on this platform */ |
194 | /* try to deduce the maximum number of signals on this platform */ |
… | |
… | |
206 | #elif defined (MAXSIG) |
207 | #elif defined (MAXSIG) |
207 | # define EV_NSIG (MAXSIG+1) |
208 | # define EV_NSIG (MAXSIG+1) |
208 | #elif defined (MAX_SIG) |
209 | #elif defined (MAX_SIG) |
209 | # define EV_NSIG (MAX_SIG+1) |
210 | # define EV_NSIG (MAX_SIG+1) |
210 | #elif defined (SIGARRAYSIZE) |
211 | #elif defined (SIGARRAYSIZE) |
211 | # define EV_NSIG SIGARRAYSIZE /* Assume ary[SIGARRAYSIZE] */ |
212 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
212 | #elif defined (_sys_nsig) |
213 | #elif defined (_sys_nsig) |
213 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
214 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
214 | #else |
215 | #else |
215 | # error "unable to find value for NSIG, please report" |
216 | # error "unable to find value for NSIG, please report" |
216 | /* 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! :) */ |
217 | # define EV_NSIG 65 |
219 | # define EV_NSIG 65 |
218 | #endif |
220 | #endif |
219 | |
221 | |
220 | #ifndef EV_USE_CLOCK_SYSCALL |
222 | #ifndef EV_USE_CLOCK_SYSCALL |
221 | # if __linux && __GLIBC__ >= 2 |
223 | # if __linux && __GLIBC__ >= 2 |
222 | # define EV_USE_CLOCK_SYSCALL 1 |
224 | # define EV_USE_CLOCK_SYSCALL EV_FEATURE_OS |
223 | # else |
225 | # else |
224 | # define EV_USE_CLOCK_SYSCALL 0 |
226 | # define EV_USE_CLOCK_SYSCALL 0 |
225 | # endif |
227 | # endif |
226 | #endif |
228 | #endif |
227 | |
229 | |
228 | #ifndef EV_USE_MONOTONIC |
230 | #ifndef EV_USE_MONOTONIC |
229 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
231 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
230 | # define EV_USE_MONOTONIC 1 |
232 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
231 | # else |
233 | # else |
232 | # define EV_USE_MONOTONIC 0 |
234 | # define EV_USE_MONOTONIC 0 |
233 | # endif |
235 | # endif |
234 | #endif |
236 | #endif |
235 | |
237 | |
… | |
… | |
237 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
239 | # define EV_USE_REALTIME !EV_USE_CLOCK_SYSCALL |
238 | #endif |
240 | #endif |
239 | |
241 | |
240 | #ifndef EV_USE_NANOSLEEP |
242 | #ifndef EV_USE_NANOSLEEP |
241 | # if _POSIX_C_SOURCE >= 199309L |
243 | # if _POSIX_C_SOURCE >= 199309L |
242 | # define EV_USE_NANOSLEEP 1 |
244 | # define EV_USE_NANOSLEEP EV_FEATURE_OS |
243 | # else |
245 | # else |
244 | # define EV_USE_NANOSLEEP 0 |
246 | # define EV_USE_NANOSLEEP 0 |
245 | # endif |
247 | # endif |
246 | #endif |
248 | #endif |
247 | |
249 | |
248 | #ifndef EV_USE_SELECT |
250 | #ifndef EV_USE_SELECT |
249 | # define EV_USE_SELECT 1 |
251 | # define EV_USE_SELECT EV_FEATURE_BACKENDS |
250 | #endif |
252 | #endif |
251 | |
253 | |
252 | #ifndef EV_USE_POLL |
254 | #ifndef EV_USE_POLL |
253 | # ifdef _WIN32 |
255 | # ifdef _WIN32 |
254 | # define EV_USE_POLL 0 |
256 | # define EV_USE_POLL 0 |
255 | # else |
257 | # else |
256 | # define EV_USE_POLL 1 |
258 | # define EV_USE_POLL EV_FEATURE_BACKENDS |
257 | # endif |
259 | # endif |
258 | #endif |
260 | #endif |
259 | |
261 | |
260 | #ifndef EV_USE_EPOLL |
262 | #ifndef EV_USE_EPOLL |
261 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
263 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
262 | # define EV_USE_EPOLL 1 |
264 | # define EV_USE_EPOLL EV_FEATURE_BACKENDS |
263 | # else |
265 | # else |
264 | # define EV_USE_EPOLL 0 |
266 | # define EV_USE_EPOLL 0 |
265 | # endif |
267 | # endif |
266 | #endif |
268 | #endif |
267 | |
269 | |
… | |
… | |
273 | # define EV_USE_PORT 0 |
275 | # define EV_USE_PORT 0 |
274 | #endif |
276 | #endif |
275 | |
277 | |
276 | #ifndef EV_USE_INOTIFY |
278 | #ifndef EV_USE_INOTIFY |
277 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
279 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
278 | # define EV_USE_INOTIFY 1 |
280 | # define EV_USE_INOTIFY EV_FEATURE_OS |
279 | # else |
281 | # else |
280 | # define EV_USE_INOTIFY 0 |
282 | # define EV_USE_INOTIFY 0 |
281 | # endif |
283 | # endif |
282 | #endif |
284 | #endif |
283 | |
285 | |
284 | #ifndef EV_PID_HASHSIZE |
286 | #ifndef EV_PID_HASHSIZE |
285 | # if EV_MINIMAL |
287 | # define EV_PID_HASHSIZE EV_FEATURE_DATA ? 16 : 1 |
286 | # define EV_PID_HASHSIZE 1 |
|
|
287 | # else |
|
|
288 | # define EV_PID_HASHSIZE 16 |
|
|
289 | # endif |
|
|
290 | #endif |
288 | #endif |
291 | |
289 | |
292 | #ifndef EV_INOTIFY_HASHSIZE |
290 | #ifndef EV_INOTIFY_HASHSIZE |
293 | # if EV_MINIMAL |
291 | # define EV_INOTIFY_HASHSIZE EV_FEATURE_DATA ? 16 : 1 |
294 | # define EV_INOTIFY_HASHSIZE 1 |
|
|
295 | # else |
|
|
296 | # define EV_INOTIFY_HASHSIZE 16 |
|
|
297 | # endif |
|
|
298 | #endif |
292 | #endif |
299 | |
293 | |
300 | #ifndef EV_USE_EVENTFD |
294 | #ifndef EV_USE_EVENTFD |
301 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
295 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
302 | # define EV_USE_EVENTFD 1 |
296 | # define EV_USE_EVENTFD EV_FEATURE_OS |
303 | # else |
297 | # else |
304 | # define EV_USE_EVENTFD 0 |
298 | # define EV_USE_EVENTFD 0 |
305 | # endif |
299 | # endif |
306 | #endif |
300 | #endif |
307 | |
301 | |
308 | #ifndef EV_USE_SIGNALFD |
302 | #ifndef EV_USE_SIGNALFD |
309 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
303 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) |
310 | # define EV_USE_SIGNALFD 1 |
304 | # define EV_USE_SIGNALFD EV_FEATURE_OS |
311 | # else |
305 | # else |
312 | # define EV_USE_SIGNALFD 0 |
306 | # define EV_USE_SIGNALFD 0 |
313 | # endif |
307 | # endif |
314 | #endif |
308 | #endif |
315 | |
309 | |
… | |
… | |
318 | # define EV_USE_4HEAP 1 |
312 | # define EV_USE_4HEAP 1 |
319 | # define EV_HEAP_CACHE_AT 1 |
313 | # define EV_HEAP_CACHE_AT 1 |
320 | #endif |
314 | #endif |
321 | |
315 | |
322 | #ifndef EV_VERIFY |
316 | #ifndef EV_VERIFY |
323 | # define EV_VERIFY !EV_MINIMAL |
317 | # define EV_VERIFY (EV_FEATURE_API ? 1 : 0) |
324 | #endif |
318 | #endif |
325 | |
319 | |
326 | #ifndef EV_USE_4HEAP |
320 | #ifndef EV_USE_4HEAP |
327 | # define EV_USE_4HEAP !EV_MINIMAL |
321 | # define EV_USE_4HEAP EV_FEATURE_DATA |
328 | #endif |
322 | #endif |
329 | |
323 | |
330 | #ifndef EV_HEAP_CACHE_AT |
324 | #ifndef EV_HEAP_CACHE_AT |
331 | # define EV_HEAP_CACHE_AT !EV_MINIMAL |
325 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
332 | #endif |
326 | #endif |
333 | |
327 | |
334 | /* 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, */ |
335 | /* which makes programs even slower. might work on other unices, too. */ |
329 | /* which makes programs even slower. might work on other unices, too. */ |
336 | #if EV_USE_CLOCK_SYSCALL |
330 | #if EV_USE_CLOCK_SYSCALL |
… | |
… | |
474 | |
468 | |
475 | #define expect_false(expr) expect ((expr) != 0, 0) |
469 | #define expect_false(expr) expect ((expr) != 0, 0) |
476 | #define expect_true(expr) expect ((expr) != 0, 1) |
470 | #define expect_true(expr) expect ((expr) != 0, 1) |
477 | #define inline_size static inline |
471 | #define inline_size static inline |
478 | |
472 | |
479 | #if EV_MINIMAL |
473 | #if EV_FEATURE_CODE |
|
|
474 | # define inline_speed static inline |
|
|
475 | #else |
480 | # define inline_speed static noinline |
476 | # define inline_speed static noinline |
481 | #else |
|
|
482 | # define inline_speed static inline |
|
|
483 | #endif |
477 | #endif |
484 | |
478 | |
485 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
479 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
486 | |
480 | |
487 | #if EV_MINPRI == EV_MAXPRI |
481 | #if EV_MINPRI == EV_MAXPRI |
… | |
… | |
524 | # include "ev_win32.c" |
518 | # include "ev_win32.c" |
525 | #endif |
519 | #endif |
526 | |
520 | |
527 | /*****************************************************************************/ |
521 | /*****************************************************************************/ |
528 | |
522 | |
|
|
523 | #if EV_AVOID_STDIO |
|
|
524 | static void noinline |
|
|
525 | ev_printerr (const char *msg) |
|
|
526 | { |
|
|
527 | write (STDERR_FILENO, msg, strlen (msg)); |
|
|
528 | } |
|
|
529 | #endif |
|
|
530 | |
529 | static void (*syserr_cb)(const char *msg); |
531 | static void (*syserr_cb)(const char *msg); |
530 | |
532 | |
531 | void |
533 | void |
532 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
534 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
533 | { |
535 | { |
… | |
… | |
543 | if (syserr_cb) |
545 | if (syserr_cb) |
544 | syserr_cb (msg); |
546 | syserr_cb (msg); |
545 | else |
547 | else |
546 | { |
548 | { |
547 | #if EV_AVOID_STDIO |
549 | #if EV_AVOID_STDIO |
548 | write (STDERR_FILENO, msg, strlen (msg)); |
|
|
549 | write (STDERR_FILENO, ": ", 2); |
|
|
550 | msg = strerror (errno); |
550 | const char *err = strerror (errno); |
551 | write (STDERR_FILENO, msg, strlen (msg)); |
551 | |
552 | write (STDERR_FILENO, "\n", 1); |
552 | ev_printerr (msg); |
|
|
553 | ev_printerr (": "); |
|
|
554 | ev_printerr (err); |
|
|
555 | ev_printerr ("\n"); |
553 | #else |
556 | #else |
554 | perror (msg); |
557 | perror (msg); |
555 | #endif |
558 | #endif |
556 | abort (); |
559 | abort (); |
557 | } |
560 | } |
558 | } |
561 | } |
559 | |
562 | |
560 | static void * |
563 | static void * |
561 | ev_realloc_emul (void *ptr, long size) |
564 | ev_realloc_emul (void *ptr, long size) |
562 | { |
565 | { |
|
|
566 | #if __GLIBC__ |
|
|
567 | return realloc (ptr, size); |
|
|
568 | #else |
563 | /* some systems, notably openbsd and darwin, fail to properly |
569 | /* some systems, notably openbsd and darwin, fail to properly |
564 | * 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 |
565 | * the single unix specification, so work around them here. |
571 | * the single unix specification, so work around them here. |
566 | */ |
572 | */ |
567 | |
573 | |
568 | if (size) |
574 | if (size) |
569 | return realloc (ptr, size); |
575 | return realloc (ptr, size); |
570 | |
576 | |
571 | free (ptr); |
577 | free (ptr); |
572 | return 0; |
578 | return 0; |
|
|
579 | #endif |
573 | } |
580 | } |
574 | |
581 | |
575 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
582 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
576 | |
583 | |
577 | void |
584 | void |
… | |
… | |
586 | ptr = alloc (ptr, size); |
593 | ptr = alloc (ptr, size); |
587 | |
594 | |
588 | if (!ptr && size) |
595 | if (!ptr && size) |
589 | { |
596 | { |
590 | #if EV_AVOID_STDIO |
597 | #if EV_AVOID_STDIO |
591 | write (STDERR_FILENO, "libev: memory allocation failed, aborting.", |
598 | ev_printerr ("libev: memory allocation failed, aborting.\n"); |
592 | sizeof ("libev: memory allocation failed, aborting.") - 1); |
|
|
593 | #else |
599 | #else |
594 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
600 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
595 | #endif |
601 | #endif |
596 | abort (); |
602 | abort (); |
597 | } |
603 | } |
… | |
… | |
682 | |
688 | |
683 | static int ev_default_loop_ptr; |
689 | static int ev_default_loop_ptr; |
684 | |
690 | |
685 | #endif |
691 | #endif |
686 | |
692 | |
687 | #if EV_MINIMAL < 2 |
693 | #if EV_FEATURE_API |
688 | # 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) |
689 | # 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) |
690 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
696 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
691 | #else |
697 | #else |
692 | # define EV_RELEASE_CB (void)0 |
698 | # define EV_RELEASE_CB (void)0 |
… | |
… | |
877 | } |
883 | } |
878 | |
884 | |
879 | /*****************************************************************************/ |
885 | /*****************************************************************************/ |
880 | |
886 | |
881 | inline_speed void |
887 | inline_speed void |
882 | fd_event_nc (EV_P_ int fd, int revents) |
888 | fd_event_nocheck (EV_P_ int fd, int revents) |
883 | { |
889 | { |
884 | ANFD *anfd = anfds + fd; |
890 | ANFD *anfd = anfds + fd; |
885 | ev_io *w; |
891 | ev_io *w; |
886 | |
892 | |
887 | 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) |
… | |
… | |
899 | fd_event (EV_P_ int fd, int revents) |
905 | fd_event (EV_P_ int fd, int revents) |
900 | { |
906 | { |
901 | ANFD *anfd = anfds + fd; |
907 | ANFD *anfd = anfds + fd; |
902 | |
908 | |
903 | if (expect_true (!anfd->reify)) |
909 | if (expect_true (!anfd->reify)) |
904 | fd_event_nc (EV_A_ fd, revents); |
910 | fd_event_nocheck (EV_A_ fd, revents); |
905 | } |
911 | } |
906 | |
912 | |
907 | void |
913 | void |
908 | ev_feed_fd_event (EV_P_ int fd, int revents) |
914 | ev_feed_fd_event (EV_P_ int fd, int revents) |
909 | { |
915 | { |
910 | if (fd >= 0 && fd < anfdmax) |
916 | if (fd >= 0 && fd < anfdmax) |
911 | fd_event_nc (EV_A_ fd, revents); |
917 | fd_event_nocheck (EV_A_ fd, revents); |
912 | } |
918 | } |
913 | |
919 | |
914 | /* make sure the external fd watch events are in-sync */ |
920 | /* make sure the external fd watch events are in-sync */ |
915 | /* with the kernel/libev internal state */ |
921 | /* with the kernel/libev internal state */ |
916 | inline_size void |
922 | inline_size void |
… | |
… | |
979 | ev_io_stop (EV_A_ w); |
985 | ev_io_stop (EV_A_ w); |
980 | 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); |
981 | } |
987 | } |
982 | } |
988 | } |
983 | |
989 | |
984 | /* check whether the given fd is atcually valid, for error recovery */ |
990 | /* check whether the given fd is actually valid, for error recovery */ |
985 | inline_size int |
991 | inline_size int |
986 | fd_valid (int fd) |
992 | fd_valid (int fd) |
987 | { |
993 | { |
988 | #ifdef _WIN32 |
994 | #ifdef _WIN32 |
989 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
995 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
… | |
… | |
1029 | { |
1035 | { |
1030 | anfds [fd].events = 0; |
1036 | anfds [fd].events = 0; |
1031 | anfds [fd].emask = 0; |
1037 | anfds [fd].emask = 0; |
1032 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1038 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1033 | } |
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 |
1034 | } |
1054 | } |
1035 | |
1055 | |
1036 | /*****************************************************************************/ |
1056 | /*****************************************************************************/ |
1037 | |
1057 | |
1038 | /* |
1058 | /* |
… | |
… | |
1192 | |
1212 | |
1193 | static ANSIG signals [EV_NSIG - 1]; |
1213 | static ANSIG signals [EV_NSIG - 1]; |
1194 | |
1214 | |
1195 | /*****************************************************************************/ |
1215 | /*****************************************************************************/ |
1196 | |
1216 | |
1197 | /* used to prepare libev internal fd's */ |
1217 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1198 | /* this is not fork-safe */ |
|
|
1199 | inline_speed void |
|
|
1200 | fd_intern (int fd) |
|
|
1201 | { |
|
|
1202 | #ifdef _WIN32 |
|
|
1203 | unsigned long arg = 1; |
|
|
1204 | ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg); |
|
|
1205 | #else |
|
|
1206 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1207 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1208 | #endif |
|
|
1209 | } |
|
|
1210 | |
1218 | |
1211 | static void noinline |
1219 | static void noinline |
1212 | evpipe_init (EV_P) |
1220 | evpipe_init (EV_P) |
1213 | { |
1221 | { |
1214 | if (!ev_is_active (&pipe_w)) |
1222 | if (!ev_is_active (&pipe_w)) |
1215 | { |
1223 | { |
1216 | #if EV_USE_EVENTFD |
1224 | # if EV_USE_EVENTFD |
1217 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1225 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1218 | if (evfd < 0 && errno == EINVAL) |
1226 | if (evfd < 0 && errno == EINVAL) |
1219 | evfd = eventfd (0, 0); |
1227 | evfd = eventfd (0, 0); |
1220 | |
1228 | |
1221 | if (evfd >= 0) |
1229 | if (evfd >= 0) |
… | |
… | |
1223 | evpipe [0] = -1; |
1231 | evpipe [0] = -1; |
1224 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1232 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1225 | ev_io_set (&pipe_w, evfd, EV_READ); |
1233 | ev_io_set (&pipe_w, evfd, EV_READ); |
1226 | } |
1234 | } |
1227 | else |
1235 | else |
1228 | #endif |
1236 | # endif |
1229 | { |
1237 | { |
1230 | while (pipe (evpipe)) |
1238 | while (pipe (evpipe)) |
1231 | ev_syserr ("(libev) error creating signal/async pipe"); |
1239 | ev_syserr ("(libev) error creating signal/async pipe"); |
1232 | |
1240 | |
1233 | fd_intern (evpipe [0]); |
1241 | fd_intern (evpipe [0]); |
… | |
… | |
1244 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1252 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1245 | { |
1253 | { |
1246 | if (!*flag) |
1254 | if (!*flag) |
1247 | { |
1255 | { |
1248 | 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; |
1249 | |
1258 | |
1250 | *flag = 1; |
1259 | *flag = 1; |
1251 | |
1260 | |
1252 | #if EV_USE_EVENTFD |
1261 | #if EV_USE_EVENTFD |
1253 | if (evfd >= 0) |
1262 | if (evfd >= 0) |
… | |
… | |
1255 | uint64_t counter = 1; |
1264 | uint64_t counter = 1; |
1256 | write (evfd, &counter, sizeof (uint64_t)); |
1265 | write (evfd, &counter, sizeof (uint64_t)); |
1257 | } |
1266 | } |
1258 | else |
1267 | else |
1259 | #endif |
1268 | #endif |
1260 | write (evpipe [1], &old_errno, 1); |
1269 | write (evpipe [1], &dummy, 1); |
1261 | |
1270 | |
1262 | errno = old_errno; |
1271 | errno = old_errno; |
1263 | } |
1272 | } |
1264 | } |
1273 | } |
1265 | |
1274 | |
… | |
… | |
1366 | break; |
1375 | break; |
1367 | } |
1376 | } |
1368 | } |
1377 | } |
1369 | #endif |
1378 | #endif |
1370 | |
1379 | |
|
|
1380 | #endif |
|
|
1381 | |
1371 | /*****************************************************************************/ |
1382 | /*****************************************************************************/ |
1372 | |
1383 | |
|
|
1384 | #if EV_CHILD_ENABLE |
1373 | static WL childs [EV_PID_HASHSIZE]; |
1385 | static WL childs [EV_PID_HASHSIZE]; |
1374 | |
|
|
1375 | #ifndef _WIN32 |
|
|
1376 | |
1386 | |
1377 | static ev_signal childev; |
1387 | static ev_signal childev; |
1378 | |
1388 | |
1379 | #ifndef WIFCONTINUED |
1389 | #ifndef WIFCONTINUED |
1380 | # define WIFCONTINUED(status) 0 |
1390 | # define WIFCONTINUED(status) 0 |
… | |
… | |
1385 | child_reap (EV_P_ int chain, int pid, int status) |
1395 | child_reap (EV_P_ int chain, int pid, int status) |
1386 | { |
1396 | { |
1387 | ev_child *w; |
1397 | ev_child *w; |
1388 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1398 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1389 | |
1399 | |
1390 | 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) |
1391 | { |
1401 | { |
1392 | if ((w->pid == pid || !w->pid) |
1402 | if ((w->pid == pid || !w->pid) |
1393 | && (!traced || (w->flags & 1))) |
1403 | && (!traced || (w->flags & 1))) |
1394 | { |
1404 | { |
1395 | 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 */ |
… | |
… | |
1420 | /* 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 */ |
1421 | /* 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 */ |
1422 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1432 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1423 | |
1433 | |
1424 | child_reap (EV_A_ pid, pid, status); |
1434 | child_reap (EV_A_ pid, pid, status); |
1425 | if (EV_PID_HASHSIZE > 1) |
1435 | if ((EV_PID_HASHSIZE) > 1) |
1426 | 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 */ |
1427 | } |
1437 | } |
1428 | |
1438 | |
1429 | #endif |
1439 | #endif |
1430 | |
1440 | |
… | |
… | |
1519 | ev_backend (EV_P) |
1529 | ev_backend (EV_P) |
1520 | { |
1530 | { |
1521 | return backend; |
1531 | return backend; |
1522 | } |
1532 | } |
1523 | |
1533 | |
1524 | #if EV_MINIMAL < 2 |
1534 | #if EV_FEATURE_API |
1525 | unsigned int |
1535 | unsigned int |
1526 | ev_loop_count (EV_P) |
1536 | ev_loop_count (EV_P) |
1527 | { |
1537 | { |
1528 | return loop_count; |
1538 | return loop_count; |
1529 | } |
1539 | } |
… | |
… | |
1609 | |
1619 | |
1610 | ev_rt_now = ev_time (); |
1620 | ev_rt_now = ev_time (); |
1611 | mn_now = get_clock (); |
1621 | mn_now = get_clock (); |
1612 | now_floor = mn_now; |
1622 | now_floor = mn_now; |
1613 | rtmn_diff = ev_rt_now - mn_now; |
1623 | rtmn_diff = ev_rt_now - mn_now; |
1614 | #if EV_MINIMAL < 2 |
1624 | #if EV_FEATURE_API |
1615 | invoke_cb = ev_invoke_pending; |
1625 | invoke_cb = ev_invoke_pending; |
1616 | #endif |
1626 | #endif |
1617 | |
1627 | |
1618 | io_blocktime = 0.; |
1628 | io_blocktime = 0.; |
1619 | timeout_blocktime = 0.; |
1629 | timeout_blocktime = 0.; |
… | |
… | |
1649 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1659 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1650 | #endif |
1660 | #endif |
1651 | |
1661 | |
1652 | ev_prepare_init (&pending_w, pendingcb); |
1662 | ev_prepare_init (&pending_w, pendingcb); |
1653 | |
1663 | |
|
|
1664 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1654 | ev_init (&pipe_w, pipecb); |
1665 | ev_init (&pipe_w, pipecb); |
1655 | ev_set_priority (&pipe_w, EV_MAXPRI); |
1666 | ev_set_priority (&pipe_w, EV_MAXPRI); |
|
|
1667 | #endif |
1656 | } |
1668 | } |
1657 | } |
1669 | } |
1658 | |
1670 | |
1659 | /* free up a loop structure */ |
1671 | /* free up a loop structure */ |
1660 | static void noinline |
1672 | static void noinline |
… | |
… | |
1778 | { |
1790 | { |
1779 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1791 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1780 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1792 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1781 | } |
1793 | } |
1782 | |
1794 | |
|
|
1795 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1783 | evpipe_init (EV_A); |
1796 | evpipe_init (EV_A); |
1784 | /* now iterate over everything, in case we missed something */ |
1797 | /* now iterate over everything, in case we missed something */ |
1785 | pipecb (EV_A_ &pipe_w, EV_READ); |
1798 | pipecb (EV_A_ &pipe_w, EV_READ); |
|
|
1799 | #endif |
1786 | } |
1800 | } |
1787 | |
1801 | |
1788 | postfork = 0; |
1802 | postfork = 0; |
1789 | } |
1803 | } |
1790 | |
1804 | |
… | |
… | |
1852 | verify_watcher (EV_A_ ws [cnt]); |
1866 | verify_watcher (EV_A_ ws [cnt]); |
1853 | } |
1867 | } |
1854 | } |
1868 | } |
1855 | #endif |
1869 | #endif |
1856 | |
1870 | |
1857 | #if EV_MINIMAL < 2 |
1871 | #if EV_FEATURE_API |
1858 | void |
1872 | void |
1859 | ev_loop_verify (EV_P) |
1873 | ev_loop_verify (EV_P) |
1860 | { |
1874 | { |
1861 | #if EV_VERIFY |
1875 | #if EV_VERIFY |
1862 | int i; |
1876 | int i; |
… | |
… | |
1903 | #if EV_ASYNC_ENABLE |
1917 | #if EV_ASYNC_ENABLE |
1904 | assert (asyncmax >= asynccnt); |
1918 | assert (asyncmax >= asynccnt); |
1905 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1919 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1906 | #endif |
1920 | #endif |
1907 | |
1921 | |
|
|
1922 | #if EV_PREPARE_ENABLE |
1908 | assert (preparemax >= preparecnt); |
1923 | assert (preparemax >= preparecnt); |
1909 | array_verify (EV_A_ (W *)prepares, preparecnt); |
1924 | array_verify (EV_A_ (W *)prepares, preparecnt); |
|
|
1925 | #endif |
1910 | |
1926 | |
|
|
1927 | #if EV_CHECK_ENABLE |
1911 | assert (checkmax >= checkcnt); |
1928 | assert (checkmax >= checkcnt); |
1912 | array_verify (EV_A_ (W *)checks, checkcnt); |
1929 | array_verify (EV_A_ (W *)checks, checkcnt); |
|
|
1930 | #endif |
1913 | |
1931 | |
1914 | # if 0 |
1932 | # if 0 |
|
|
1933 | #if EV_CHILD_ENABLE |
1915 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1934 | for (w = (ev_child *)childs [chain & ((EV_PID_HASHSIZE) - 1)]; w; w = (ev_child *)((WL)w)->next) |
1916 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
1935 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
|
|
1936 | #endif |
1917 | # endif |
1937 | # endif |
1918 | #endif |
1938 | #endif |
1919 | } |
1939 | } |
1920 | #endif |
1940 | #endif |
1921 | |
1941 | |
… | |
… | |
1937 | |
1957 | |
1938 | loop_init (EV_A_ flags); |
1958 | loop_init (EV_A_ flags); |
1939 | |
1959 | |
1940 | if (ev_backend (EV_A)) |
1960 | if (ev_backend (EV_A)) |
1941 | { |
1961 | { |
1942 | #ifndef _WIN32 |
1962 | #if EV_CHILD_ENABLE |
1943 | ev_signal_init (&childev, childcb, SIGCHLD); |
1963 | ev_signal_init (&childev, childcb, SIGCHLD); |
1944 | ev_set_priority (&childev, EV_MAXPRI); |
1964 | ev_set_priority (&childev, EV_MAXPRI); |
1945 | ev_signal_start (EV_A_ &childev); |
1965 | ev_signal_start (EV_A_ &childev); |
1946 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1966 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1947 | #endif |
1967 | #endif |
… | |
… | |
1960 | EV_P = ev_default_loop_ptr; |
1980 | EV_P = ev_default_loop_ptr; |
1961 | #endif |
1981 | #endif |
1962 | |
1982 | |
1963 | ev_default_loop_ptr = 0; |
1983 | ev_default_loop_ptr = 0; |
1964 | |
1984 | |
1965 | #ifndef _WIN32 |
1985 | #if EV_CHILD_ENABLE |
1966 | ev_ref (EV_A); /* child watcher */ |
1986 | ev_ref (EV_A); /* child watcher */ |
1967 | ev_signal_stop (EV_A_ &childev); |
1987 | ev_signal_stop (EV_A_ &childev); |
1968 | #endif |
1988 | #endif |
1969 | |
1989 | |
1970 | loop_destroy (EV_A); |
1990 | loop_destroy (EV_A); |
… | |
… | |
2247 | } |
2267 | } |
2248 | |
2268 | |
2249 | void |
2269 | void |
2250 | ev_loop (EV_P_ int flags) |
2270 | ev_loop (EV_P_ int flags) |
2251 | { |
2271 | { |
2252 | #if EV_MINIMAL < 2 |
2272 | #if EV_FEATURE_API |
2253 | ++loop_depth; |
2273 | ++loop_depth; |
2254 | #endif |
2274 | #endif |
2255 | |
2275 | |
2256 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2276 | assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE)); |
2257 | |
2277 | |
… | |
… | |
2282 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2302 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2283 | EV_INVOKE_PENDING; |
2303 | EV_INVOKE_PENDING; |
2284 | } |
2304 | } |
2285 | #endif |
2305 | #endif |
2286 | |
2306 | |
|
|
2307 | #if EV_PREPARE_ENABLE |
2287 | /* queue prepare watchers (and execute them) */ |
2308 | /* queue prepare watchers (and execute them) */ |
2288 | if (expect_false (preparecnt)) |
2309 | if (expect_false (preparecnt)) |
2289 | { |
2310 | { |
2290 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2311 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2291 | EV_INVOKE_PENDING; |
2312 | EV_INVOKE_PENDING; |
2292 | } |
2313 | } |
|
|
2314 | #endif |
2293 | |
2315 | |
2294 | if (expect_false (loop_done)) |
2316 | if (expect_false (loop_done)) |
2295 | break; |
2317 | break; |
2296 | |
2318 | |
2297 | /* we might have forked, so reify kernel state if necessary */ |
2319 | /* we might have forked, so reify kernel state if necessary */ |
… | |
… | |
2348 | waittime -= sleeptime; |
2370 | waittime -= sleeptime; |
2349 | } |
2371 | } |
2350 | } |
2372 | } |
2351 | } |
2373 | } |
2352 | |
2374 | |
2353 | #if EV_MINIMAL < 2 |
2375 | #if EV_FEATURE_API |
2354 | ++loop_count; |
2376 | ++loop_count; |
2355 | #endif |
2377 | #endif |
2356 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2378 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2357 | backend_poll (EV_A_ waittime); |
2379 | backend_poll (EV_A_ waittime); |
2358 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
2380 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
… | |
… | |
2370 | #if EV_IDLE_ENABLE |
2392 | #if EV_IDLE_ENABLE |
2371 | /* queue idle watchers unless other events are pending */ |
2393 | /* queue idle watchers unless other events are pending */ |
2372 | idle_reify (EV_A); |
2394 | idle_reify (EV_A); |
2373 | #endif |
2395 | #endif |
2374 | |
2396 | |
|
|
2397 | #if EV_CHECK_ENABLE |
2375 | /* queue check watchers, to be executed first */ |
2398 | /* queue check watchers, to be executed first */ |
2376 | if (expect_false (checkcnt)) |
2399 | if (expect_false (checkcnt)) |
2377 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
2400 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
|
|
2401 | #endif |
2378 | |
2402 | |
2379 | EV_INVOKE_PENDING; |
2403 | EV_INVOKE_PENDING; |
2380 | } |
2404 | } |
2381 | while (expect_true ( |
2405 | while (expect_true ( |
2382 | activecnt |
2406 | activecnt |
… | |
… | |
2385 | )); |
2409 | )); |
2386 | |
2410 | |
2387 | if (loop_done == EVUNLOOP_ONE) |
2411 | if (loop_done == EVUNLOOP_ONE) |
2388 | loop_done = EVUNLOOP_CANCEL; |
2412 | loop_done = EVUNLOOP_CANCEL; |
2389 | |
2413 | |
2390 | #if EV_MINIMAL < 2 |
2414 | #if EV_FEATURE_API |
2391 | --loop_depth; |
2415 | --loop_depth; |
2392 | #endif |
2416 | #endif |
2393 | } |
2417 | } |
2394 | |
2418 | |
2395 | void |
2419 | void |
… | |
… | |
2712 | |
2736 | |
2713 | #ifndef SA_RESTART |
2737 | #ifndef SA_RESTART |
2714 | # define SA_RESTART 0 |
2738 | # define SA_RESTART 0 |
2715 | #endif |
2739 | #endif |
2716 | |
2740 | |
|
|
2741 | #if EV_SIGNAL_ENABLE |
|
|
2742 | |
2717 | void noinline |
2743 | void noinline |
2718 | ev_signal_start (EV_P_ ev_signal *w) |
2744 | ev_signal_start (EV_P_ ev_signal *w) |
2719 | { |
2745 | { |
2720 | if (expect_false (ev_is_active (w))) |
2746 | if (expect_false (ev_is_active (w))) |
2721 | return; |
2747 | return; |
… | |
… | |
2827 | } |
2853 | } |
2828 | |
2854 | |
2829 | EV_FREQUENT_CHECK; |
2855 | EV_FREQUENT_CHECK; |
2830 | } |
2856 | } |
2831 | |
2857 | |
|
|
2858 | #endif |
|
|
2859 | |
|
|
2860 | #if EV_CHILD_ENABLE |
|
|
2861 | |
2832 | void |
2862 | void |
2833 | ev_child_start (EV_P_ ev_child *w) |
2863 | ev_child_start (EV_P_ ev_child *w) |
2834 | { |
2864 | { |
2835 | #if EV_MULTIPLICITY |
2865 | #if EV_MULTIPLICITY |
2836 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
2866 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
… | |
… | |
2839 | return; |
2869 | return; |
2840 | |
2870 | |
2841 | EV_FREQUENT_CHECK; |
2871 | EV_FREQUENT_CHECK; |
2842 | |
2872 | |
2843 | ev_start (EV_A_ (W)w, 1); |
2873 | ev_start (EV_A_ (W)w, 1); |
2844 | wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2874 | wlist_add (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2845 | |
2875 | |
2846 | EV_FREQUENT_CHECK; |
2876 | EV_FREQUENT_CHECK; |
2847 | } |
2877 | } |
2848 | |
2878 | |
2849 | void |
2879 | void |
… | |
… | |
2853 | if (expect_false (!ev_is_active (w))) |
2883 | if (expect_false (!ev_is_active (w))) |
2854 | return; |
2884 | return; |
2855 | |
2885 | |
2856 | EV_FREQUENT_CHECK; |
2886 | EV_FREQUENT_CHECK; |
2857 | |
2887 | |
2858 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2888 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2859 | ev_stop (EV_A_ (W)w); |
2889 | ev_stop (EV_A_ (W)w); |
2860 | |
2890 | |
2861 | EV_FREQUENT_CHECK; |
2891 | EV_FREQUENT_CHECK; |
2862 | } |
2892 | } |
|
|
2893 | |
|
|
2894 | #endif |
2863 | |
2895 | |
2864 | #if EV_STAT_ENABLE |
2896 | #if EV_STAT_ENABLE |
2865 | |
2897 | |
2866 | # ifdef _WIN32 |
2898 | # ifdef _WIN32 |
2867 | # undef lstat |
2899 | # undef lstat |
… | |
… | |
2934 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2966 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2935 | } |
2967 | } |
2936 | } |
2968 | } |
2937 | |
2969 | |
2938 | if (w->wd >= 0) |
2970 | if (w->wd >= 0) |
2939 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2971 | wlist_add (&fs_hash [w->wd & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
2940 | |
2972 | |
2941 | /* now re-arm timer, if required */ |
2973 | /* now re-arm timer, if required */ |
2942 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2974 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2943 | ev_timer_again (EV_A_ &w->timer); |
2975 | ev_timer_again (EV_A_ &w->timer); |
2944 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
2976 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
… | |
… | |
2952 | |
2984 | |
2953 | if (wd < 0) |
2985 | if (wd < 0) |
2954 | return; |
2986 | return; |
2955 | |
2987 | |
2956 | w->wd = -2; |
2988 | w->wd = -2; |
2957 | slot = wd & (EV_INOTIFY_HASHSIZE - 1); |
2989 | slot = wd & ((EV_INOTIFY_HASHSIZE) - 1); |
2958 | wlist_del (&fs_hash [slot].head, (WL)w); |
2990 | wlist_del (&fs_hash [slot].head, (WL)w); |
2959 | |
2991 | |
2960 | /* remove this watcher, if others are watching it, they will rearm */ |
2992 | /* remove this watcher, if others are watching it, they will rearm */ |
2961 | inotify_rm_watch (fs_fd, wd); |
2993 | inotify_rm_watch (fs_fd, wd); |
2962 | } |
2994 | } |
… | |
… | |
2964 | static void noinline |
2996 | static void noinline |
2965 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
2997 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
2966 | { |
2998 | { |
2967 | if (slot < 0) |
2999 | if (slot < 0) |
2968 | /* overflow, need to check for all hash slots */ |
3000 | /* overflow, need to check for all hash slots */ |
2969 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3001 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
2970 | infy_wd (EV_A_ slot, wd, ev); |
3002 | infy_wd (EV_A_ slot, wd, ev); |
2971 | else |
3003 | else |
2972 | { |
3004 | { |
2973 | WL w_; |
3005 | WL w_; |
2974 | |
3006 | |
2975 | for (w_ = fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head; w_; ) |
3007 | for (w_ = fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head; w_; ) |
2976 | { |
3008 | { |
2977 | ev_stat *w = (ev_stat *)w_; |
3009 | ev_stat *w = (ev_stat *)w_; |
2978 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
3010 | w_ = w_->next; /* lets us remove this watcher and all before it */ |
2979 | |
3011 | |
2980 | if (w->wd == wd || wd == -1) |
3012 | if (w->wd == wd || wd == -1) |
2981 | { |
3013 | { |
2982 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
3014 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
2983 | { |
3015 | { |
2984 | wlist_del (&fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
3016 | wlist_del (&fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head, (WL)w); |
2985 | w->wd = -1; |
3017 | w->wd = -1; |
2986 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3018 | infy_add (EV_A_ w); /* re-add, no matter what */ |
2987 | } |
3019 | } |
2988 | |
3020 | |
2989 | stat_timer_cb (EV_A_ &w->timer, 0); |
3021 | stat_timer_cb (EV_A_ &w->timer, 0); |
… | |
… | |
3103 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3135 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3104 | ev_io_start (EV_A_ &fs_w); |
3136 | ev_io_start (EV_A_ &fs_w); |
3105 | ev_unref (EV_A); |
3137 | ev_unref (EV_A); |
3106 | } |
3138 | } |
3107 | |
3139 | |
3108 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3140 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
3109 | { |
3141 | { |
3110 | WL w_ = fs_hash [slot].head; |
3142 | WL w_ = fs_hash [slot].head; |
3111 | fs_hash [slot].head = 0; |
3143 | fs_hash [slot].head = 0; |
3112 | |
3144 | |
3113 | while (w_) |
3145 | while (w_) |
… | |
… | |
3288 | |
3320 | |
3289 | EV_FREQUENT_CHECK; |
3321 | EV_FREQUENT_CHECK; |
3290 | } |
3322 | } |
3291 | #endif |
3323 | #endif |
3292 | |
3324 | |
|
|
3325 | #if EV_PREPARE_ENABLE |
3293 | void |
3326 | void |
3294 | ev_prepare_start (EV_P_ ev_prepare *w) |
3327 | ev_prepare_start (EV_P_ ev_prepare *w) |
3295 | { |
3328 | { |
3296 | if (expect_false (ev_is_active (w))) |
3329 | if (expect_false (ev_is_active (w))) |
3297 | return; |
3330 | return; |
… | |
… | |
3323 | |
3356 | |
3324 | ev_stop (EV_A_ (W)w); |
3357 | ev_stop (EV_A_ (W)w); |
3325 | |
3358 | |
3326 | EV_FREQUENT_CHECK; |
3359 | EV_FREQUENT_CHECK; |
3327 | } |
3360 | } |
|
|
3361 | #endif |
3328 | |
3362 | |
|
|
3363 | #if EV_CHECK_ENABLE |
3329 | void |
3364 | void |
3330 | ev_check_start (EV_P_ ev_check *w) |
3365 | ev_check_start (EV_P_ ev_check *w) |
3331 | { |
3366 | { |
3332 | if (expect_false (ev_is_active (w))) |
3367 | if (expect_false (ev_is_active (w))) |
3333 | return; |
3368 | return; |
… | |
… | |
3359 | |
3394 | |
3360 | ev_stop (EV_A_ (W)w); |
3395 | ev_stop (EV_A_ (W)w); |
3361 | |
3396 | |
3362 | EV_FREQUENT_CHECK; |
3397 | EV_FREQUENT_CHECK; |
3363 | } |
3398 | } |
|
|
3399 | #endif |
3364 | |
3400 | |
3365 | #if EV_EMBED_ENABLE |
3401 | #if EV_EMBED_ENABLE |
3366 | void noinline |
3402 | void noinline |
3367 | ev_embed_sweep (EV_P_ ev_embed *w) |
3403 | ev_embed_sweep (EV_P_ ev_embed *w) |
3368 | { |
3404 | { |
… | |
… | |
3697 | if (types & EV_ASYNC) |
3733 | if (types & EV_ASYNC) |
3698 | for (i = asynccnt; i--; ) |
3734 | for (i = asynccnt; i--; ) |
3699 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3735 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3700 | #endif |
3736 | #endif |
3701 | |
3737 | |
|
|
3738 | #if EV_PREPARE_ENABLE |
3702 | if (types & EV_PREPARE) |
3739 | if (types & EV_PREPARE) |
3703 | for (i = preparecnt; i--; ) |
3740 | for (i = preparecnt; i--; ) |
3704 | #if EV_EMBED_ENABLE |
3741 | # if EV_EMBED_ENABLE |
3705 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3742 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3706 | #endif |
3743 | # endif |
3707 | cb (EV_A_ EV_PREPARE, prepares [i]); |
3744 | cb (EV_A_ EV_PREPARE, prepares [i]); |
|
|
3745 | #endif |
3708 | |
3746 | |
|
|
3747 | #if EV_CHECK_ENABLE |
3709 | if (types & EV_CHECK) |
3748 | if (types & EV_CHECK) |
3710 | for (i = checkcnt; i--; ) |
3749 | for (i = checkcnt; i--; ) |
3711 | cb (EV_A_ EV_CHECK, checks [i]); |
3750 | cb (EV_A_ EV_CHECK, checks [i]); |
|
|
3751 | #endif |
3712 | |
3752 | |
|
|
3753 | #if EV_SIGNAL_ENABLE |
3713 | if (types & EV_SIGNAL) |
3754 | if (types & EV_SIGNAL) |
3714 | for (i = 0; i < EV_NSIG - 1; ++i) |
3755 | for (i = 0; i < EV_NSIG - 1; ++i) |
3715 | for (wl = signals [i].head; wl; ) |
3756 | for (wl = signals [i].head; wl; ) |
3716 | { |
3757 | { |
3717 | wn = wl->next; |
3758 | wn = wl->next; |
3718 | cb (EV_A_ EV_SIGNAL, wl); |
3759 | cb (EV_A_ EV_SIGNAL, wl); |
3719 | wl = wn; |
3760 | wl = wn; |
3720 | } |
3761 | } |
|
|
3762 | #endif |
3721 | |
3763 | |
|
|
3764 | #if EV_CHILD_ENABLE |
3722 | if (types & EV_CHILD) |
3765 | if (types & EV_CHILD) |
3723 | for (i = EV_PID_HASHSIZE; i--; ) |
3766 | for (i = (EV_PID_HASHSIZE); i--; ) |
3724 | for (wl = childs [i]; wl; ) |
3767 | for (wl = childs [i]; wl; ) |
3725 | { |
3768 | { |
3726 | wn = wl->next; |
3769 | wn = wl->next; |
3727 | cb (EV_A_ EV_CHILD, wl); |
3770 | cb (EV_A_ EV_CHILD, wl); |
3728 | wl = wn; |
3771 | wl = wn; |
3729 | } |
3772 | } |
|
|
3773 | #endif |
3730 | /* EV_STAT 0x00001000 /* stat data changed */ |
3774 | /* EV_STAT 0x00001000 /* stat data changed */ |
3731 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3775 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3732 | } |
3776 | } |
3733 | #endif |
3777 | #endif |
3734 | |
3778 | |