1 | /* |
1 | /* |
2 | * libev event processing core, watcher management |
2 | * libev event processing core, watcher management |
3 | * |
3 | * |
4 | * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann <libev@schmorp.de> |
4 | * Copyright (c) 2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann <libev@schmorp.de> |
5 | * All rights reserved. |
5 | * All rights reserved. |
6 | * |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
8 | * tion, are permitted provided that the following conditions are met: |
8 | * tion, are permitted provided that the following conditions are met: |
9 | * |
9 | * |
… | |
… | |
59 | # endif |
59 | # endif |
60 | # ifndef EV_USE_MONOTONIC |
60 | # ifndef EV_USE_MONOTONIC |
61 | # define EV_USE_MONOTONIC 1 |
61 | # define EV_USE_MONOTONIC 1 |
62 | # endif |
62 | # endif |
63 | # endif |
63 | # endif |
64 | # elif !defined(EV_USE_CLOCK_SYSCALL) |
64 | # elif !defined EV_USE_CLOCK_SYSCALL |
65 | # define EV_USE_CLOCK_SYSCALL 0 |
65 | # define EV_USE_CLOCK_SYSCALL 0 |
66 | # endif |
66 | # endif |
67 | |
67 | |
68 | # if HAVE_CLOCK_GETTIME |
68 | # if HAVE_CLOCK_GETTIME |
69 | # ifndef EV_USE_MONOTONIC |
69 | # ifndef EV_USE_MONOTONIC |
… | |
… | |
201 | # include <sys/wait.h> |
201 | # include <sys/wait.h> |
202 | # include <unistd.h> |
202 | # include <unistd.h> |
203 | #else |
203 | #else |
204 | # include <io.h> |
204 | # include <io.h> |
205 | # define WIN32_LEAN_AND_MEAN |
205 | # define WIN32_LEAN_AND_MEAN |
|
|
206 | # include <winsock2.h> |
206 | # include <windows.h> |
207 | # include <windows.h> |
207 | # ifndef EV_SELECT_IS_WINSOCKET |
208 | # ifndef EV_SELECT_IS_WINSOCKET |
208 | # define EV_SELECT_IS_WINSOCKET 1 |
209 | # define EV_SELECT_IS_WINSOCKET 1 |
209 | # endif |
210 | # endif |
210 | # undef EV_AVOID_STDIO |
211 | # undef EV_AVOID_STDIO |
… | |
… | |
219 | #define _DARWIN_UNLIMITED_SELECT 1 |
220 | #define _DARWIN_UNLIMITED_SELECT 1 |
220 | |
221 | |
221 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
222 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
222 | |
223 | |
223 | /* try to deduce the maximum number of signals on this platform */ |
224 | /* try to deduce the maximum number of signals on this platform */ |
224 | #if defined (EV_NSIG) |
225 | #if defined EV_NSIG |
225 | /* use what's provided */ |
226 | /* use what's provided */ |
226 | #elif defined (NSIG) |
227 | #elif defined NSIG |
227 | # define EV_NSIG (NSIG) |
228 | # define EV_NSIG (NSIG) |
228 | #elif defined(_NSIG) |
229 | #elif defined _NSIG |
229 | # define EV_NSIG (_NSIG) |
230 | # define EV_NSIG (_NSIG) |
230 | #elif defined (SIGMAX) |
231 | #elif defined SIGMAX |
231 | # define EV_NSIG (SIGMAX+1) |
232 | # define EV_NSIG (SIGMAX+1) |
232 | #elif defined (SIG_MAX) |
233 | #elif defined SIG_MAX |
233 | # define EV_NSIG (SIG_MAX+1) |
234 | # define EV_NSIG (SIG_MAX+1) |
234 | #elif defined (_SIG_MAX) |
235 | #elif defined _SIG_MAX |
235 | # define EV_NSIG (_SIG_MAX+1) |
236 | # define EV_NSIG (_SIG_MAX+1) |
236 | #elif defined (MAXSIG) |
237 | #elif defined MAXSIG |
237 | # define EV_NSIG (MAXSIG+1) |
238 | # define EV_NSIG (MAXSIG+1) |
238 | #elif defined (MAX_SIG) |
239 | #elif defined MAX_SIG |
239 | # define EV_NSIG (MAX_SIG+1) |
240 | # define EV_NSIG (MAX_SIG+1) |
240 | #elif defined (SIGARRAYSIZE) |
241 | #elif defined SIGARRAYSIZE |
241 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
242 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
242 | #elif defined (_sys_nsig) |
243 | #elif defined _sys_nsig |
243 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
244 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
244 | #else |
245 | #else |
245 | # error "unable to find value for NSIG, please report" |
246 | # error "unable to find value for NSIG, please report" |
246 | /* to make it compile regardless, just remove the above line, */ |
247 | /* to make it compile regardless, just remove the above line, */ |
247 | /* but consider reporting it, too! :) */ |
248 | /* but consider reporting it, too! :) */ |
… | |
… | |
259 | # define EV_USE_CLOCK_SYSCALL 0 |
260 | # define EV_USE_CLOCK_SYSCALL 0 |
260 | # endif |
261 | # endif |
261 | #endif |
262 | #endif |
262 | |
263 | |
263 | #ifndef EV_USE_MONOTONIC |
264 | #ifndef EV_USE_MONOTONIC |
264 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
265 | # if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0 |
265 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
266 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
266 | # else |
267 | # else |
267 | # define EV_USE_MONOTONIC 0 |
268 | # define EV_USE_MONOTONIC 0 |
268 | # endif |
269 | # endif |
269 | #endif |
270 | #endif |
… | |
… | |
359 | #endif |
360 | #endif |
360 | |
361 | |
361 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
362 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
362 | /* which makes programs even slower. might work on other unices, too. */ |
363 | /* which makes programs even slower. might work on other unices, too. */ |
363 | #if EV_USE_CLOCK_SYSCALL |
364 | #if EV_USE_CLOCK_SYSCALL |
364 | # include <syscall.h> |
365 | # include <sys/syscall.h> |
365 | # ifdef SYS_clock_gettime |
366 | # ifdef SYS_clock_gettime |
366 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
367 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
367 | # undef EV_USE_MONOTONIC |
368 | # undef EV_USE_MONOTONIC |
368 | # define EV_USE_MONOTONIC 1 |
369 | # define EV_USE_MONOTONIC 1 |
369 | # else |
370 | # else |
… | |
… | |
395 | # define EV_USE_INOTIFY 0 |
396 | # define EV_USE_INOTIFY 0 |
396 | #endif |
397 | #endif |
397 | |
398 | |
398 | #if !EV_USE_NANOSLEEP |
399 | #if !EV_USE_NANOSLEEP |
399 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
400 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
400 | # if !defined(_WIN32) && !defined(__hpux) |
401 | # if !defined _WIN32 && !defined __hpux |
401 | # include <sys/select.h> |
402 | # include <sys/select.h> |
402 | # endif |
403 | # endif |
403 | #endif |
404 | #endif |
404 | |
405 | |
405 | #if EV_USE_INOTIFY |
406 | #if EV_USE_INOTIFY |
… | |
… | |
408 | /* some very old inotify.h headers don't have IN_DONT_FOLLOW */ |
409 | /* some very old inotify.h headers don't have IN_DONT_FOLLOW */ |
409 | # ifndef IN_DONT_FOLLOW |
410 | # ifndef IN_DONT_FOLLOW |
410 | # undef EV_USE_INOTIFY |
411 | # undef EV_USE_INOTIFY |
411 | # define EV_USE_INOTIFY 0 |
412 | # define EV_USE_INOTIFY 0 |
412 | # endif |
413 | # endif |
413 | #endif |
|
|
414 | |
|
|
415 | #if EV_SELECT_IS_WINSOCKET |
|
|
416 | # include <winsock.h> |
|
|
417 | #endif |
414 | #endif |
418 | |
415 | |
419 | #if EV_USE_EVENTFD |
416 | #if EV_USE_EVENTFD |
420 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
417 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
421 | # include <stdint.h> |
418 | # include <stdint.h> |
… | |
… | |
533 | * or so. |
530 | * or so. |
534 | * we try to detect these and simply assume they are not gcc - if they have |
531 | * we try to detect these and simply assume they are not gcc - if they have |
535 | * an issue with that they should have done it right in the first place. |
532 | * an issue with that they should have done it right in the first place. |
536 | */ |
533 | */ |
537 | #ifndef ECB_GCC_VERSION |
534 | #ifndef ECB_GCC_VERSION |
538 | #if !defined(__GNUC_MINOR__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__llvm__) || defined(__clang__) |
535 | #if !defined __GNUC_MINOR__ || defined __INTEL_COMPILER || defined __SUNPRO_C || defined __SUNPRO_CC || defined __llvm__ || defined __clang__ |
539 | #define ECB_GCC_VERSION(major,minor) 0 |
536 | #define ECB_GCC_VERSION(major,minor) 0 |
540 | #else |
537 | #else |
541 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
538 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
542 | #endif |
539 | #endif |
543 | #endif |
540 | #endif |
… | |
… | |
554 | #if ECB_NO_THREADS || ECB_NO_SMP |
551 | #if ECB_NO_THREADS || ECB_NO_SMP |
555 | #define ECB_MEMORY_FENCE do { } while (0) |
552 | #define ECB_MEMORY_FENCE do { } while (0) |
556 | #endif |
553 | #endif |
557 | |
554 | |
558 | #ifndef ECB_MEMORY_FENCE |
555 | #ifndef ECB_MEMORY_FENCE |
559 | #if ECB_GCC_VERSION(2,5) || defined(__INTEL_COMPILER) || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
556 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
560 | #if __i386 || __i386__ |
557 | #if __i386 || __i386__ |
561 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
558 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
562 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */ |
559 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */ |
563 | #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ |
560 | #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ |
564 | #elif __amd64 || __amd64__ || __x86_64 || __x86_64__ |
561 | #elif __amd64 || __amd64__ || __x86_64 || __x86_64__ |
565 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
562 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
566 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") |
563 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") |
567 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */ |
564 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */ |
568 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
565 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
569 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
566 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
570 | #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \ |
567 | #elif defined __ARM_ARCH_6__ || defined __ARM_ARCH_6J__ \ |
571 | || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) |
568 | || defined __ARM_ARCH_6K__ || defined __ARM_ARCH_6ZK__ |
572 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory") |
569 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory") |
573 | #elif defined(__ARM_ARCH_7__ ) || defined(__ARM_ARCH_7A__ ) \ |
570 | #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \ |
574 | || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ ) |
571 | || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__ |
575 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
572 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
576 | #elif __sparc || __sparc__ |
573 | #elif __sparc || __sparc__ |
577 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad | " : : : "memory") |
574 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad | " : : : "memory") |
578 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") |
575 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") |
579 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") |
576 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") |
580 | #elif defined(__s390__) || defined(__s390x__) |
577 | #elif defined __s390__ || defined __s390x__ |
581 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") |
578 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") |
|
|
579 | #elif defined __mips__ |
|
|
580 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
|
|
581 | #elif defined __alpha__ |
|
|
582 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mb" : : : "memory") |
582 | #endif |
583 | #endif |
583 | #endif |
584 | #endif |
584 | #endif |
585 | #endif |
585 | |
586 | |
586 | #ifndef ECB_MEMORY_FENCE |
587 | #ifndef ECB_MEMORY_FENCE |
587 | #if ECB_GCC_VERSION(4,4) || defined(__INTEL_COMPILER) || defined(__clang__) |
588 | #if ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
588 | #define ECB_MEMORY_FENCE __sync_synchronize () |
589 | #define ECB_MEMORY_FENCE __sync_synchronize () |
589 | /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */ |
590 | /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */ |
590 | /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */ |
591 | /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */ |
591 | #elif _MSC_VER >= 1400 /* VC++ 2005 */ |
592 | #elif _MSC_VER >= 1400 /* VC++ 2005 */ |
592 | #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) |
593 | #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) |
593 | #define ECB_MEMORY_FENCE _ReadWriteBarrier () |
594 | #define ECB_MEMORY_FENCE _ReadWriteBarrier () |
594 | #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ |
595 | #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ |
595 | #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () |
596 | #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () |
596 | #elif defined(_WIN32) |
597 | #elif defined _WIN32 |
597 | #include <WinNT.h> |
598 | #include <WinNT.h> |
598 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
599 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
599 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
600 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
600 | #include <mbarrier.h> |
601 | #include <mbarrier.h> |
601 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
602 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
602 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () |
603 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () |
603 | #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () |
604 | #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () |
|
|
605 | #elif __xlC__ |
|
|
606 | #define ECB_MEMORY_FENCE __sync () |
604 | #endif |
607 | #endif |
605 | #endif |
608 | #endif |
606 | |
609 | |
607 | #ifndef ECB_MEMORY_FENCE |
610 | #ifndef ECB_MEMORY_FENCE |
608 | #if !ECB_AVOID_PTHREADS |
611 | #if !ECB_AVOID_PTHREADS |
… | |
… | |
620 | static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; |
623 | static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; |
621 | #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0) |
624 | #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0) |
622 | #endif |
625 | #endif |
623 | #endif |
626 | #endif |
624 | |
627 | |
625 | #if !defined(ECB_MEMORY_FENCE_ACQUIRE) && defined(ECB_MEMORY_FENCE) |
628 | #if !defined ECB_MEMORY_FENCE_ACQUIRE && defined ECB_MEMORY_FENCE |
626 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
629 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
627 | #endif |
630 | #endif |
628 | |
631 | |
629 | #if !defined(ECB_MEMORY_FENCE_RELEASE) && defined(ECB_MEMORY_FENCE) |
632 | #if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE |
630 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
633 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
631 | #endif |
634 | #endif |
632 | |
635 | |
633 | /*****************************************************************************/ |
636 | /*****************************************************************************/ |
634 | |
637 | |
… | |
… | |
1099 | { |
1102 | { |
1100 | write (STDERR_FILENO, msg, strlen (msg)); |
1103 | write (STDERR_FILENO, msg, strlen (msg)); |
1101 | } |
1104 | } |
1102 | #endif |
1105 | #endif |
1103 | |
1106 | |
1104 | static void (*syserr_cb)(const char *msg); |
1107 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1105 | |
1108 | |
1106 | void ecb_cold |
1109 | void ecb_cold |
1107 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
1110 | ev_set_syserr_cb (void (*cb)(const char *msg)) EV_THROW |
1108 | { |
1111 | { |
1109 | syserr_cb = cb; |
1112 | syserr_cb = cb; |
1110 | } |
1113 | } |
1111 | |
1114 | |
1112 | static void noinline ecb_cold |
1115 | static void noinline ecb_cold |
… | |
… | |
1148 | free (ptr); |
1151 | free (ptr); |
1149 | return 0; |
1152 | return 0; |
1150 | #endif |
1153 | #endif |
1151 | } |
1154 | } |
1152 | |
1155 | |
1153 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
1156 | static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; |
1154 | |
1157 | |
1155 | void ecb_cold |
1158 | void ecb_cold |
1156 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
1159 | ev_set_allocator (void *(*cb)(void *ptr, long size)) EV_THROW |
1157 | { |
1160 | { |
1158 | alloc = cb; |
1161 | alloc = cb; |
1159 | } |
1162 | } |
1160 | |
1163 | |
1161 | inline_speed void * |
1164 | inline_speed void * |
… | |
… | |
1278 | |
1281 | |
1279 | /*****************************************************************************/ |
1282 | /*****************************************************************************/ |
1280 | |
1283 | |
1281 | #ifndef EV_HAVE_EV_TIME |
1284 | #ifndef EV_HAVE_EV_TIME |
1282 | ev_tstamp |
1285 | ev_tstamp |
1283 | ev_time (void) |
1286 | ev_time (void) EV_THROW |
1284 | { |
1287 | { |
1285 | #if EV_USE_REALTIME |
1288 | #if EV_USE_REALTIME |
1286 | if (expect_true (have_realtime)) |
1289 | if (expect_true (have_realtime)) |
1287 | { |
1290 | { |
1288 | struct timespec ts; |
1291 | struct timespec ts; |
… | |
… | |
1312 | return ev_time (); |
1315 | return ev_time (); |
1313 | } |
1316 | } |
1314 | |
1317 | |
1315 | #if EV_MULTIPLICITY |
1318 | #if EV_MULTIPLICITY |
1316 | ev_tstamp |
1319 | ev_tstamp |
1317 | ev_now (EV_P) |
1320 | ev_now (EV_P) EV_THROW |
1318 | { |
1321 | { |
1319 | return ev_rt_now; |
1322 | return ev_rt_now; |
1320 | } |
1323 | } |
1321 | #endif |
1324 | #endif |
1322 | |
1325 | |
1323 | void |
1326 | void |
1324 | ev_sleep (ev_tstamp delay) |
1327 | ev_sleep (ev_tstamp delay) EV_THROW |
1325 | { |
1328 | { |
1326 | if (delay > 0.) |
1329 | if (delay > 0.) |
1327 | { |
1330 | { |
1328 | #if EV_USE_NANOSLEEP |
1331 | #if EV_USE_NANOSLEEP |
1329 | struct timespec ts; |
1332 | struct timespec ts; |
1330 | |
1333 | |
1331 | EV_TS_SET (ts, delay); |
1334 | EV_TS_SET (ts, delay); |
1332 | nanosleep (&ts, 0); |
1335 | nanosleep (&ts, 0); |
1333 | #elif defined(_WIN32) |
1336 | #elif defined _WIN32 |
1334 | Sleep ((unsigned long)(delay * 1e3)); |
1337 | Sleep ((unsigned long)(delay * 1e3)); |
1335 | #else |
1338 | #else |
1336 | struct timeval tv; |
1339 | struct timeval tv; |
1337 | |
1340 | |
1338 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
1341 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
… | |
… | |
1410 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1413 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1411 | { |
1414 | { |
1412 | } |
1415 | } |
1413 | |
1416 | |
1414 | void noinline |
1417 | void noinline |
1415 | ev_feed_event (EV_P_ void *w, int revents) |
1418 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
1416 | { |
1419 | { |
1417 | W w_ = (W)w; |
1420 | W w_ = (W)w; |
1418 | int pri = ABSPRI (w_); |
1421 | int pri = ABSPRI (w_); |
1419 | |
1422 | |
1420 | if (expect_false (w_->pending)) |
1423 | if (expect_false (w_->pending)) |
… | |
… | |
1424 | w_->pending = ++pendingcnt [pri]; |
1427 | w_->pending = ++pendingcnt [pri]; |
1425 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
1428 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
1426 | pendings [pri][w_->pending - 1].w = w_; |
1429 | pendings [pri][w_->pending - 1].w = w_; |
1427 | pendings [pri][w_->pending - 1].events = revents; |
1430 | pendings [pri][w_->pending - 1].events = revents; |
1428 | } |
1431 | } |
|
|
1432 | |
|
|
1433 | pendingpri = NUMPRI - 1; |
1429 | } |
1434 | } |
1430 | |
1435 | |
1431 | inline_speed void |
1436 | inline_speed void |
1432 | feed_reverse (EV_P_ W w) |
1437 | feed_reverse (EV_P_ W w) |
1433 | { |
1438 | { |
… | |
… | |
1479 | if (expect_true (!anfd->reify)) |
1484 | if (expect_true (!anfd->reify)) |
1480 | fd_event_nocheck (EV_A_ fd, revents); |
1485 | fd_event_nocheck (EV_A_ fd, revents); |
1481 | } |
1486 | } |
1482 | |
1487 | |
1483 | void |
1488 | void |
1484 | ev_feed_fd_event (EV_P_ int fd, int revents) |
1489 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW |
1485 | { |
1490 | { |
1486 | if (fd >= 0 && fd < anfdmax) |
1491 | if (fd >= 0 && fd < anfdmax) |
1487 | fd_event_nocheck (EV_A_ fd, revents); |
1492 | fd_event_nocheck (EV_A_ fd, revents); |
1488 | } |
1493 | } |
1489 | |
1494 | |
… | |
… | |
1838 | } |
1843 | } |
1839 | |
1844 | |
1840 | inline_speed void |
1845 | inline_speed void |
1841 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1846 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1842 | { |
1847 | { |
|
|
1848 | ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */ |
|
|
1849 | |
1843 | if (expect_true (*flag)) |
1850 | if (expect_true (*flag)) |
1844 | return; |
1851 | return; |
1845 | |
1852 | |
1846 | *flag = 1; |
1853 | *flag = 1; |
1847 | |
1854 | |
… | |
… | |
1866 | write (evfd, &counter, sizeof (uint64_t)); |
1873 | write (evfd, &counter, sizeof (uint64_t)); |
1867 | } |
1874 | } |
1868 | else |
1875 | else |
1869 | #endif |
1876 | #endif |
1870 | { |
1877 | { |
1871 | /* win32 people keep sending patches that change this write() to send() */ |
1878 | #ifdef _WIN32 |
1872 | /* and then run away. but send() is wrong, it wants a socket handle on win32 */ |
1879 | WSABUF buf; |
1873 | /* so when you think this write should be a send instead, please find out */ |
1880 | DWORD sent; |
1874 | /* where your send() is from - it's definitely not the microsoft send, and */ |
1881 | buf.buf = &buf; |
1875 | /* tell me. thank you. */ |
1882 | buf.len = 1; |
|
|
1883 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
|
|
1884 | #else |
1876 | write (evpipe [1], &(evpipe [1]), 1); |
1885 | write (evpipe [1], &(evpipe [1]), 1); |
|
|
1886 | #endif |
1877 | } |
1887 | } |
1878 | |
1888 | |
1879 | errno = old_errno; |
1889 | errno = old_errno; |
1880 | } |
1890 | } |
1881 | } |
1891 | } |
… | |
… | |
1896 | read (evfd, &counter, sizeof (uint64_t)); |
1906 | read (evfd, &counter, sizeof (uint64_t)); |
1897 | } |
1907 | } |
1898 | else |
1908 | else |
1899 | #endif |
1909 | #endif |
1900 | { |
1910 | { |
1901 | char dummy; |
1911 | char dummy[4]; |
1902 | /* see discussion in evpipe_write when you think this read should be recv in win32 */ |
1912 | #ifdef _WIN32 |
|
|
1913 | WSABUF buf; |
|
|
1914 | DWORD recvd; |
|
|
1915 | buf.buf = dummy; |
|
|
1916 | buf.len = sizeof (dummy); |
|
|
1917 | WSARecv (EV_FD_TO_WIN32_HANDLE (evpipe [0]), &buf, 1, &recvd, 0, 0, 0); |
|
|
1918 | #else |
1903 | read (evpipe [0], &dummy, 1); |
1919 | read (evpipe [0], &dummy, sizeof (dummy)); |
|
|
1920 | #endif |
1904 | } |
1921 | } |
1905 | } |
1922 | } |
1906 | |
1923 | |
1907 | pipe_write_skipped = 0; |
1924 | pipe_write_skipped = 0; |
|
|
1925 | |
|
|
1926 | ECB_MEMORY_FENCE; /* push out skipped, acquire flags */ |
1908 | |
1927 | |
1909 | #if EV_SIGNAL_ENABLE |
1928 | #if EV_SIGNAL_ENABLE |
1910 | if (sig_pending) |
1929 | if (sig_pending) |
1911 | { |
1930 | { |
1912 | sig_pending = 0; |
1931 | sig_pending = 0; |
|
|
1932 | |
|
|
1933 | ECB_MEMORY_FENCE_RELEASE; |
1913 | |
1934 | |
1914 | for (i = EV_NSIG - 1; i--; ) |
1935 | for (i = EV_NSIG - 1; i--; ) |
1915 | if (expect_false (signals [i].pending)) |
1936 | if (expect_false (signals [i].pending)) |
1916 | ev_feed_signal_event (EV_A_ i + 1); |
1937 | ev_feed_signal_event (EV_A_ i + 1); |
1917 | } |
1938 | } |
… | |
… | |
1919 | |
1940 | |
1920 | #if EV_ASYNC_ENABLE |
1941 | #if EV_ASYNC_ENABLE |
1921 | if (async_pending) |
1942 | if (async_pending) |
1922 | { |
1943 | { |
1923 | async_pending = 0; |
1944 | async_pending = 0; |
|
|
1945 | |
|
|
1946 | ECB_MEMORY_FENCE_RELEASE; |
1924 | |
1947 | |
1925 | for (i = asynccnt; i--; ) |
1948 | for (i = asynccnt; i--; ) |
1926 | if (asyncs [i]->sent) |
1949 | if (asyncs [i]->sent) |
1927 | { |
1950 | { |
1928 | asyncs [i]->sent = 0; |
1951 | asyncs [i]->sent = 0; |
… | |
… | |
1933 | } |
1956 | } |
1934 | |
1957 | |
1935 | /*****************************************************************************/ |
1958 | /*****************************************************************************/ |
1936 | |
1959 | |
1937 | void |
1960 | void |
1938 | ev_feed_signal (int signum) |
1961 | ev_feed_signal (int signum) EV_THROW |
1939 | { |
1962 | { |
1940 | #if EV_MULTIPLICITY |
1963 | #if EV_MULTIPLICITY |
1941 | EV_P = signals [signum - 1].loop; |
1964 | EV_P = signals [signum - 1].loop; |
1942 | |
1965 | |
1943 | if (!EV_A) |
1966 | if (!EV_A) |
… | |
… | |
1960 | |
1983 | |
1961 | ev_feed_signal (signum); |
1984 | ev_feed_signal (signum); |
1962 | } |
1985 | } |
1963 | |
1986 | |
1964 | void noinline |
1987 | void noinline |
1965 | ev_feed_signal_event (EV_P_ int signum) |
1988 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
1966 | { |
1989 | { |
1967 | WL w; |
1990 | WL w; |
1968 | |
1991 | |
1969 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
1992 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
1970 | return; |
1993 | return; |
… | |
… | |
2086 | #if EV_USE_SELECT |
2109 | #if EV_USE_SELECT |
2087 | # include "ev_select.c" |
2110 | # include "ev_select.c" |
2088 | #endif |
2111 | #endif |
2089 | |
2112 | |
2090 | int ecb_cold |
2113 | int ecb_cold |
2091 | ev_version_major (void) |
2114 | ev_version_major (void) EV_THROW |
2092 | { |
2115 | { |
2093 | return EV_VERSION_MAJOR; |
2116 | return EV_VERSION_MAJOR; |
2094 | } |
2117 | } |
2095 | |
2118 | |
2096 | int ecb_cold |
2119 | int ecb_cold |
2097 | ev_version_minor (void) |
2120 | ev_version_minor (void) EV_THROW |
2098 | { |
2121 | { |
2099 | return EV_VERSION_MINOR; |
2122 | return EV_VERSION_MINOR; |
2100 | } |
2123 | } |
2101 | |
2124 | |
2102 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2125 | /* return true if we are running with elevated privileges and should ignore env variables */ |
… | |
… | |
2110 | || getgid () != getegid (); |
2133 | || getgid () != getegid (); |
2111 | #endif |
2134 | #endif |
2112 | } |
2135 | } |
2113 | |
2136 | |
2114 | unsigned int ecb_cold |
2137 | unsigned int ecb_cold |
2115 | ev_supported_backends (void) |
2138 | ev_supported_backends (void) EV_THROW |
2116 | { |
2139 | { |
2117 | unsigned int flags = 0; |
2140 | unsigned int flags = 0; |
2118 | |
2141 | |
2119 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2142 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2120 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2143 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
… | |
… | |
2124 | |
2147 | |
2125 | return flags; |
2148 | return flags; |
2126 | } |
2149 | } |
2127 | |
2150 | |
2128 | unsigned int ecb_cold |
2151 | unsigned int ecb_cold |
2129 | ev_recommended_backends (void) |
2152 | ev_recommended_backends (void) EV_THROW |
2130 | { |
2153 | { |
2131 | unsigned int flags = ev_supported_backends (); |
2154 | unsigned int flags = ev_supported_backends (); |
2132 | |
2155 | |
2133 | #ifndef __NetBSD__ |
2156 | #ifndef __NetBSD__ |
2134 | /* kqueue is borked on everything but netbsd apparently */ |
2157 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2146 | |
2169 | |
2147 | return flags; |
2170 | return flags; |
2148 | } |
2171 | } |
2149 | |
2172 | |
2150 | unsigned int ecb_cold |
2173 | unsigned int ecb_cold |
2151 | ev_embeddable_backends (void) |
2174 | ev_embeddable_backends (void) EV_THROW |
2152 | { |
2175 | { |
2153 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2176 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2154 | |
2177 | |
2155 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2178 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2156 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
2179 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
… | |
… | |
2158 | |
2181 | |
2159 | return flags; |
2182 | return flags; |
2160 | } |
2183 | } |
2161 | |
2184 | |
2162 | unsigned int |
2185 | unsigned int |
2163 | ev_backend (EV_P) |
2186 | ev_backend (EV_P) EV_THROW |
2164 | { |
2187 | { |
2165 | return backend; |
2188 | return backend; |
2166 | } |
2189 | } |
2167 | |
2190 | |
2168 | #if EV_FEATURE_API |
2191 | #if EV_FEATURE_API |
2169 | unsigned int |
2192 | unsigned int |
2170 | ev_iteration (EV_P) |
2193 | ev_iteration (EV_P) EV_THROW |
2171 | { |
2194 | { |
2172 | return loop_count; |
2195 | return loop_count; |
2173 | } |
2196 | } |
2174 | |
2197 | |
2175 | unsigned int |
2198 | unsigned int |
2176 | ev_depth (EV_P) |
2199 | ev_depth (EV_P) EV_THROW |
2177 | { |
2200 | { |
2178 | return loop_depth; |
2201 | return loop_depth; |
2179 | } |
2202 | } |
2180 | |
2203 | |
2181 | void |
2204 | void |
2182 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) |
2205 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2183 | { |
2206 | { |
2184 | io_blocktime = interval; |
2207 | io_blocktime = interval; |
2185 | } |
2208 | } |
2186 | |
2209 | |
2187 | void |
2210 | void |
2188 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) |
2211 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2189 | { |
2212 | { |
2190 | timeout_blocktime = interval; |
2213 | timeout_blocktime = interval; |
2191 | } |
2214 | } |
2192 | |
2215 | |
2193 | void |
2216 | void |
2194 | ev_set_userdata (EV_P_ void *data) |
2217 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2195 | { |
2218 | { |
2196 | userdata = data; |
2219 | userdata = data; |
2197 | } |
2220 | } |
2198 | |
2221 | |
2199 | void * |
2222 | void * |
2200 | ev_userdata (EV_P) |
2223 | ev_userdata (EV_P) EV_THROW |
2201 | { |
2224 | { |
2202 | return userdata; |
2225 | return userdata; |
2203 | } |
2226 | } |
2204 | |
2227 | |
2205 | void |
2228 | void |
2206 | ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) |
2229 | ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) EV_THROW |
2207 | { |
2230 | { |
2208 | invoke_cb = invoke_pending_cb; |
2231 | invoke_cb = invoke_pending_cb; |
2209 | } |
2232 | } |
2210 | |
2233 | |
2211 | void |
2234 | void |
2212 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) |
2235 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW |
2213 | { |
2236 | { |
2214 | release_cb = release; |
2237 | release_cb = release; |
2215 | acquire_cb = acquire; |
2238 | acquire_cb = acquire; |
2216 | } |
2239 | } |
2217 | #endif |
2240 | #endif |
2218 | |
2241 | |
2219 | /* initialise a loop structure, must be zero-initialised */ |
2242 | /* initialise a loop structure, must be zero-initialised */ |
2220 | static void noinline ecb_cold |
2243 | static void noinline ecb_cold |
2221 | loop_init (EV_P_ unsigned int flags) |
2244 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2222 | { |
2245 | { |
2223 | if (!backend) |
2246 | if (!backend) |
2224 | { |
2247 | { |
2225 | origflags = flags; |
2248 | origflags = flags; |
2226 | |
2249 | |
… | |
… | |
2479 | } |
2502 | } |
2480 | |
2503 | |
2481 | #if EV_MULTIPLICITY |
2504 | #if EV_MULTIPLICITY |
2482 | |
2505 | |
2483 | struct ev_loop * ecb_cold |
2506 | struct ev_loop * ecb_cold |
2484 | ev_loop_new (unsigned int flags) |
2507 | ev_loop_new (unsigned int flags) EV_THROW |
2485 | { |
2508 | { |
2486 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2509 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2487 | |
2510 | |
2488 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2511 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2489 | loop_init (EV_A_ flags); |
2512 | loop_init (EV_A_ flags); |
… | |
… | |
2533 | } |
2556 | } |
2534 | #endif |
2557 | #endif |
2535 | |
2558 | |
2536 | #if EV_FEATURE_API |
2559 | #if EV_FEATURE_API |
2537 | void ecb_cold |
2560 | void ecb_cold |
2538 | ev_verify (EV_P) |
2561 | ev_verify (EV_P) EV_THROW |
2539 | { |
2562 | { |
2540 | #if EV_VERIFY |
2563 | #if EV_VERIFY |
2541 | int i; |
2564 | int i; |
2542 | WL w; |
2565 | WL w, w2; |
2543 | |
2566 | |
2544 | assert (activecnt >= -1); |
2567 | assert (activecnt >= -1); |
2545 | |
2568 | |
2546 | assert (fdchangemax >= fdchangecnt); |
2569 | assert (fdchangemax >= fdchangecnt); |
2547 | for (i = 0; i < fdchangecnt; ++i) |
2570 | for (i = 0; i < fdchangecnt; ++i) |
2548 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2571 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2549 | |
2572 | |
2550 | assert (anfdmax >= 0); |
2573 | assert (anfdmax >= 0); |
2551 | for (i = 0; i < anfdmax; ++i) |
2574 | for (i = 0; i < anfdmax; ++i) |
|
|
2575 | { |
|
|
2576 | int j = 0; |
|
|
2577 | |
2552 | for (w = anfds [i].head; w; w = w->next) |
2578 | for (w = w2 = anfds [i].head; w; w = w->next) |
2553 | { |
2579 | { |
2554 | verify_watcher (EV_A_ (W)w); |
2580 | verify_watcher (EV_A_ (W)w); |
|
|
2581 | |
|
|
2582 | if (j++ & 1) |
|
|
2583 | { |
|
|
2584 | assert (("libev: io watcher list contains a loop", w != w2)); |
|
|
2585 | w2 = w2->next; |
|
|
2586 | } |
|
|
2587 | |
2555 | assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); |
2588 | assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); |
2556 | assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); |
2589 | assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); |
2557 | } |
2590 | } |
|
|
2591 | } |
2558 | |
2592 | |
2559 | assert (timermax >= timercnt); |
2593 | assert (timermax >= timercnt); |
2560 | verify_heap (EV_A_ timers, timercnt); |
2594 | verify_heap (EV_A_ timers, timercnt); |
2561 | |
2595 | |
2562 | #if EV_PERIODIC_ENABLE |
2596 | #if EV_PERIODIC_ENABLE |
… | |
… | |
2612 | #if EV_MULTIPLICITY |
2646 | #if EV_MULTIPLICITY |
2613 | struct ev_loop * ecb_cold |
2647 | struct ev_loop * ecb_cold |
2614 | #else |
2648 | #else |
2615 | int |
2649 | int |
2616 | #endif |
2650 | #endif |
2617 | ev_default_loop (unsigned int flags) |
2651 | ev_default_loop (unsigned int flags) EV_THROW |
2618 | { |
2652 | { |
2619 | if (!ev_default_loop_ptr) |
2653 | if (!ev_default_loop_ptr) |
2620 | { |
2654 | { |
2621 | #if EV_MULTIPLICITY |
2655 | #if EV_MULTIPLICITY |
2622 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
2656 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
2641 | |
2675 | |
2642 | return ev_default_loop_ptr; |
2676 | return ev_default_loop_ptr; |
2643 | } |
2677 | } |
2644 | |
2678 | |
2645 | void |
2679 | void |
2646 | ev_loop_fork (EV_P) |
2680 | ev_loop_fork (EV_P) EV_THROW |
2647 | { |
2681 | { |
2648 | postfork = 1; /* must be in line with ev_default_fork */ |
2682 | postfork = 1; /* must be in line with ev_default_fork */ |
2649 | } |
2683 | } |
2650 | |
2684 | |
2651 | /*****************************************************************************/ |
2685 | /*****************************************************************************/ |
… | |
… | |
2655 | { |
2689 | { |
2656 | EV_CB_INVOKE ((W)w, revents); |
2690 | EV_CB_INVOKE ((W)w, revents); |
2657 | } |
2691 | } |
2658 | |
2692 | |
2659 | unsigned int |
2693 | unsigned int |
2660 | ev_pending_count (EV_P) |
2694 | ev_pending_count (EV_P) EV_THROW |
2661 | { |
2695 | { |
2662 | int pri; |
2696 | int pri; |
2663 | unsigned int count = 0; |
2697 | unsigned int count = 0; |
2664 | |
2698 | |
2665 | for (pri = NUMPRI; pri--; ) |
2699 | for (pri = NUMPRI; pri--; ) |
… | |
… | |
2669 | } |
2703 | } |
2670 | |
2704 | |
2671 | void noinline |
2705 | void noinline |
2672 | ev_invoke_pending (EV_P) |
2706 | ev_invoke_pending (EV_P) |
2673 | { |
2707 | { |
2674 | int pri; |
2708 | for (pendingpri = NUMPRI; pendingpri--; ) /* pendingpri is modified during the loop */ |
2675 | |
|
|
2676 | for (pri = NUMPRI; pri--; ) |
|
|
2677 | while (pendingcnt [pri]) |
2709 | while (pendingcnt [pendingpri]) |
2678 | { |
2710 | { |
2679 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
2711 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
2680 | |
2712 | |
2681 | p->w->pending = 0; |
2713 | p->w->pending = 0; |
2682 | EV_CB_INVOKE (p->w, p->events); |
2714 | EV_CB_INVOKE (p->w, p->events); |
2683 | EV_FREQUENT_CHECK; |
2715 | EV_FREQUENT_CHECK; |
2684 | } |
2716 | } |
… | |
… | |
2924 | |
2956 | |
2925 | mn_now = ev_rt_now; |
2957 | mn_now = ev_rt_now; |
2926 | } |
2958 | } |
2927 | } |
2959 | } |
2928 | |
2960 | |
2929 | void |
2961 | int |
2930 | ev_run (EV_P_ int flags) |
2962 | ev_run (EV_P_ int flags) |
2931 | { |
2963 | { |
2932 | #if EV_FEATURE_API |
2964 | #if EV_FEATURE_API |
2933 | ++loop_depth; |
2965 | ++loop_depth; |
2934 | #endif |
2966 | #endif |
… | |
… | |
3091 | loop_done = EVBREAK_CANCEL; |
3123 | loop_done = EVBREAK_CANCEL; |
3092 | |
3124 | |
3093 | #if EV_FEATURE_API |
3125 | #if EV_FEATURE_API |
3094 | --loop_depth; |
3126 | --loop_depth; |
3095 | #endif |
3127 | #endif |
|
|
3128 | |
|
|
3129 | return activecnt; |
3096 | } |
3130 | } |
3097 | |
3131 | |
3098 | void |
3132 | void |
3099 | ev_break (EV_P_ int how) |
3133 | ev_break (EV_P_ int how) EV_THROW |
3100 | { |
3134 | { |
3101 | loop_done = how; |
3135 | loop_done = how; |
3102 | } |
3136 | } |
3103 | |
3137 | |
3104 | void |
3138 | void |
3105 | ev_ref (EV_P) |
3139 | ev_ref (EV_P) EV_THROW |
3106 | { |
3140 | { |
3107 | ++activecnt; |
3141 | ++activecnt; |
3108 | } |
3142 | } |
3109 | |
3143 | |
3110 | void |
3144 | void |
3111 | ev_unref (EV_P) |
3145 | ev_unref (EV_P) EV_THROW |
3112 | { |
3146 | { |
3113 | --activecnt; |
3147 | --activecnt; |
3114 | } |
3148 | } |
3115 | |
3149 | |
3116 | void |
3150 | void |
3117 | ev_now_update (EV_P) |
3151 | ev_now_update (EV_P) EV_THROW |
3118 | { |
3152 | { |
3119 | time_update (EV_A_ 1e100); |
3153 | time_update (EV_A_ 1e100); |
3120 | } |
3154 | } |
3121 | |
3155 | |
3122 | void |
3156 | void |
3123 | ev_suspend (EV_P) |
3157 | ev_suspend (EV_P) EV_THROW |
3124 | { |
3158 | { |
3125 | ev_now_update (EV_A); |
3159 | ev_now_update (EV_A); |
3126 | } |
3160 | } |
3127 | |
3161 | |
3128 | void |
3162 | void |
3129 | ev_resume (EV_P) |
3163 | ev_resume (EV_P) EV_THROW |
3130 | { |
3164 | { |
3131 | ev_tstamp mn_prev = mn_now; |
3165 | ev_tstamp mn_prev = mn_now; |
3132 | |
3166 | |
3133 | ev_now_update (EV_A); |
3167 | ev_now_update (EV_A); |
3134 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3168 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3173 | w->pending = 0; |
3207 | w->pending = 0; |
3174 | } |
3208 | } |
3175 | } |
3209 | } |
3176 | |
3210 | |
3177 | int |
3211 | int |
3178 | ev_clear_pending (EV_P_ void *w) |
3212 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3179 | { |
3213 | { |
3180 | W w_ = (W)w; |
3214 | W w_ = (W)w; |
3181 | int pending = w_->pending; |
3215 | int pending = w_->pending; |
3182 | |
3216 | |
3183 | if (expect_true (pending)) |
3217 | if (expect_true (pending)) |
… | |
… | |
3216 | } |
3250 | } |
3217 | |
3251 | |
3218 | /*****************************************************************************/ |
3252 | /*****************************************************************************/ |
3219 | |
3253 | |
3220 | void noinline |
3254 | void noinline |
3221 | ev_io_start (EV_P_ ev_io *w) |
3255 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3222 | { |
3256 | { |
3223 | int fd = w->fd; |
3257 | int fd = w->fd; |
3224 | |
3258 | |
3225 | if (expect_false (ev_is_active (w))) |
3259 | if (expect_false (ev_is_active (w))) |
3226 | return; |
3260 | return; |
… | |
… | |
3232 | |
3266 | |
3233 | ev_start (EV_A_ (W)w, 1); |
3267 | ev_start (EV_A_ (W)w, 1); |
3234 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3268 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3235 | wlist_add (&anfds[fd].head, (WL)w); |
3269 | wlist_add (&anfds[fd].head, (WL)w); |
3236 | |
3270 | |
|
|
3271 | /* common bug, apparently */ |
|
|
3272 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
|
|
3273 | |
3237 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3274 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3238 | w->events &= ~EV__IOFDSET; |
3275 | w->events &= ~EV__IOFDSET; |
3239 | |
3276 | |
3240 | EV_FREQUENT_CHECK; |
3277 | EV_FREQUENT_CHECK; |
3241 | } |
3278 | } |
3242 | |
3279 | |
3243 | void noinline |
3280 | void noinline |
3244 | ev_io_stop (EV_P_ ev_io *w) |
3281 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3245 | { |
3282 | { |
3246 | clear_pending (EV_A_ (W)w); |
3283 | clear_pending (EV_A_ (W)w); |
3247 | if (expect_false (!ev_is_active (w))) |
3284 | if (expect_false (!ev_is_active (w))) |
3248 | return; |
3285 | return; |
3249 | |
3286 | |
… | |
… | |
3258 | |
3295 | |
3259 | EV_FREQUENT_CHECK; |
3296 | EV_FREQUENT_CHECK; |
3260 | } |
3297 | } |
3261 | |
3298 | |
3262 | void noinline |
3299 | void noinline |
3263 | ev_timer_start (EV_P_ ev_timer *w) |
3300 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3264 | { |
3301 | { |
3265 | if (expect_false (ev_is_active (w))) |
3302 | if (expect_false (ev_is_active (w))) |
3266 | return; |
3303 | return; |
3267 | |
3304 | |
3268 | ev_at (w) += mn_now; |
3305 | ev_at (w) += mn_now; |
… | |
… | |
3282 | |
3319 | |
3283 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3320 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3284 | } |
3321 | } |
3285 | |
3322 | |
3286 | void noinline |
3323 | void noinline |
3287 | ev_timer_stop (EV_P_ ev_timer *w) |
3324 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3288 | { |
3325 | { |
3289 | clear_pending (EV_A_ (W)w); |
3326 | clear_pending (EV_A_ (W)w); |
3290 | if (expect_false (!ev_is_active (w))) |
3327 | if (expect_false (!ev_is_active (w))) |
3291 | return; |
3328 | return; |
3292 | |
3329 | |
… | |
… | |
3312 | |
3349 | |
3313 | EV_FREQUENT_CHECK; |
3350 | EV_FREQUENT_CHECK; |
3314 | } |
3351 | } |
3315 | |
3352 | |
3316 | void noinline |
3353 | void noinline |
3317 | ev_timer_again (EV_P_ ev_timer *w) |
3354 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
3318 | { |
3355 | { |
3319 | EV_FREQUENT_CHECK; |
3356 | EV_FREQUENT_CHECK; |
3320 | |
3357 | |
3321 | clear_pending (EV_A_ (W)w); |
3358 | clear_pending (EV_A_ (W)w); |
3322 | |
3359 | |
… | |
… | |
3339 | |
3376 | |
3340 | EV_FREQUENT_CHECK; |
3377 | EV_FREQUENT_CHECK; |
3341 | } |
3378 | } |
3342 | |
3379 | |
3343 | ev_tstamp |
3380 | ev_tstamp |
3344 | ev_timer_remaining (EV_P_ ev_timer *w) |
3381 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
3345 | { |
3382 | { |
3346 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3383 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3347 | } |
3384 | } |
3348 | |
3385 | |
3349 | #if EV_PERIODIC_ENABLE |
3386 | #if EV_PERIODIC_ENABLE |
3350 | void noinline |
3387 | void noinline |
3351 | ev_periodic_start (EV_P_ ev_periodic *w) |
3388 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
3352 | { |
3389 | { |
3353 | if (expect_false (ev_is_active (w))) |
3390 | if (expect_false (ev_is_active (w))) |
3354 | return; |
3391 | return; |
3355 | |
3392 | |
3356 | if (w->reschedule_cb) |
3393 | if (w->reschedule_cb) |
… | |
… | |
3376 | |
3413 | |
3377 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3414 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3378 | } |
3415 | } |
3379 | |
3416 | |
3380 | void noinline |
3417 | void noinline |
3381 | ev_periodic_stop (EV_P_ ev_periodic *w) |
3418 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
3382 | { |
3419 | { |
3383 | clear_pending (EV_A_ (W)w); |
3420 | clear_pending (EV_A_ (W)w); |
3384 | if (expect_false (!ev_is_active (w))) |
3421 | if (expect_false (!ev_is_active (w))) |
3385 | return; |
3422 | return; |
3386 | |
3423 | |
… | |
… | |
3404 | |
3441 | |
3405 | EV_FREQUENT_CHECK; |
3442 | EV_FREQUENT_CHECK; |
3406 | } |
3443 | } |
3407 | |
3444 | |
3408 | void noinline |
3445 | void noinline |
3409 | ev_periodic_again (EV_P_ ev_periodic *w) |
3446 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
3410 | { |
3447 | { |
3411 | /* TODO: use adjustheap and recalculation */ |
3448 | /* TODO: use adjustheap and recalculation */ |
3412 | ev_periodic_stop (EV_A_ w); |
3449 | ev_periodic_stop (EV_A_ w); |
3413 | ev_periodic_start (EV_A_ w); |
3450 | ev_periodic_start (EV_A_ w); |
3414 | } |
3451 | } |
… | |
… | |
3419 | #endif |
3456 | #endif |
3420 | |
3457 | |
3421 | #if EV_SIGNAL_ENABLE |
3458 | #if EV_SIGNAL_ENABLE |
3422 | |
3459 | |
3423 | void noinline |
3460 | void noinline |
3424 | ev_signal_start (EV_P_ ev_signal *w) |
3461 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
3425 | { |
3462 | { |
3426 | if (expect_false (ev_is_active (w))) |
3463 | if (expect_false (ev_is_active (w))) |
3427 | return; |
3464 | return; |
3428 | |
3465 | |
3429 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
3466 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
… | |
… | |
3500 | |
3537 | |
3501 | EV_FREQUENT_CHECK; |
3538 | EV_FREQUENT_CHECK; |
3502 | } |
3539 | } |
3503 | |
3540 | |
3504 | void noinline |
3541 | void noinline |
3505 | ev_signal_stop (EV_P_ ev_signal *w) |
3542 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
3506 | { |
3543 | { |
3507 | clear_pending (EV_A_ (W)w); |
3544 | clear_pending (EV_A_ (W)w); |
3508 | if (expect_false (!ev_is_active (w))) |
3545 | if (expect_false (!ev_is_active (w))) |
3509 | return; |
3546 | return; |
3510 | |
3547 | |
… | |
… | |
3541 | #endif |
3578 | #endif |
3542 | |
3579 | |
3543 | #if EV_CHILD_ENABLE |
3580 | #if EV_CHILD_ENABLE |
3544 | |
3581 | |
3545 | void |
3582 | void |
3546 | ev_child_start (EV_P_ ev_child *w) |
3583 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
3547 | { |
3584 | { |
3548 | #if EV_MULTIPLICITY |
3585 | #if EV_MULTIPLICITY |
3549 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
3586 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
3550 | #endif |
3587 | #endif |
3551 | if (expect_false (ev_is_active (w))) |
3588 | if (expect_false (ev_is_active (w))) |
… | |
… | |
3558 | |
3595 | |
3559 | EV_FREQUENT_CHECK; |
3596 | EV_FREQUENT_CHECK; |
3560 | } |
3597 | } |
3561 | |
3598 | |
3562 | void |
3599 | void |
3563 | ev_child_stop (EV_P_ ev_child *w) |
3600 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
3564 | { |
3601 | { |
3565 | clear_pending (EV_A_ (W)w); |
3602 | clear_pending (EV_A_ (W)w); |
3566 | if (expect_false (!ev_is_active (w))) |
3603 | if (expect_false (!ev_is_active (w))) |
3567 | return; |
3604 | return; |
3568 | |
3605 | |
… | |
… | |
3735 | } |
3772 | } |
3736 | |
3773 | |
3737 | inline_size int |
3774 | inline_size int |
3738 | infy_newfd (void) |
3775 | infy_newfd (void) |
3739 | { |
3776 | { |
3740 | #if defined (IN_CLOEXEC) && defined (IN_NONBLOCK) |
3777 | #if defined IN_CLOEXEC && defined IN_NONBLOCK |
3741 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3778 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3742 | if (fd >= 0) |
3779 | if (fd >= 0) |
3743 | return fd; |
3780 | return fd; |
3744 | #endif |
3781 | #endif |
3745 | return inotify_init (); |
3782 | return inotify_init (); |
… | |
… | |
3820 | #else |
3857 | #else |
3821 | # define EV_LSTAT(p,b) lstat (p, b) |
3858 | # define EV_LSTAT(p,b) lstat (p, b) |
3822 | #endif |
3859 | #endif |
3823 | |
3860 | |
3824 | void |
3861 | void |
3825 | ev_stat_stat (EV_P_ ev_stat *w) |
3862 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
3826 | { |
3863 | { |
3827 | if (lstat (w->path, &w->attr) < 0) |
3864 | if (lstat (w->path, &w->attr) < 0) |
3828 | w->attr.st_nlink = 0; |
3865 | w->attr.st_nlink = 0; |
3829 | else if (!w->attr.st_nlink) |
3866 | else if (!w->attr.st_nlink) |
3830 | w->attr.st_nlink = 1; |
3867 | w->attr.st_nlink = 1; |
… | |
… | |
3869 | ev_feed_event (EV_A_ w, EV_STAT); |
3906 | ev_feed_event (EV_A_ w, EV_STAT); |
3870 | } |
3907 | } |
3871 | } |
3908 | } |
3872 | |
3909 | |
3873 | void |
3910 | void |
3874 | ev_stat_start (EV_P_ ev_stat *w) |
3911 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
3875 | { |
3912 | { |
3876 | if (expect_false (ev_is_active (w))) |
3913 | if (expect_false (ev_is_active (w))) |
3877 | return; |
3914 | return; |
3878 | |
3915 | |
3879 | ev_stat_stat (EV_A_ w); |
3916 | ev_stat_stat (EV_A_ w); |
… | |
… | |
3900 | |
3937 | |
3901 | EV_FREQUENT_CHECK; |
3938 | EV_FREQUENT_CHECK; |
3902 | } |
3939 | } |
3903 | |
3940 | |
3904 | void |
3941 | void |
3905 | ev_stat_stop (EV_P_ ev_stat *w) |
3942 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
3906 | { |
3943 | { |
3907 | clear_pending (EV_A_ (W)w); |
3944 | clear_pending (EV_A_ (W)w); |
3908 | if (expect_false (!ev_is_active (w))) |
3945 | if (expect_false (!ev_is_active (w))) |
3909 | return; |
3946 | return; |
3910 | |
3947 | |
… | |
… | |
3926 | } |
3963 | } |
3927 | #endif |
3964 | #endif |
3928 | |
3965 | |
3929 | #if EV_IDLE_ENABLE |
3966 | #if EV_IDLE_ENABLE |
3930 | void |
3967 | void |
3931 | ev_idle_start (EV_P_ ev_idle *w) |
3968 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
3932 | { |
3969 | { |
3933 | if (expect_false (ev_is_active (w))) |
3970 | if (expect_false (ev_is_active (w))) |
3934 | return; |
3971 | return; |
3935 | |
3972 | |
3936 | pri_adjust (EV_A_ (W)w); |
3973 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
3949 | |
3986 | |
3950 | EV_FREQUENT_CHECK; |
3987 | EV_FREQUENT_CHECK; |
3951 | } |
3988 | } |
3952 | |
3989 | |
3953 | void |
3990 | void |
3954 | ev_idle_stop (EV_P_ ev_idle *w) |
3991 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
3955 | { |
3992 | { |
3956 | clear_pending (EV_A_ (W)w); |
3993 | clear_pending (EV_A_ (W)w); |
3957 | if (expect_false (!ev_is_active (w))) |
3994 | if (expect_false (!ev_is_active (w))) |
3958 | return; |
3995 | return; |
3959 | |
3996 | |
… | |
… | |
3973 | } |
4010 | } |
3974 | #endif |
4011 | #endif |
3975 | |
4012 | |
3976 | #if EV_PREPARE_ENABLE |
4013 | #if EV_PREPARE_ENABLE |
3977 | void |
4014 | void |
3978 | ev_prepare_start (EV_P_ ev_prepare *w) |
4015 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
3979 | { |
4016 | { |
3980 | if (expect_false (ev_is_active (w))) |
4017 | if (expect_false (ev_is_active (w))) |
3981 | return; |
4018 | return; |
3982 | |
4019 | |
3983 | EV_FREQUENT_CHECK; |
4020 | EV_FREQUENT_CHECK; |
… | |
… | |
3988 | |
4025 | |
3989 | EV_FREQUENT_CHECK; |
4026 | EV_FREQUENT_CHECK; |
3990 | } |
4027 | } |
3991 | |
4028 | |
3992 | void |
4029 | void |
3993 | ev_prepare_stop (EV_P_ ev_prepare *w) |
4030 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
3994 | { |
4031 | { |
3995 | clear_pending (EV_A_ (W)w); |
4032 | clear_pending (EV_A_ (W)w); |
3996 | if (expect_false (!ev_is_active (w))) |
4033 | if (expect_false (!ev_is_active (w))) |
3997 | return; |
4034 | return; |
3998 | |
4035 | |
… | |
… | |
4011 | } |
4048 | } |
4012 | #endif |
4049 | #endif |
4013 | |
4050 | |
4014 | #if EV_CHECK_ENABLE |
4051 | #if EV_CHECK_ENABLE |
4015 | void |
4052 | void |
4016 | ev_check_start (EV_P_ ev_check *w) |
4053 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
4017 | { |
4054 | { |
4018 | if (expect_false (ev_is_active (w))) |
4055 | if (expect_false (ev_is_active (w))) |
4019 | return; |
4056 | return; |
4020 | |
4057 | |
4021 | EV_FREQUENT_CHECK; |
4058 | EV_FREQUENT_CHECK; |
… | |
… | |
4026 | |
4063 | |
4027 | EV_FREQUENT_CHECK; |
4064 | EV_FREQUENT_CHECK; |
4028 | } |
4065 | } |
4029 | |
4066 | |
4030 | void |
4067 | void |
4031 | ev_check_stop (EV_P_ ev_check *w) |
4068 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
4032 | { |
4069 | { |
4033 | clear_pending (EV_A_ (W)w); |
4070 | clear_pending (EV_A_ (W)w); |
4034 | if (expect_false (!ev_is_active (w))) |
4071 | if (expect_false (!ev_is_active (w))) |
4035 | return; |
4072 | return; |
4036 | |
4073 | |
… | |
… | |
4049 | } |
4086 | } |
4050 | #endif |
4087 | #endif |
4051 | |
4088 | |
4052 | #if EV_EMBED_ENABLE |
4089 | #if EV_EMBED_ENABLE |
4053 | void noinline |
4090 | void noinline |
4054 | ev_embed_sweep (EV_P_ ev_embed *w) |
4091 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4055 | { |
4092 | { |
4056 | ev_run (w->other, EVRUN_NOWAIT); |
4093 | ev_run (w->other, EVRUN_NOWAIT); |
4057 | } |
4094 | } |
4058 | |
4095 | |
4059 | static void |
4096 | static void |
… | |
… | |
4107 | ev_idle_stop (EV_A_ idle); |
4144 | ev_idle_stop (EV_A_ idle); |
4108 | } |
4145 | } |
4109 | #endif |
4146 | #endif |
4110 | |
4147 | |
4111 | void |
4148 | void |
4112 | ev_embed_start (EV_P_ ev_embed *w) |
4149 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4113 | { |
4150 | { |
4114 | if (expect_false (ev_is_active (w))) |
4151 | if (expect_false (ev_is_active (w))) |
4115 | return; |
4152 | return; |
4116 | |
4153 | |
4117 | { |
4154 | { |
… | |
… | |
4138 | |
4175 | |
4139 | EV_FREQUENT_CHECK; |
4176 | EV_FREQUENT_CHECK; |
4140 | } |
4177 | } |
4141 | |
4178 | |
4142 | void |
4179 | void |
4143 | ev_embed_stop (EV_P_ ev_embed *w) |
4180 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4144 | { |
4181 | { |
4145 | clear_pending (EV_A_ (W)w); |
4182 | clear_pending (EV_A_ (W)w); |
4146 | if (expect_false (!ev_is_active (w))) |
4183 | if (expect_false (!ev_is_active (w))) |
4147 | return; |
4184 | return; |
4148 | |
4185 | |
… | |
… | |
4158 | } |
4195 | } |
4159 | #endif |
4196 | #endif |
4160 | |
4197 | |
4161 | #if EV_FORK_ENABLE |
4198 | #if EV_FORK_ENABLE |
4162 | void |
4199 | void |
4163 | ev_fork_start (EV_P_ ev_fork *w) |
4200 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4164 | { |
4201 | { |
4165 | if (expect_false (ev_is_active (w))) |
4202 | if (expect_false (ev_is_active (w))) |
4166 | return; |
4203 | return; |
4167 | |
4204 | |
4168 | EV_FREQUENT_CHECK; |
4205 | EV_FREQUENT_CHECK; |
… | |
… | |
4173 | |
4210 | |
4174 | EV_FREQUENT_CHECK; |
4211 | EV_FREQUENT_CHECK; |
4175 | } |
4212 | } |
4176 | |
4213 | |
4177 | void |
4214 | void |
4178 | ev_fork_stop (EV_P_ ev_fork *w) |
4215 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4179 | { |
4216 | { |
4180 | clear_pending (EV_A_ (W)w); |
4217 | clear_pending (EV_A_ (W)w); |
4181 | if (expect_false (!ev_is_active (w))) |
4218 | if (expect_false (!ev_is_active (w))) |
4182 | return; |
4219 | return; |
4183 | |
4220 | |
… | |
… | |
4196 | } |
4233 | } |
4197 | #endif |
4234 | #endif |
4198 | |
4235 | |
4199 | #if EV_CLEANUP_ENABLE |
4236 | #if EV_CLEANUP_ENABLE |
4200 | void |
4237 | void |
4201 | ev_cleanup_start (EV_P_ ev_cleanup *w) |
4238 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4202 | { |
4239 | { |
4203 | if (expect_false (ev_is_active (w))) |
4240 | if (expect_false (ev_is_active (w))) |
4204 | return; |
4241 | return; |
4205 | |
4242 | |
4206 | EV_FREQUENT_CHECK; |
4243 | EV_FREQUENT_CHECK; |
… | |
… | |
4213 | ev_unref (EV_A); |
4250 | ev_unref (EV_A); |
4214 | EV_FREQUENT_CHECK; |
4251 | EV_FREQUENT_CHECK; |
4215 | } |
4252 | } |
4216 | |
4253 | |
4217 | void |
4254 | void |
4218 | ev_cleanup_stop (EV_P_ ev_cleanup *w) |
4255 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4219 | { |
4256 | { |
4220 | clear_pending (EV_A_ (W)w); |
4257 | clear_pending (EV_A_ (W)w); |
4221 | if (expect_false (!ev_is_active (w))) |
4258 | if (expect_false (!ev_is_active (w))) |
4222 | return; |
4259 | return; |
4223 | |
4260 | |
… | |
… | |
4237 | } |
4274 | } |
4238 | #endif |
4275 | #endif |
4239 | |
4276 | |
4240 | #if EV_ASYNC_ENABLE |
4277 | #if EV_ASYNC_ENABLE |
4241 | void |
4278 | void |
4242 | ev_async_start (EV_P_ ev_async *w) |
4279 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4243 | { |
4280 | { |
4244 | if (expect_false (ev_is_active (w))) |
4281 | if (expect_false (ev_is_active (w))) |
4245 | return; |
4282 | return; |
4246 | |
4283 | |
4247 | w->sent = 0; |
4284 | w->sent = 0; |
… | |
… | |
4256 | |
4293 | |
4257 | EV_FREQUENT_CHECK; |
4294 | EV_FREQUENT_CHECK; |
4258 | } |
4295 | } |
4259 | |
4296 | |
4260 | void |
4297 | void |
4261 | ev_async_stop (EV_P_ ev_async *w) |
4298 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4262 | { |
4299 | { |
4263 | clear_pending (EV_A_ (W)w); |
4300 | clear_pending (EV_A_ (W)w); |
4264 | if (expect_false (!ev_is_active (w))) |
4301 | if (expect_false (!ev_is_active (w))) |
4265 | return; |
4302 | return; |
4266 | |
4303 | |
… | |
… | |
4277 | |
4314 | |
4278 | EV_FREQUENT_CHECK; |
4315 | EV_FREQUENT_CHECK; |
4279 | } |
4316 | } |
4280 | |
4317 | |
4281 | void |
4318 | void |
4282 | ev_async_send (EV_P_ ev_async *w) |
4319 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
4283 | { |
4320 | { |
4284 | w->sent = 1; |
4321 | w->sent = 1; |
4285 | evpipe_write (EV_A_ &async_pending); |
4322 | evpipe_write (EV_A_ &async_pending); |
4286 | } |
4323 | } |
4287 | #endif |
4324 | #endif |
… | |
… | |
4324 | |
4361 | |
4325 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4362 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4326 | } |
4363 | } |
4327 | |
4364 | |
4328 | void |
4365 | void |
4329 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
4366 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW |
4330 | { |
4367 | { |
4331 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4368 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4332 | |
4369 | |
4333 | if (expect_false (!once)) |
4370 | if (expect_false (!once)) |
4334 | { |
4371 | { |
… | |
… | |
4356 | |
4393 | |
4357 | /*****************************************************************************/ |
4394 | /*****************************************************************************/ |
4358 | |
4395 | |
4359 | #if EV_WALK_ENABLE |
4396 | #if EV_WALK_ENABLE |
4360 | void ecb_cold |
4397 | void ecb_cold |
4361 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) |
4398 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
4362 | { |
4399 | { |
4363 | int i, j; |
4400 | int i, j; |
4364 | ev_watcher_list *wl, *wn; |
4401 | ev_watcher_list *wl, *wn; |
4365 | |
4402 | |
4366 | if (types & (EV_IO | EV_EMBED)) |
4403 | if (types & (EV_IO | EV_EMBED)) |