… | |
… | |
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 |
… | |
… | |
403 | # endif |
397 | # endif |
404 | # endif |
398 | # endif |
405 | # ifdef __cplusplus |
399 | # ifdef __cplusplus |
406 | extern "C" { |
400 | extern "C" { |
407 | # endif |
401 | # endif |
408 | int eventfd (unsigned int initval, int flags); |
402 | int (eventfd) (unsigned int initval, int flags); |
409 | # ifdef __cplusplus |
403 | # ifdef __cplusplus |
410 | } |
404 | } |
411 | # endif |
405 | # endif |
412 | #endif |
406 | #endif |
413 | |
407 | |
… | |
… | |
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 | { |
… | |
… | |
542 | |
544 | |
543 | if (syserr_cb) |
545 | if (syserr_cb) |
544 | syserr_cb (msg); |
546 | syserr_cb (msg); |
545 | else |
547 | else |
546 | { |
548 | { |
|
|
549 | #if EV_AVOID_STDIO |
|
|
550 | const char *err = strerror (errno); |
|
|
551 | |
|
|
552 | ev_printerr (msg); |
|
|
553 | ev_printerr (": "); |
|
|
554 | ev_printerr (err); |
|
|
555 | ev_printerr ("\n"); |
|
|
556 | #else |
547 | perror (msg); |
557 | perror (msg); |
|
|
558 | #endif |
548 | abort (); |
559 | abort (); |
549 | } |
560 | } |
550 | } |
561 | } |
551 | |
562 | |
552 | static void * |
563 | static void * |
553 | ev_realloc_emul (void *ptr, long size) |
564 | ev_realloc_emul (void *ptr, long size) |
554 | { |
565 | { |
|
|
566 | #if __GLIBC__ |
|
|
567 | return realloc (ptr, size); |
|
|
568 | #else |
555 | /* some systems, notably openbsd and darwin, fail to properly |
569 | /* some systems, notably openbsd and darwin, fail to properly |
556 | * 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 |
557 | * the single unix specification, so work around them here. |
571 | * the single unix specification, so work around them here. |
558 | */ |
572 | */ |
559 | |
573 | |
560 | if (size) |
574 | if (size) |
561 | return realloc (ptr, size); |
575 | return realloc (ptr, size); |
562 | |
576 | |
563 | free (ptr); |
577 | free (ptr); |
564 | return 0; |
578 | return 0; |
|
|
579 | #endif |
565 | } |
580 | } |
566 | |
581 | |
567 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
582 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
568 | |
583 | |
569 | void |
584 | void |
… | |
… | |
577 | { |
592 | { |
578 | ptr = alloc (ptr, size); |
593 | ptr = alloc (ptr, size); |
579 | |
594 | |
580 | if (!ptr && size) |
595 | if (!ptr && size) |
581 | { |
596 | { |
|
|
597 | #if EV_AVOID_STDIO |
|
|
598 | ev_printerr ("libev: memory allocation failed, aborting.\n"); |
|
|
599 | #else |
582 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
600 | fprintf (stderr, "libev: cannot allocate %ld bytes, aborting.", size); |
|
|
601 | #endif |
583 | abort (); |
602 | abort (); |
584 | } |
603 | } |
585 | |
604 | |
586 | return ptr; |
605 | return ptr; |
587 | } |
606 | } |
… | |
… | |
669 | |
688 | |
670 | static int ev_default_loop_ptr; |
689 | static int ev_default_loop_ptr; |
671 | |
690 | |
672 | #endif |
691 | #endif |
673 | |
692 | |
674 | #if EV_MINIMAL < 2 |
693 | #if EV_FEATURE_API |
675 | # 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) |
676 | # 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) |
677 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
696 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
678 | #else |
697 | #else |
679 | # define EV_RELEASE_CB (void)0 |
698 | # define EV_RELEASE_CB (void)0 |
… | |
… | |
864 | } |
883 | } |
865 | |
884 | |
866 | /*****************************************************************************/ |
885 | /*****************************************************************************/ |
867 | |
886 | |
868 | inline_speed void |
887 | inline_speed void |
869 | fd_event_nc (EV_P_ int fd, int revents) |
888 | fd_event_nocheck (EV_P_ int fd, int revents) |
870 | { |
889 | { |
871 | ANFD *anfd = anfds + fd; |
890 | ANFD *anfd = anfds + fd; |
872 | ev_io *w; |
891 | ev_io *w; |
873 | |
892 | |
874 | 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) |
… | |
… | |
886 | fd_event (EV_P_ int fd, int revents) |
905 | fd_event (EV_P_ int fd, int revents) |
887 | { |
906 | { |
888 | ANFD *anfd = anfds + fd; |
907 | ANFD *anfd = anfds + fd; |
889 | |
908 | |
890 | if (expect_true (!anfd->reify)) |
909 | if (expect_true (!anfd->reify)) |
891 | fd_event_nc (EV_A_ fd, revents); |
910 | fd_event_nocheck (EV_A_ fd, revents); |
892 | } |
911 | } |
893 | |
912 | |
894 | void |
913 | void |
895 | ev_feed_fd_event (EV_P_ int fd, int revents) |
914 | ev_feed_fd_event (EV_P_ int fd, int revents) |
896 | { |
915 | { |
897 | if (fd >= 0 && fd < anfdmax) |
916 | if (fd >= 0 && fd < anfdmax) |
898 | fd_event_nc (EV_A_ fd, revents); |
917 | fd_event_nocheck (EV_A_ fd, revents); |
899 | } |
918 | } |
900 | |
919 | |
901 | /* make sure the external fd watch events are in-sync */ |
920 | /* make sure the external fd watch events are in-sync */ |
902 | /* with the kernel/libev internal state */ |
921 | /* with the kernel/libev internal state */ |
903 | inline_size void |
922 | inline_size void |
… | |
… | |
966 | ev_io_stop (EV_A_ w); |
985 | ev_io_stop (EV_A_ w); |
967 | 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); |
968 | } |
987 | } |
969 | } |
988 | } |
970 | |
989 | |
971 | /* check whether the given fd is atcually valid, for error recovery */ |
990 | /* check whether the given fd is actually valid, for error recovery */ |
972 | inline_size int |
991 | inline_size int |
973 | fd_valid (int fd) |
992 | fd_valid (int fd) |
974 | { |
993 | { |
975 | #ifdef _WIN32 |
994 | #ifdef _WIN32 |
976 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
995 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
… | |
… | |
1016 | { |
1035 | { |
1017 | anfds [fd].events = 0; |
1036 | anfds [fd].events = 0; |
1018 | anfds [fd].emask = 0; |
1037 | anfds [fd].emask = 0; |
1019 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1038 | fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY); |
1020 | } |
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 |
1021 | } |
1054 | } |
1022 | |
1055 | |
1023 | /*****************************************************************************/ |
1056 | /*****************************************************************************/ |
1024 | |
1057 | |
1025 | /* |
1058 | /* |
… | |
… | |
1179 | |
1212 | |
1180 | static ANSIG signals [EV_NSIG - 1]; |
1213 | static ANSIG signals [EV_NSIG - 1]; |
1181 | |
1214 | |
1182 | /*****************************************************************************/ |
1215 | /*****************************************************************************/ |
1183 | |
1216 | |
1184 | /* used to prepare libev internal fd's */ |
1217 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1185 | /* this is not fork-safe */ |
|
|
1186 | inline_speed void |
|
|
1187 | fd_intern (int fd) |
|
|
1188 | { |
|
|
1189 | #ifdef _WIN32 |
|
|
1190 | unsigned long arg = 1; |
|
|
1191 | ioctlsocket (EV_FD_TO_WIN32_HANDLE (fd), FIONBIO, &arg); |
|
|
1192 | #else |
|
|
1193 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
1194 | fcntl (fd, F_SETFL, O_NONBLOCK); |
|
|
1195 | #endif |
|
|
1196 | } |
|
|
1197 | |
1218 | |
1198 | static void noinline |
1219 | static void noinline |
1199 | evpipe_init (EV_P) |
1220 | evpipe_init (EV_P) |
1200 | { |
1221 | { |
1201 | if (!ev_is_active (&pipe_w)) |
1222 | if (!ev_is_active (&pipe_w)) |
1202 | { |
1223 | { |
1203 | #if EV_USE_EVENTFD |
1224 | # if EV_USE_EVENTFD |
1204 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1225 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1205 | if (evfd < 0 && errno == EINVAL) |
1226 | if (evfd < 0 && errno == EINVAL) |
1206 | evfd = eventfd (0, 0); |
1227 | evfd = eventfd (0, 0); |
1207 | |
1228 | |
1208 | if (evfd >= 0) |
1229 | if (evfd >= 0) |
… | |
… | |
1210 | evpipe [0] = -1; |
1231 | evpipe [0] = -1; |
1211 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1232 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
1212 | ev_io_set (&pipe_w, evfd, EV_READ); |
1233 | ev_io_set (&pipe_w, evfd, EV_READ); |
1213 | } |
1234 | } |
1214 | else |
1235 | else |
1215 | #endif |
1236 | # endif |
1216 | { |
1237 | { |
1217 | while (pipe (evpipe)) |
1238 | while (pipe (evpipe)) |
1218 | ev_syserr ("(libev) error creating signal/async pipe"); |
1239 | ev_syserr ("(libev) error creating signal/async pipe"); |
1219 | |
1240 | |
1220 | fd_intern (evpipe [0]); |
1241 | fd_intern (evpipe [0]); |
… | |
… | |
1231 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1252 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1232 | { |
1253 | { |
1233 | if (!*flag) |
1254 | if (!*flag) |
1234 | { |
1255 | { |
1235 | 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; |
1236 | |
1258 | |
1237 | *flag = 1; |
1259 | *flag = 1; |
1238 | |
1260 | |
1239 | #if EV_USE_EVENTFD |
1261 | #if EV_USE_EVENTFD |
1240 | if (evfd >= 0) |
1262 | if (evfd >= 0) |
… | |
… | |
1242 | uint64_t counter = 1; |
1264 | uint64_t counter = 1; |
1243 | write (evfd, &counter, sizeof (uint64_t)); |
1265 | write (evfd, &counter, sizeof (uint64_t)); |
1244 | } |
1266 | } |
1245 | else |
1267 | else |
1246 | #endif |
1268 | #endif |
1247 | write (evpipe [1], &old_errno, 1); |
1269 | write (evpipe [1], &dummy, 1); |
1248 | |
1270 | |
1249 | errno = old_errno; |
1271 | errno = old_errno; |
1250 | } |
1272 | } |
1251 | } |
1273 | } |
1252 | |
1274 | |
… | |
… | |
1353 | break; |
1375 | break; |
1354 | } |
1376 | } |
1355 | } |
1377 | } |
1356 | #endif |
1378 | #endif |
1357 | |
1379 | |
|
|
1380 | #endif |
|
|
1381 | |
1358 | /*****************************************************************************/ |
1382 | /*****************************************************************************/ |
1359 | |
1383 | |
|
|
1384 | #if EV_CHILD_ENABLE |
1360 | static WL childs [EV_PID_HASHSIZE]; |
1385 | static WL childs [EV_PID_HASHSIZE]; |
1361 | |
|
|
1362 | #ifndef _WIN32 |
|
|
1363 | |
1386 | |
1364 | static ev_signal childev; |
1387 | static ev_signal childev; |
1365 | |
1388 | |
1366 | #ifndef WIFCONTINUED |
1389 | #ifndef WIFCONTINUED |
1367 | # define WIFCONTINUED(status) 0 |
1390 | # define WIFCONTINUED(status) 0 |
… | |
… | |
1372 | child_reap (EV_P_ int chain, int pid, int status) |
1395 | child_reap (EV_P_ int chain, int pid, int status) |
1373 | { |
1396 | { |
1374 | ev_child *w; |
1397 | ev_child *w; |
1375 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1398 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1376 | |
1399 | |
1377 | 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) |
1378 | { |
1401 | { |
1379 | if ((w->pid == pid || !w->pid) |
1402 | if ((w->pid == pid || !w->pid) |
1380 | && (!traced || (w->flags & 1))) |
1403 | && (!traced || (w->flags & 1))) |
1381 | { |
1404 | { |
1382 | 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 */ |
… | |
… | |
1407 | /* 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 */ |
1408 | /* 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 */ |
1409 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1432 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
1410 | |
1433 | |
1411 | child_reap (EV_A_ pid, pid, status); |
1434 | child_reap (EV_A_ pid, pid, status); |
1412 | if (EV_PID_HASHSIZE > 1) |
1435 | if ((EV_PID_HASHSIZE) > 1) |
1413 | 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 */ |
1414 | } |
1437 | } |
1415 | |
1438 | |
1416 | #endif |
1439 | #endif |
1417 | |
1440 | |
… | |
… | |
1506 | ev_backend (EV_P) |
1529 | ev_backend (EV_P) |
1507 | { |
1530 | { |
1508 | return backend; |
1531 | return backend; |
1509 | } |
1532 | } |
1510 | |
1533 | |
1511 | #if EV_MINIMAL < 2 |
1534 | #if EV_FEATURE_API |
1512 | unsigned int |
1535 | unsigned int |
1513 | ev_loop_count (EV_P) |
1536 | ev_loop_count (EV_P) |
1514 | { |
1537 | { |
1515 | return loop_count; |
1538 | return loop_count; |
1516 | } |
1539 | } |
… | |
… | |
1596 | |
1619 | |
1597 | ev_rt_now = ev_time (); |
1620 | ev_rt_now = ev_time (); |
1598 | mn_now = get_clock (); |
1621 | mn_now = get_clock (); |
1599 | now_floor = mn_now; |
1622 | now_floor = mn_now; |
1600 | rtmn_diff = ev_rt_now - mn_now; |
1623 | rtmn_diff = ev_rt_now - mn_now; |
1601 | #if EV_MINIMAL < 2 |
1624 | #if EV_FEATURE_API |
1602 | invoke_cb = ev_invoke_pending; |
1625 | invoke_cb = ev_invoke_pending; |
1603 | #endif |
1626 | #endif |
1604 | |
1627 | |
1605 | io_blocktime = 0.; |
1628 | io_blocktime = 0.; |
1606 | timeout_blocktime = 0.; |
1629 | timeout_blocktime = 0.; |
… | |
… | |
1636 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1659 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1637 | #endif |
1660 | #endif |
1638 | |
1661 | |
1639 | ev_prepare_init (&pending_w, pendingcb); |
1662 | ev_prepare_init (&pending_w, pendingcb); |
1640 | |
1663 | |
|
|
1664 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1641 | ev_init (&pipe_w, pipecb); |
1665 | ev_init (&pipe_w, pipecb); |
1642 | ev_set_priority (&pipe_w, EV_MAXPRI); |
1666 | ev_set_priority (&pipe_w, EV_MAXPRI); |
|
|
1667 | #endif |
1643 | } |
1668 | } |
1644 | } |
1669 | } |
1645 | |
1670 | |
1646 | /* free up a loop structure */ |
1671 | /* free up a loop structure */ |
1647 | static void noinline |
1672 | static void noinline |
… | |
… | |
1765 | { |
1790 | { |
1766 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1791 | EV_WIN32_CLOSE_FD (evpipe [0]); |
1767 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1792 | EV_WIN32_CLOSE_FD (evpipe [1]); |
1768 | } |
1793 | } |
1769 | |
1794 | |
|
|
1795 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
1770 | evpipe_init (EV_A); |
1796 | evpipe_init (EV_A); |
1771 | /* now iterate over everything, in case we missed something */ |
1797 | /* now iterate over everything, in case we missed something */ |
1772 | pipecb (EV_A_ &pipe_w, EV_READ); |
1798 | pipecb (EV_A_ &pipe_w, EV_READ); |
|
|
1799 | #endif |
1773 | } |
1800 | } |
1774 | |
1801 | |
1775 | postfork = 0; |
1802 | postfork = 0; |
1776 | } |
1803 | } |
1777 | |
1804 | |
… | |
… | |
1839 | verify_watcher (EV_A_ ws [cnt]); |
1866 | verify_watcher (EV_A_ ws [cnt]); |
1840 | } |
1867 | } |
1841 | } |
1868 | } |
1842 | #endif |
1869 | #endif |
1843 | |
1870 | |
1844 | #if EV_MINIMAL < 2 |
1871 | #if EV_FEATURE_API |
1845 | void |
1872 | void |
1846 | ev_loop_verify (EV_P) |
1873 | ev_loop_verify (EV_P) |
1847 | { |
1874 | { |
1848 | #if EV_VERIFY |
1875 | #if EV_VERIFY |
1849 | int i; |
1876 | int i; |
… | |
… | |
1890 | #if EV_ASYNC_ENABLE |
1917 | #if EV_ASYNC_ENABLE |
1891 | assert (asyncmax >= asynccnt); |
1918 | assert (asyncmax >= asynccnt); |
1892 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1919 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
1893 | #endif |
1920 | #endif |
1894 | |
1921 | |
|
|
1922 | #if EV_PREPARE_ENABLE |
1895 | assert (preparemax >= preparecnt); |
1923 | assert (preparemax >= preparecnt); |
1896 | array_verify (EV_A_ (W *)prepares, preparecnt); |
1924 | array_verify (EV_A_ (W *)prepares, preparecnt); |
|
|
1925 | #endif |
1897 | |
1926 | |
|
|
1927 | #if EV_CHECK_ENABLE |
1898 | assert (checkmax >= checkcnt); |
1928 | assert (checkmax >= checkcnt); |
1899 | array_verify (EV_A_ (W *)checks, checkcnt); |
1929 | array_verify (EV_A_ (W *)checks, checkcnt); |
|
|
1930 | #endif |
1900 | |
1931 | |
1901 | # if 0 |
1932 | # if 0 |
|
|
1933 | #if EV_CHILD_ENABLE |
1902 | 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) |
1903 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
1935 | for (signum = EV_NSIG; signum--; ) if (signals [signum].pending) |
|
|
1936 | #endif |
1904 | # endif |
1937 | # endif |
1905 | #endif |
1938 | #endif |
1906 | } |
1939 | } |
1907 | #endif |
1940 | #endif |
1908 | |
1941 | |
… | |
… | |
1924 | |
1957 | |
1925 | loop_init (EV_A_ flags); |
1958 | loop_init (EV_A_ flags); |
1926 | |
1959 | |
1927 | if (ev_backend (EV_A)) |
1960 | if (ev_backend (EV_A)) |
1928 | { |
1961 | { |
1929 | #ifndef _WIN32 |
1962 | #if EV_CHILD_ENABLE |
1930 | ev_signal_init (&childev, childcb, SIGCHLD); |
1963 | ev_signal_init (&childev, childcb, SIGCHLD); |
1931 | ev_set_priority (&childev, EV_MAXPRI); |
1964 | ev_set_priority (&childev, EV_MAXPRI); |
1932 | ev_signal_start (EV_A_ &childev); |
1965 | ev_signal_start (EV_A_ &childev); |
1933 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1966 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
1934 | #endif |
1967 | #endif |
… | |
… | |
1947 | EV_P = ev_default_loop_ptr; |
1980 | EV_P = ev_default_loop_ptr; |
1948 | #endif |
1981 | #endif |
1949 | |
1982 | |
1950 | ev_default_loop_ptr = 0; |
1983 | ev_default_loop_ptr = 0; |
1951 | |
1984 | |
1952 | #ifndef _WIN32 |
1985 | #if EV_CHILD_ENABLE |
1953 | ev_ref (EV_A); /* child watcher */ |
1986 | ev_ref (EV_A); /* child watcher */ |
1954 | ev_signal_stop (EV_A_ &childev); |
1987 | ev_signal_stop (EV_A_ &childev); |
1955 | #endif |
1988 | #endif |
1956 | |
1989 | |
1957 | loop_destroy (EV_A); |
1990 | loop_destroy (EV_A); |
… | |
… | |
2234 | } |
2267 | } |
2235 | |
2268 | |
2236 | void |
2269 | void |
2237 | ev_loop (EV_P_ int flags) |
2270 | ev_loop (EV_P_ int flags) |
2238 | { |
2271 | { |
2239 | #if EV_MINIMAL < 2 |
2272 | #if EV_FEATURE_API |
2240 | ++loop_depth; |
2273 | ++loop_depth; |
2241 | #endif |
2274 | #endif |
2242 | |
2275 | |
2243 | 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)); |
2244 | |
2277 | |
… | |
… | |
2269 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2302 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2270 | EV_INVOKE_PENDING; |
2303 | EV_INVOKE_PENDING; |
2271 | } |
2304 | } |
2272 | #endif |
2305 | #endif |
2273 | |
2306 | |
|
|
2307 | #if EV_PREPARE_ENABLE |
2274 | /* queue prepare watchers (and execute them) */ |
2308 | /* queue prepare watchers (and execute them) */ |
2275 | if (expect_false (preparecnt)) |
2309 | if (expect_false (preparecnt)) |
2276 | { |
2310 | { |
2277 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2311 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2278 | EV_INVOKE_PENDING; |
2312 | EV_INVOKE_PENDING; |
2279 | } |
2313 | } |
|
|
2314 | #endif |
2280 | |
2315 | |
2281 | if (expect_false (loop_done)) |
2316 | if (expect_false (loop_done)) |
2282 | break; |
2317 | break; |
2283 | |
2318 | |
2284 | /* we might have forked, so reify kernel state if necessary */ |
2319 | /* we might have forked, so reify kernel state if necessary */ |
… | |
… | |
2335 | waittime -= sleeptime; |
2370 | waittime -= sleeptime; |
2336 | } |
2371 | } |
2337 | } |
2372 | } |
2338 | } |
2373 | } |
2339 | |
2374 | |
2340 | #if EV_MINIMAL < 2 |
2375 | #if EV_FEATURE_API |
2341 | ++loop_count; |
2376 | ++loop_count; |
2342 | #endif |
2377 | #endif |
2343 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2378 | assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */ |
2344 | backend_poll (EV_A_ waittime); |
2379 | backend_poll (EV_A_ waittime); |
2345 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
2380 | assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */ |
… | |
… | |
2357 | #if EV_IDLE_ENABLE |
2392 | #if EV_IDLE_ENABLE |
2358 | /* queue idle watchers unless other events are pending */ |
2393 | /* queue idle watchers unless other events are pending */ |
2359 | idle_reify (EV_A); |
2394 | idle_reify (EV_A); |
2360 | #endif |
2395 | #endif |
2361 | |
2396 | |
|
|
2397 | #if EV_CHECK_ENABLE |
2362 | /* queue check watchers, to be executed first */ |
2398 | /* queue check watchers, to be executed first */ |
2363 | if (expect_false (checkcnt)) |
2399 | if (expect_false (checkcnt)) |
2364 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
2400 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
|
|
2401 | #endif |
2365 | |
2402 | |
2366 | EV_INVOKE_PENDING; |
2403 | EV_INVOKE_PENDING; |
2367 | } |
2404 | } |
2368 | while (expect_true ( |
2405 | while (expect_true ( |
2369 | activecnt |
2406 | activecnt |
… | |
… | |
2372 | )); |
2409 | )); |
2373 | |
2410 | |
2374 | if (loop_done == EVUNLOOP_ONE) |
2411 | if (loop_done == EVUNLOOP_ONE) |
2375 | loop_done = EVUNLOOP_CANCEL; |
2412 | loop_done = EVUNLOOP_CANCEL; |
2376 | |
2413 | |
2377 | #if EV_MINIMAL < 2 |
2414 | #if EV_FEATURE_API |
2378 | --loop_depth; |
2415 | --loop_depth; |
2379 | #endif |
2416 | #endif |
2380 | } |
2417 | } |
2381 | |
2418 | |
2382 | void |
2419 | void |
… | |
… | |
2588 | timers [active] = timers [timercnt + HEAP0]; |
2625 | timers [active] = timers [timercnt + HEAP0]; |
2589 | adjustheap (timers, timercnt, active); |
2626 | adjustheap (timers, timercnt, active); |
2590 | } |
2627 | } |
2591 | } |
2628 | } |
2592 | |
2629 | |
2593 | EV_FREQUENT_CHECK; |
|
|
2594 | |
|
|
2595 | ev_at (w) -= mn_now; |
2630 | ev_at (w) -= mn_now; |
2596 | |
2631 | |
2597 | ev_stop (EV_A_ (W)w); |
2632 | ev_stop (EV_A_ (W)w); |
|
|
2633 | |
|
|
2634 | EV_FREQUENT_CHECK; |
2598 | } |
2635 | } |
2599 | |
2636 | |
2600 | void noinline |
2637 | void noinline |
2601 | ev_timer_again (EV_P_ ev_timer *w) |
2638 | ev_timer_again (EV_P_ ev_timer *w) |
2602 | { |
2639 | { |
… | |
… | |
2681 | periodics [active] = periodics [periodiccnt + HEAP0]; |
2718 | periodics [active] = periodics [periodiccnt + HEAP0]; |
2682 | adjustheap (periodics, periodiccnt, active); |
2719 | adjustheap (periodics, periodiccnt, active); |
2683 | } |
2720 | } |
2684 | } |
2721 | } |
2685 | |
2722 | |
2686 | EV_FREQUENT_CHECK; |
|
|
2687 | |
|
|
2688 | ev_stop (EV_A_ (W)w); |
2723 | ev_stop (EV_A_ (W)w); |
|
|
2724 | |
|
|
2725 | EV_FREQUENT_CHECK; |
2689 | } |
2726 | } |
2690 | |
2727 | |
2691 | void noinline |
2728 | void noinline |
2692 | ev_periodic_again (EV_P_ ev_periodic *w) |
2729 | ev_periodic_again (EV_P_ ev_periodic *w) |
2693 | { |
2730 | { |
… | |
… | |
2698 | #endif |
2735 | #endif |
2699 | |
2736 | |
2700 | #ifndef SA_RESTART |
2737 | #ifndef SA_RESTART |
2701 | # define SA_RESTART 0 |
2738 | # define SA_RESTART 0 |
2702 | #endif |
2739 | #endif |
|
|
2740 | |
|
|
2741 | #if EV_SIGNAL_ENABLE |
2703 | |
2742 | |
2704 | void noinline |
2743 | void noinline |
2705 | ev_signal_start (EV_P_ ev_signal *w) |
2744 | ev_signal_start (EV_P_ ev_signal *w) |
2706 | { |
2745 | { |
2707 | if (expect_false (ev_is_active (w))) |
2746 | if (expect_false (ev_is_active (w))) |
… | |
… | |
2814 | } |
2853 | } |
2815 | |
2854 | |
2816 | EV_FREQUENT_CHECK; |
2855 | EV_FREQUENT_CHECK; |
2817 | } |
2856 | } |
2818 | |
2857 | |
|
|
2858 | #endif |
|
|
2859 | |
|
|
2860 | #if EV_CHILD_ENABLE |
|
|
2861 | |
2819 | void |
2862 | void |
2820 | ev_child_start (EV_P_ ev_child *w) |
2863 | ev_child_start (EV_P_ ev_child *w) |
2821 | { |
2864 | { |
2822 | #if EV_MULTIPLICITY |
2865 | #if EV_MULTIPLICITY |
2823 | 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)); |
… | |
… | |
2826 | return; |
2869 | return; |
2827 | |
2870 | |
2828 | EV_FREQUENT_CHECK; |
2871 | EV_FREQUENT_CHECK; |
2829 | |
2872 | |
2830 | ev_start (EV_A_ (W)w, 1); |
2873 | ev_start (EV_A_ (W)w, 1); |
2831 | wlist_add (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2874 | wlist_add (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2832 | |
2875 | |
2833 | EV_FREQUENT_CHECK; |
2876 | EV_FREQUENT_CHECK; |
2834 | } |
2877 | } |
2835 | |
2878 | |
2836 | void |
2879 | void |
… | |
… | |
2840 | if (expect_false (!ev_is_active (w))) |
2883 | if (expect_false (!ev_is_active (w))) |
2841 | return; |
2884 | return; |
2842 | |
2885 | |
2843 | EV_FREQUENT_CHECK; |
2886 | EV_FREQUENT_CHECK; |
2844 | |
2887 | |
2845 | wlist_del (&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
2888 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
2846 | ev_stop (EV_A_ (W)w); |
2889 | ev_stop (EV_A_ (W)w); |
2847 | |
2890 | |
2848 | EV_FREQUENT_CHECK; |
2891 | EV_FREQUENT_CHECK; |
2849 | } |
2892 | } |
|
|
2893 | |
|
|
2894 | #endif |
2850 | |
2895 | |
2851 | #if EV_STAT_ENABLE |
2896 | #if EV_STAT_ENABLE |
2852 | |
2897 | |
2853 | # ifdef _WIN32 |
2898 | # ifdef _WIN32 |
2854 | # undef lstat |
2899 | # undef lstat |
… | |
… | |
2921 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2966 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2922 | } |
2967 | } |
2923 | } |
2968 | } |
2924 | |
2969 | |
2925 | if (w->wd >= 0) |
2970 | if (w->wd >= 0) |
2926 | 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); |
2927 | |
2972 | |
2928 | /* now re-arm timer, if required */ |
2973 | /* now re-arm timer, if required */ |
2929 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2974 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2930 | ev_timer_again (EV_A_ &w->timer); |
2975 | ev_timer_again (EV_A_ &w->timer); |
2931 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
2976 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
… | |
… | |
2939 | |
2984 | |
2940 | if (wd < 0) |
2985 | if (wd < 0) |
2941 | return; |
2986 | return; |
2942 | |
2987 | |
2943 | w->wd = -2; |
2988 | w->wd = -2; |
2944 | slot = wd & (EV_INOTIFY_HASHSIZE - 1); |
2989 | slot = wd & ((EV_INOTIFY_HASHSIZE) - 1); |
2945 | wlist_del (&fs_hash [slot].head, (WL)w); |
2990 | wlist_del (&fs_hash [slot].head, (WL)w); |
2946 | |
2991 | |
2947 | /* remove this watcher, if others are watching it, they will rearm */ |
2992 | /* remove this watcher, if others are watching it, they will rearm */ |
2948 | inotify_rm_watch (fs_fd, wd); |
2993 | inotify_rm_watch (fs_fd, wd); |
2949 | } |
2994 | } |
… | |
… | |
2951 | static void noinline |
2996 | static void noinline |
2952 | 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) |
2953 | { |
2998 | { |
2954 | if (slot < 0) |
2999 | if (slot < 0) |
2955 | /* overflow, need to check for all hash slots */ |
3000 | /* overflow, need to check for all hash slots */ |
2956 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3001 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
2957 | infy_wd (EV_A_ slot, wd, ev); |
3002 | infy_wd (EV_A_ slot, wd, ev); |
2958 | else |
3003 | else |
2959 | { |
3004 | { |
2960 | WL w_; |
3005 | WL w_; |
2961 | |
3006 | |
2962 | for (w_ = fs_hash [slot & (EV_INOTIFY_HASHSIZE - 1)].head; w_; ) |
3007 | for (w_ = fs_hash [slot & ((EV_INOTIFY_HASHSIZE) - 1)].head; w_; ) |
2963 | { |
3008 | { |
2964 | ev_stat *w = (ev_stat *)w_; |
3009 | ev_stat *w = (ev_stat *)w_; |
2965 | 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 */ |
2966 | |
3011 | |
2967 | if (w->wd == wd || wd == -1) |
3012 | if (w->wd == wd || wd == -1) |
2968 | { |
3013 | { |
2969 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
3014 | if (ev->mask & (IN_IGNORED | IN_UNMOUNT | IN_DELETE_SELF)) |
2970 | { |
3015 | { |
2971 | 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); |
2972 | w->wd = -1; |
3017 | w->wd = -1; |
2973 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3018 | infy_add (EV_A_ w); /* re-add, no matter what */ |
2974 | } |
3019 | } |
2975 | |
3020 | |
2976 | stat_timer_cb (EV_A_ &w->timer, 0); |
3021 | stat_timer_cb (EV_A_ &w->timer, 0); |
… | |
… | |
2992 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
3037 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
2993 | ofs += sizeof (struct inotify_event) + ev->len; |
3038 | ofs += sizeof (struct inotify_event) + ev->len; |
2994 | } |
3039 | } |
2995 | } |
3040 | } |
2996 | |
3041 | |
|
|
3042 | inline_size unsigned int |
|
|
3043 | ev_linux_version (void) |
|
|
3044 | { |
|
|
3045 | struct utsname buf; |
|
|
3046 | unsigned int v; |
|
|
3047 | int i; |
|
|
3048 | char *p = buf.release; |
|
|
3049 | |
|
|
3050 | if (uname (&buf)) |
|
|
3051 | return 0; |
|
|
3052 | |
|
|
3053 | for (i = 3+1; --i; ) |
|
|
3054 | { |
|
|
3055 | unsigned int c = 0; |
|
|
3056 | |
|
|
3057 | for (;;) |
|
|
3058 | { |
|
|
3059 | if (*p >= '0' && *p <= '9') |
|
|
3060 | c = c * 10 + *p++ - '0'; |
|
|
3061 | else |
|
|
3062 | { |
|
|
3063 | p += *p == '.'; |
|
|
3064 | break; |
|
|
3065 | } |
|
|
3066 | } |
|
|
3067 | |
|
|
3068 | v = (v << 8) | c; |
|
|
3069 | } |
|
|
3070 | |
|
|
3071 | return v; |
|
|
3072 | } |
|
|
3073 | |
2997 | inline_size void |
3074 | inline_size void |
2998 | check_2625 (EV_P) |
3075 | ev_check_2625 (EV_P) |
2999 | { |
3076 | { |
3000 | /* kernels < 2.6.25 are borked |
3077 | /* kernels < 2.6.25 are borked |
3001 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
3078 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
3002 | */ |
3079 | */ |
3003 | struct utsname buf; |
3080 | if (ev_linux_version () < 0x020619) |
3004 | int major, minor, micro; |
|
|
3005 | |
|
|
3006 | if (uname (&buf)) |
|
|
3007 | return; |
|
|
3008 | |
|
|
3009 | if (sscanf (buf.release, "%d.%d.%d", &major, &minor, µ) != 3) |
|
|
3010 | return; |
|
|
3011 | |
|
|
3012 | if (major < 2 |
|
|
3013 | || (major == 2 && minor < 6) |
|
|
3014 | || (major == 2 && minor == 6 && micro < 25)) |
|
|
3015 | return; |
3081 | return; |
3016 | |
3082 | |
3017 | fs_2625 = 1; |
3083 | fs_2625 = 1; |
3018 | } |
3084 | } |
3019 | |
3085 | |
… | |
… | |
3034 | if (fs_fd != -2) |
3100 | if (fs_fd != -2) |
3035 | return; |
3101 | return; |
3036 | |
3102 | |
3037 | fs_fd = -1; |
3103 | fs_fd = -1; |
3038 | |
3104 | |
3039 | check_2625 (EV_A); |
3105 | ev_check_2625 (EV_A); |
3040 | |
3106 | |
3041 | fs_fd = infy_newfd (); |
3107 | fs_fd = infy_newfd (); |
3042 | |
3108 | |
3043 | if (fs_fd >= 0) |
3109 | if (fs_fd >= 0) |
3044 | { |
3110 | { |
… | |
… | |
3069 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3135 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3070 | ev_io_start (EV_A_ &fs_w); |
3136 | ev_io_start (EV_A_ &fs_w); |
3071 | ev_unref (EV_A); |
3137 | ev_unref (EV_A); |
3072 | } |
3138 | } |
3073 | |
3139 | |
3074 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3140 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
3075 | { |
3141 | { |
3076 | WL w_ = fs_hash [slot].head; |
3142 | WL w_ = fs_hash [slot].head; |
3077 | fs_hash [slot].head = 0; |
3143 | fs_hash [slot].head = 0; |
3078 | |
3144 | |
3079 | while (w_) |
3145 | while (w_) |
… | |
… | |
3254 | |
3320 | |
3255 | EV_FREQUENT_CHECK; |
3321 | EV_FREQUENT_CHECK; |
3256 | } |
3322 | } |
3257 | #endif |
3323 | #endif |
3258 | |
3324 | |
|
|
3325 | #if EV_PREPARE_ENABLE |
3259 | void |
3326 | void |
3260 | ev_prepare_start (EV_P_ ev_prepare *w) |
3327 | ev_prepare_start (EV_P_ ev_prepare *w) |
3261 | { |
3328 | { |
3262 | if (expect_false (ev_is_active (w))) |
3329 | if (expect_false (ev_is_active (w))) |
3263 | return; |
3330 | return; |
… | |
… | |
3289 | |
3356 | |
3290 | ev_stop (EV_A_ (W)w); |
3357 | ev_stop (EV_A_ (W)w); |
3291 | |
3358 | |
3292 | EV_FREQUENT_CHECK; |
3359 | EV_FREQUENT_CHECK; |
3293 | } |
3360 | } |
|
|
3361 | #endif |
3294 | |
3362 | |
|
|
3363 | #if EV_CHECK_ENABLE |
3295 | void |
3364 | void |
3296 | ev_check_start (EV_P_ ev_check *w) |
3365 | ev_check_start (EV_P_ ev_check *w) |
3297 | { |
3366 | { |
3298 | if (expect_false (ev_is_active (w))) |
3367 | if (expect_false (ev_is_active (w))) |
3299 | return; |
3368 | return; |
… | |
… | |
3325 | |
3394 | |
3326 | ev_stop (EV_A_ (W)w); |
3395 | ev_stop (EV_A_ (W)w); |
3327 | |
3396 | |
3328 | EV_FREQUENT_CHECK; |
3397 | EV_FREQUENT_CHECK; |
3329 | } |
3398 | } |
|
|
3399 | #endif |
3330 | |
3400 | |
3331 | #if EV_EMBED_ENABLE |
3401 | #if EV_EMBED_ENABLE |
3332 | void noinline |
3402 | void noinline |
3333 | ev_embed_sweep (EV_P_ ev_embed *w) |
3403 | ev_embed_sweep (EV_P_ ev_embed *w) |
3334 | { |
3404 | { |
… | |
… | |
3428 | EV_FREQUENT_CHECK; |
3498 | EV_FREQUENT_CHECK; |
3429 | |
3499 | |
3430 | ev_io_stop (EV_A_ &w->io); |
3500 | ev_io_stop (EV_A_ &w->io); |
3431 | ev_prepare_stop (EV_A_ &w->prepare); |
3501 | ev_prepare_stop (EV_A_ &w->prepare); |
3432 | ev_fork_stop (EV_A_ &w->fork); |
3502 | ev_fork_stop (EV_A_ &w->fork); |
|
|
3503 | |
|
|
3504 | ev_stop (EV_A_ (W)w); |
3433 | |
3505 | |
3434 | EV_FREQUENT_CHECK; |
3506 | EV_FREQUENT_CHECK; |
3435 | } |
3507 | } |
3436 | #endif |
3508 | #endif |
3437 | |
3509 | |
… | |
… | |
3661 | if (types & EV_ASYNC) |
3733 | if (types & EV_ASYNC) |
3662 | for (i = asynccnt; i--; ) |
3734 | for (i = asynccnt; i--; ) |
3663 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3735 | cb (EV_A_ EV_ASYNC, asyncs [i]); |
3664 | #endif |
3736 | #endif |
3665 | |
3737 | |
|
|
3738 | #if EV_PREPARE_ENABLE |
3666 | if (types & EV_PREPARE) |
3739 | if (types & EV_PREPARE) |
3667 | for (i = preparecnt; i--; ) |
3740 | for (i = preparecnt; i--; ) |
3668 | #if EV_EMBED_ENABLE |
3741 | # if EV_EMBED_ENABLE |
3669 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3742 | if (ev_cb (prepares [i]) != embed_prepare_cb) |
3670 | #endif |
3743 | # endif |
3671 | cb (EV_A_ EV_PREPARE, prepares [i]); |
3744 | cb (EV_A_ EV_PREPARE, prepares [i]); |
|
|
3745 | #endif |
3672 | |
3746 | |
|
|
3747 | #if EV_CHECK_ENABLE |
3673 | if (types & EV_CHECK) |
3748 | if (types & EV_CHECK) |
3674 | for (i = checkcnt; i--; ) |
3749 | for (i = checkcnt; i--; ) |
3675 | cb (EV_A_ EV_CHECK, checks [i]); |
3750 | cb (EV_A_ EV_CHECK, checks [i]); |
|
|
3751 | #endif |
3676 | |
3752 | |
|
|
3753 | #if EV_SIGNAL_ENABLE |
3677 | if (types & EV_SIGNAL) |
3754 | if (types & EV_SIGNAL) |
3678 | for (i = 0; i < EV_NSIG - 1; ++i) |
3755 | for (i = 0; i < EV_NSIG - 1; ++i) |
3679 | for (wl = signals [i].head; wl; ) |
3756 | for (wl = signals [i].head; wl; ) |
3680 | { |
3757 | { |
3681 | wn = wl->next; |
3758 | wn = wl->next; |
3682 | cb (EV_A_ EV_SIGNAL, wl); |
3759 | cb (EV_A_ EV_SIGNAL, wl); |
3683 | wl = wn; |
3760 | wl = wn; |
3684 | } |
3761 | } |
|
|
3762 | #endif |
3685 | |
3763 | |
|
|
3764 | #if EV_CHILD_ENABLE |
3686 | if (types & EV_CHILD) |
3765 | if (types & EV_CHILD) |
3687 | for (i = EV_PID_HASHSIZE; i--; ) |
3766 | for (i = (EV_PID_HASHSIZE); i--; ) |
3688 | for (wl = childs [i]; wl; ) |
3767 | for (wl = childs [i]; wl; ) |
3689 | { |
3768 | { |
3690 | wn = wl->next; |
3769 | wn = wl->next; |
3691 | cb (EV_A_ EV_CHILD, wl); |
3770 | cb (EV_A_ EV_CHILD, wl); |
3692 | wl = wn; |
3771 | wl = wn; |
3693 | } |
3772 | } |
|
|
3773 | #endif |
3694 | /* EV_STAT 0x00001000 /* stat data changed */ |
3774 | /* EV_STAT 0x00001000 /* stat data changed */ |
3695 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3775 | /* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ |
3696 | } |
3776 | } |
3697 | #endif |
3777 | #endif |
3698 | |
3778 | |