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 |
… | |
… | |
183 | # include EV_H |
183 | # include EV_H |
184 | #else |
184 | #else |
185 | # include "ev.h" |
185 | # include "ev.h" |
186 | #endif |
186 | #endif |
187 | |
187 | |
|
|
188 | #if EV_NO_THREADS |
|
|
189 | # undef EV_NO_SMP |
|
|
190 | # define EV_NO_SMP 1 |
|
|
191 | # undef ECB_NO_THREADS |
|
|
192 | # define ECB_NO_THREADS 1 |
|
|
193 | #endif |
|
|
194 | #if EV_NO_SMP |
|
|
195 | # undef EV_NO_SMP |
|
|
196 | # define ECB_NO_SMP 1 |
|
|
197 | #endif |
|
|
198 | |
188 | #ifndef _WIN32 |
199 | #ifndef _WIN32 |
189 | # include <sys/time.h> |
200 | # include <sys/time.h> |
190 | # include <sys/wait.h> |
201 | # include <sys/wait.h> |
191 | # include <unistd.h> |
202 | # include <unistd.h> |
192 | #else |
203 | #else |
193 | # include <io.h> |
204 | # include <io.h> |
194 | # define WIN32_LEAN_AND_MEAN |
205 | # define WIN32_LEAN_AND_MEAN |
195 | # include <windows.h> |
206 | # include <windows.h> |
|
|
207 | # include <winsock2.h> |
196 | # ifndef EV_SELECT_IS_WINSOCKET |
208 | # ifndef EV_SELECT_IS_WINSOCKET |
197 | # define EV_SELECT_IS_WINSOCKET 1 |
209 | # define EV_SELECT_IS_WINSOCKET 1 |
198 | # endif |
210 | # endif |
199 | # undef EV_AVOID_STDIO |
211 | # undef EV_AVOID_STDIO |
200 | #endif |
212 | #endif |
… | |
… | |
208 | #define _DARWIN_UNLIMITED_SELECT 1 |
220 | #define _DARWIN_UNLIMITED_SELECT 1 |
209 | |
221 | |
210 | /* 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 */ |
211 | |
223 | |
212 | /* try to deduce the maximum number of signals on this platform */ |
224 | /* try to deduce the maximum number of signals on this platform */ |
213 | #if defined (EV_NSIG) |
225 | #if defined EV_NSIG |
214 | /* use what's provided */ |
226 | /* use what's provided */ |
215 | #elif defined (NSIG) |
227 | #elif defined NSIG |
216 | # define EV_NSIG (NSIG) |
228 | # define EV_NSIG (NSIG) |
217 | #elif defined(_NSIG) |
229 | #elif defined _NSIG |
218 | # define EV_NSIG (_NSIG) |
230 | # define EV_NSIG (_NSIG) |
219 | #elif defined (SIGMAX) |
231 | #elif defined SIGMAX |
220 | # define EV_NSIG (SIGMAX+1) |
232 | # define EV_NSIG (SIGMAX+1) |
221 | #elif defined (SIG_MAX) |
233 | #elif defined SIG_MAX |
222 | # define EV_NSIG (SIG_MAX+1) |
234 | # define EV_NSIG (SIG_MAX+1) |
223 | #elif defined (_SIG_MAX) |
235 | #elif defined _SIG_MAX |
224 | # define EV_NSIG (_SIG_MAX+1) |
236 | # define EV_NSIG (_SIG_MAX+1) |
225 | #elif defined (MAXSIG) |
237 | #elif defined MAXSIG |
226 | # define EV_NSIG (MAXSIG+1) |
238 | # define EV_NSIG (MAXSIG+1) |
227 | #elif defined (MAX_SIG) |
239 | #elif defined MAX_SIG |
228 | # define EV_NSIG (MAX_SIG+1) |
240 | # define EV_NSIG (MAX_SIG+1) |
229 | #elif defined (SIGARRAYSIZE) |
241 | #elif defined SIGARRAYSIZE |
230 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
242 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
231 | #elif defined (_sys_nsig) |
243 | #elif defined _sys_nsig |
232 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
244 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
233 | #else |
245 | #else |
234 | # error "unable to find value for NSIG, please report" |
246 | # error "unable to find value for NSIG, please report" |
235 | /* to make it compile regardless, just remove the above line, */ |
247 | /* to make it compile regardless, just remove the above line, */ |
236 | /* but consider reporting it, too! :) */ |
248 | /* but consider reporting it, too! :) */ |
… | |
… | |
248 | # define EV_USE_CLOCK_SYSCALL 0 |
260 | # define EV_USE_CLOCK_SYSCALL 0 |
249 | # endif |
261 | # endif |
250 | #endif |
262 | #endif |
251 | |
263 | |
252 | #ifndef EV_USE_MONOTONIC |
264 | #ifndef EV_USE_MONOTONIC |
253 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
265 | # if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0 |
254 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
266 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
255 | # else |
267 | # else |
256 | # define EV_USE_MONOTONIC 0 |
268 | # define EV_USE_MONOTONIC 0 |
257 | # endif |
269 | # endif |
258 | #endif |
270 | #endif |
… | |
… | |
348 | #endif |
360 | #endif |
349 | |
361 | |
350 | /* 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, */ |
351 | /* which makes programs even slower. might work on other unices, too. */ |
363 | /* which makes programs even slower. might work on other unices, too. */ |
352 | #if EV_USE_CLOCK_SYSCALL |
364 | #if EV_USE_CLOCK_SYSCALL |
353 | # include <syscall.h> |
365 | # include <sys/syscall.h> |
354 | # ifdef SYS_clock_gettime |
366 | # ifdef SYS_clock_gettime |
355 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
367 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
356 | # undef EV_USE_MONOTONIC |
368 | # undef EV_USE_MONOTONIC |
357 | # define EV_USE_MONOTONIC 1 |
369 | # define EV_USE_MONOTONIC 1 |
358 | # else |
370 | # else |
… | |
… | |
384 | # define EV_USE_INOTIFY 0 |
396 | # define EV_USE_INOTIFY 0 |
385 | #endif |
397 | #endif |
386 | |
398 | |
387 | #if !EV_USE_NANOSLEEP |
399 | #if !EV_USE_NANOSLEEP |
388 | /* 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 */ |
389 | # if !defined(_WIN32) && !defined(__hpux) |
401 | # if !defined _WIN32 && !defined __hpux |
390 | # include <sys/select.h> |
402 | # include <sys/select.h> |
391 | # endif |
403 | # endif |
392 | #endif |
404 | #endif |
393 | |
405 | |
394 | #if EV_USE_INOTIFY |
406 | #if EV_USE_INOTIFY |
… | |
… | |
397 | /* 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 */ |
398 | # ifndef IN_DONT_FOLLOW |
410 | # ifndef IN_DONT_FOLLOW |
399 | # undef EV_USE_INOTIFY |
411 | # undef EV_USE_INOTIFY |
400 | # define EV_USE_INOTIFY 0 |
412 | # define EV_USE_INOTIFY 0 |
401 | # endif |
413 | # endif |
402 | #endif |
|
|
403 | |
|
|
404 | #if EV_SELECT_IS_WINSOCKET |
|
|
405 | # include <winsock.h> |
|
|
406 | #endif |
414 | #endif |
407 | |
415 | |
408 | #if EV_USE_EVENTFD |
416 | #if EV_USE_EVENTFD |
409 | /* 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 */ |
410 | # include <stdint.h> |
418 | # include <stdint.h> |
… | |
… | |
522 | * or so. |
530 | * or so. |
523 | * 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 |
524 | * 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. |
525 | */ |
533 | */ |
526 | #ifndef ECB_GCC_VERSION |
534 | #ifndef ECB_GCC_VERSION |
527 | #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__ |
528 | #define ECB_GCC_VERSION(major,minor) 0 |
536 | #define ECB_GCC_VERSION(major,minor) 0 |
529 | #else |
537 | #else |
530 | #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))) |
531 | #endif |
539 | #endif |
532 | #endif |
540 | #endif |
… | |
… | |
534 | /*****************************************************************************/ |
542 | /*****************************************************************************/ |
535 | |
543 | |
536 | /* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ |
544 | /* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ |
537 | /* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ |
545 | /* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ |
538 | |
546 | |
|
|
547 | #if ECB_NO_THREADS |
|
|
548 | # define ECB_NO_SMP 1 |
|
|
549 | #endif |
|
|
550 | |
539 | #if ECB_NO_THREADS || ECB_NO_SMP |
551 | #if ECB_NO_THREADS || ECB_NO_SMP |
540 | #define ECB_MEMORY_FENCE do { } while (0) |
552 | #define ECB_MEMORY_FENCE do { } while (0) |
541 | #endif |
553 | #endif |
542 | |
554 | |
543 | #ifndef ECB_MEMORY_FENCE |
555 | #ifndef ECB_MEMORY_FENCE |
544 | #if ECB_GCC_VERSION(2,5) || defined(__INTEL_COMPILER) || defined(__clang__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
556 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
545 | #if __i386 || __i386__ |
557 | #if __i386 || __i386__ |
546 | #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") |
547 | #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 */ |
548 | #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 */ |
549 | #elif __amd64 || __amd64__ || __x86_64 || __x86_64__ |
561 | #elif __amd64 || __amd64__ || __x86_64 || __x86_64__ |
550 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
562 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
551 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") |
563 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") |
552 | #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 */ |
553 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
565 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
554 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
566 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
555 | #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \ |
567 | #elif defined __ARM_ARCH_6__ || defined __ARM_ARCH_6J__ \ |
556 | || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) |
568 | || defined __ARM_ARCH_6K__ || defined __ARM_ARCH_6ZK__ |
557 | #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") |
558 | #elif defined(__ARM_ARCH_7__ ) || defined(__ARM_ARCH_7A__ ) \ |
570 | #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \ |
559 | || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ ) |
571 | || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__ |
560 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
572 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
561 | #elif __sparc || __sparc__ |
573 | #elif __sparc || __sparc__ |
562 | #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") |
563 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") |
575 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") |
564 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") |
576 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") |
|
|
577 | #elif defined __s390__ || defined __s390x__ |
|
|
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") |
565 | #endif |
583 | #endif |
566 | #endif |
584 | #endif |
567 | #endif |
585 | #endif |
568 | |
586 | |
569 | #ifndef ECB_MEMORY_FENCE |
587 | #ifndef ECB_MEMORY_FENCE |
570 | #if ECB_GCC_VERSION(4,4) || defined(__INTEL_COMPILER) || defined(__clang__) |
588 | #if ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
571 | #define ECB_MEMORY_FENCE __sync_synchronize () |
589 | #define ECB_MEMORY_FENCE __sync_synchronize () |
572 | /*#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); }) */ |
573 | /*#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 ); }) */ |
574 | #elif _MSC_VER >= 1400 /* VC++ 2005 */ |
592 | #elif _MSC_VER >= 1400 /* VC++ 2005 */ |
575 | #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) |
593 | #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) |
576 | #define ECB_MEMORY_FENCE _ReadWriteBarrier () |
594 | #define ECB_MEMORY_FENCE _ReadWriteBarrier () |
577 | #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 */ |
578 | #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () |
596 | #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () |
579 | #elif defined(_WIN32) |
597 | #elif defined _WIN32 |
580 | #include <WinNT.h> |
598 | #include <WinNT.h> |
581 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
599 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
582 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
600 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
583 | #include <mbarrier.h> |
601 | #include <mbarrier.h> |
584 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
602 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
585 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () |
603 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () |
586 | #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 () |
587 | #endif |
607 | #endif |
588 | #endif |
608 | #endif |
589 | |
609 | |
590 | #ifndef ECB_MEMORY_FENCE |
610 | #ifndef ECB_MEMORY_FENCE |
591 | #if !ECB_AVOID_PTHREADS |
611 | #if !ECB_AVOID_PTHREADS |
… | |
… | |
603 | static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; |
623 | static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; |
604 | #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) |
605 | #endif |
625 | #endif |
606 | #endif |
626 | #endif |
607 | |
627 | |
608 | #if !defined(ECB_MEMORY_FENCE_ACQUIRE) && defined(ECB_MEMORY_FENCE) |
628 | #if !defined ECB_MEMORY_FENCE_ACQUIRE && defined ECB_MEMORY_FENCE |
609 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
629 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
610 | #endif |
630 | #endif |
611 | |
631 | |
612 | #if !defined(ECB_MEMORY_FENCE_RELEASE) && defined(ECB_MEMORY_FENCE) |
632 | #if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE |
613 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
633 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
614 | #endif |
634 | #endif |
615 | |
635 | |
616 | /*****************************************************************************/ |
636 | /*****************************************************************************/ |
617 | |
637 | |
… | |
… | |
854 | |
874 | |
855 | #if ECB_GCC_VERSION(4,5) |
875 | #if ECB_GCC_VERSION(4,5) |
856 | #define ecb_unreachable() __builtin_unreachable () |
876 | #define ecb_unreachable() __builtin_unreachable () |
857 | #else |
877 | #else |
858 | /* this seems to work fine, but gcc always emits a warning for it :/ */ |
878 | /* this seems to work fine, but gcc always emits a warning for it :/ */ |
859 | ecb_function_ void ecb_unreachable (void) ecb_noreturn; |
879 | ecb_inline void ecb_unreachable (void) ecb_noreturn; |
860 | ecb_function_ void ecb_unreachable (void) { } |
880 | ecb_inline void ecb_unreachable (void) { } |
861 | #endif |
881 | #endif |
862 | |
882 | |
863 | /* try to tell the compiler that some condition is definitely true */ |
883 | /* try to tell the compiler that some condition is definitely true */ |
864 | #define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) |
884 | #define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) |
865 | |
885 | |
866 | ecb_function_ unsigned char ecb_byteorder_helper (void) ecb_const; |
886 | ecb_inline unsigned char ecb_byteorder_helper (void) ecb_const; |
867 | ecb_function_ unsigned char |
887 | ecb_inline unsigned char |
868 | ecb_byteorder_helper (void) |
888 | ecb_byteorder_helper (void) |
869 | { |
889 | { |
870 | const uint32_t u = 0x11223344; |
890 | const uint32_t u = 0x11223344; |
871 | return *(unsigned char *)&u; |
891 | return *(unsigned char *)&u; |
872 | } |
892 | } |
873 | |
893 | |
874 | ecb_function_ ecb_bool ecb_big_endian (void) ecb_const; |
894 | ecb_inline ecb_bool ecb_big_endian (void) ecb_const; |
875 | ecb_function_ ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } |
895 | ecb_inline ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } |
876 | ecb_function_ ecb_bool ecb_little_endian (void) ecb_const; |
896 | ecb_inline ecb_bool ecb_little_endian (void) ecb_const; |
877 | ecb_function_ ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; } |
897 | ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; } |
878 | |
898 | |
879 | #if ECB_GCC_VERSION(3,0) || ECB_C99 |
899 | #if ECB_GCC_VERSION(3,0) || ECB_C99 |
880 | #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) |
900 | #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) |
881 | #else |
901 | #else |
882 | #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) |
902 | #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) |
… | |
… | |
1082 | { |
1102 | { |
1083 | write (STDERR_FILENO, msg, strlen (msg)); |
1103 | write (STDERR_FILENO, msg, strlen (msg)); |
1084 | } |
1104 | } |
1085 | #endif |
1105 | #endif |
1086 | |
1106 | |
1087 | static void (*syserr_cb)(const char *msg); |
1107 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1088 | |
1108 | |
1089 | void ecb_cold |
1109 | void ecb_cold |
1090 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
1110 | ev_set_syserr_cb (void (*cb)(const char *msg)) EV_THROW |
1091 | { |
1111 | { |
1092 | syserr_cb = cb; |
1112 | syserr_cb = cb; |
1093 | } |
1113 | } |
1094 | |
1114 | |
1095 | static void noinline ecb_cold |
1115 | static void noinline ecb_cold |
… | |
… | |
1131 | free (ptr); |
1151 | free (ptr); |
1132 | return 0; |
1152 | return 0; |
1133 | #endif |
1153 | #endif |
1134 | } |
1154 | } |
1135 | |
1155 | |
1136 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
1156 | static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; |
1137 | |
1157 | |
1138 | void ecb_cold |
1158 | void ecb_cold |
1139 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
1159 | ev_set_allocator (void *(*cb)(void *ptr, long size)) EV_THROW |
1140 | { |
1160 | { |
1141 | alloc = cb; |
1161 | alloc = cb; |
1142 | } |
1162 | } |
1143 | |
1163 | |
1144 | inline_speed void * |
1164 | inline_speed void * |
… | |
… | |
1261 | |
1281 | |
1262 | /*****************************************************************************/ |
1282 | /*****************************************************************************/ |
1263 | |
1283 | |
1264 | #ifndef EV_HAVE_EV_TIME |
1284 | #ifndef EV_HAVE_EV_TIME |
1265 | ev_tstamp |
1285 | ev_tstamp |
1266 | ev_time (void) |
1286 | ev_time (void) EV_THROW |
1267 | { |
1287 | { |
1268 | #if EV_USE_REALTIME |
1288 | #if EV_USE_REALTIME |
1269 | if (expect_true (have_realtime)) |
1289 | if (expect_true (have_realtime)) |
1270 | { |
1290 | { |
1271 | struct timespec ts; |
1291 | struct timespec ts; |
… | |
… | |
1295 | return ev_time (); |
1315 | return ev_time (); |
1296 | } |
1316 | } |
1297 | |
1317 | |
1298 | #if EV_MULTIPLICITY |
1318 | #if EV_MULTIPLICITY |
1299 | ev_tstamp |
1319 | ev_tstamp |
1300 | ev_now (EV_P) |
1320 | ev_now (EV_P) EV_THROW |
1301 | { |
1321 | { |
1302 | return ev_rt_now; |
1322 | return ev_rt_now; |
1303 | } |
1323 | } |
1304 | #endif |
1324 | #endif |
1305 | |
1325 | |
1306 | void |
1326 | void |
1307 | ev_sleep (ev_tstamp delay) |
1327 | ev_sleep (ev_tstamp delay) EV_THROW |
1308 | { |
1328 | { |
1309 | if (delay > 0.) |
1329 | if (delay > 0.) |
1310 | { |
1330 | { |
1311 | #if EV_USE_NANOSLEEP |
1331 | #if EV_USE_NANOSLEEP |
1312 | struct timespec ts; |
1332 | struct timespec ts; |
1313 | |
1333 | |
1314 | EV_TS_SET (ts, delay); |
1334 | EV_TS_SET (ts, delay); |
1315 | nanosleep (&ts, 0); |
1335 | nanosleep (&ts, 0); |
1316 | #elif defined(_WIN32) |
1336 | #elif defined _WIN32 |
1317 | Sleep ((unsigned long)(delay * 1e3)); |
1337 | Sleep ((unsigned long)(delay * 1e3)); |
1318 | #else |
1338 | #else |
1319 | struct timeval tv; |
1339 | struct timeval tv; |
1320 | |
1340 | |
1321 | /* 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 */ |
… | |
… | |
1393 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1413 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1394 | { |
1414 | { |
1395 | } |
1415 | } |
1396 | |
1416 | |
1397 | void noinline |
1417 | void noinline |
1398 | ev_feed_event (EV_P_ void *w, int revents) |
1418 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
1399 | { |
1419 | { |
1400 | W w_ = (W)w; |
1420 | W w_ = (W)w; |
1401 | int pri = ABSPRI (w_); |
1421 | int pri = ABSPRI (w_); |
1402 | |
1422 | |
1403 | if (expect_false (w_->pending)) |
1423 | if (expect_false (w_->pending)) |
… | |
… | |
1407 | w_->pending = ++pendingcnt [pri]; |
1427 | w_->pending = ++pendingcnt [pri]; |
1408 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
1428 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
1409 | pendings [pri][w_->pending - 1].w = w_; |
1429 | pendings [pri][w_->pending - 1].w = w_; |
1410 | pendings [pri][w_->pending - 1].events = revents; |
1430 | pendings [pri][w_->pending - 1].events = revents; |
1411 | } |
1431 | } |
|
|
1432 | |
|
|
1433 | pendingpri = NUMPRI - 1; |
1412 | } |
1434 | } |
1413 | |
1435 | |
1414 | inline_speed void |
1436 | inline_speed void |
1415 | feed_reverse (EV_P_ W w) |
1437 | feed_reverse (EV_P_ W w) |
1416 | { |
1438 | { |
… | |
… | |
1462 | if (expect_true (!anfd->reify)) |
1484 | if (expect_true (!anfd->reify)) |
1463 | fd_event_nocheck (EV_A_ fd, revents); |
1485 | fd_event_nocheck (EV_A_ fd, revents); |
1464 | } |
1486 | } |
1465 | |
1487 | |
1466 | void |
1488 | void |
1467 | ev_feed_fd_event (EV_P_ int fd, int revents) |
1489 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW |
1468 | { |
1490 | { |
1469 | if (fd >= 0 && fd < anfdmax) |
1491 | if (fd >= 0 && fd < anfdmax) |
1470 | fd_event_nocheck (EV_A_ fd, revents); |
1492 | fd_event_nocheck (EV_A_ fd, revents); |
1471 | } |
1493 | } |
1472 | |
1494 | |
… | |
… | |
1821 | } |
1843 | } |
1822 | |
1844 | |
1823 | inline_speed void |
1845 | inline_speed void |
1824 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1846 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1825 | { |
1847 | { |
|
|
1848 | ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */ |
|
|
1849 | |
1826 | if (expect_true (*flag)) |
1850 | if (expect_true (*flag)) |
1827 | return; |
1851 | return; |
1828 | |
1852 | |
1829 | *flag = 1; |
1853 | *flag = 1; |
1830 | |
1854 | |
… | |
… | |
1849 | write (evfd, &counter, sizeof (uint64_t)); |
1873 | write (evfd, &counter, sizeof (uint64_t)); |
1850 | } |
1874 | } |
1851 | else |
1875 | else |
1852 | #endif |
1876 | #endif |
1853 | { |
1877 | { |
1854 | /* win32 people keep sending patches that change this write() to send() */ |
1878 | #ifdef _WIN32 |
1855 | /* and then run away. but send() is wrong, it wants a socket handle on win32 */ |
1879 | WSABUF buf; |
1856 | /* so when you think this write should be a send instead, please find out */ |
1880 | DWORD sent; |
1857 | /* where your send() is from - it's definitely not the microsoft send, and */ |
1881 | buf.buf = &buf; |
1858 | /* 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 |
1859 | write (evpipe [1], &(evpipe [1]), 1); |
1885 | write (evpipe [1], &(evpipe [1]), 1); |
|
|
1886 | #endif |
1860 | } |
1887 | } |
1861 | |
1888 | |
1862 | errno = old_errno; |
1889 | errno = old_errno; |
1863 | } |
1890 | } |
1864 | } |
1891 | } |
… | |
… | |
1879 | read (evfd, &counter, sizeof (uint64_t)); |
1906 | read (evfd, &counter, sizeof (uint64_t)); |
1880 | } |
1907 | } |
1881 | else |
1908 | else |
1882 | #endif |
1909 | #endif |
1883 | { |
1910 | { |
1884 | char dummy; |
1911 | char dummy[4]; |
1885 | /* 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 |
1886 | read (evpipe [0], &dummy, 1); |
1919 | read (evpipe [0], &dummy, sizeof (dummy)); |
|
|
1920 | #endif |
1887 | } |
1921 | } |
1888 | } |
1922 | } |
1889 | |
1923 | |
1890 | pipe_write_skipped = 0; |
1924 | pipe_write_skipped = 0; |
|
|
1925 | |
|
|
1926 | ECB_MEMORY_FENCE; /* push out skipped, acquire flags */ |
1891 | |
1927 | |
1892 | #if EV_SIGNAL_ENABLE |
1928 | #if EV_SIGNAL_ENABLE |
1893 | if (sig_pending) |
1929 | if (sig_pending) |
1894 | { |
1930 | { |
1895 | sig_pending = 0; |
1931 | sig_pending = 0; |
|
|
1932 | |
|
|
1933 | ECB_MEMORY_FENCE_RELEASE; |
1896 | |
1934 | |
1897 | for (i = EV_NSIG - 1; i--; ) |
1935 | for (i = EV_NSIG - 1; i--; ) |
1898 | if (expect_false (signals [i].pending)) |
1936 | if (expect_false (signals [i].pending)) |
1899 | ev_feed_signal_event (EV_A_ i + 1); |
1937 | ev_feed_signal_event (EV_A_ i + 1); |
1900 | } |
1938 | } |
… | |
… | |
1902 | |
1940 | |
1903 | #if EV_ASYNC_ENABLE |
1941 | #if EV_ASYNC_ENABLE |
1904 | if (async_pending) |
1942 | if (async_pending) |
1905 | { |
1943 | { |
1906 | async_pending = 0; |
1944 | async_pending = 0; |
|
|
1945 | |
|
|
1946 | ECB_MEMORY_FENCE_RELEASE; |
1907 | |
1947 | |
1908 | for (i = asynccnt; i--; ) |
1948 | for (i = asynccnt; i--; ) |
1909 | if (asyncs [i]->sent) |
1949 | if (asyncs [i]->sent) |
1910 | { |
1950 | { |
1911 | asyncs [i]->sent = 0; |
1951 | asyncs [i]->sent = 0; |
… | |
… | |
1916 | } |
1956 | } |
1917 | |
1957 | |
1918 | /*****************************************************************************/ |
1958 | /*****************************************************************************/ |
1919 | |
1959 | |
1920 | void |
1960 | void |
1921 | ev_feed_signal (int signum) |
1961 | ev_feed_signal (int signum) EV_THROW |
1922 | { |
1962 | { |
1923 | #if EV_MULTIPLICITY |
1963 | #if EV_MULTIPLICITY |
1924 | EV_P = signals [signum - 1].loop; |
1964 | EV_P = signals [signum - 1].loop; |
1925 | |
1965 | |
1926 | if (!EV_A) |
1966 | if (!EV_A) |
… | |
… | |
1943 | |
1983 | |
1944 | ev_feed_signal (signum); |
1984 | ev_feed_signal (signum); |
1945 | } |
1985 | } |
1946 | |
1986 | |
1947 | void noinline |
1987 | void noinline |
1948 | ev_feed_signal_event (EV_P_ int signum) |
1988 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
1949 | { |
1989 | { |
1950 | WL w; |
1990 | WL w; |
1951 | |
1991 | |
1952 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
1992 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
1953 | return; |
1993 | return; |
… | |
… | |
2069 | #if EV_USE_SELECT |
2109 | #if EV_USE_SELECT |
2070 | # include "ev_select.c" |
2110 | # include "ev_select.c" |
2071 | #endif |
2111 | #endif |
2072 | |
2112 | |
2073 | int ecb_cold |
2113 | int ecb_cold |
2074 | ev_version_major (void) |
2114 | ev_version_major (void) EV_THROW |
2075 | { |
2115 | { |
2076 | return EV_VERSION_MAJOR; |
2116 | return EV_VERSION_MAJOR; |
2077 | } |
2117 | } |
2078 | |
2118 | |
2079 | int ecb_cold |
2119 | int ecb_cold |
2080 | ev_version_minor (void) |
2120 | ev_version_minor (void) EV_THROW |
2081 | { |
2121 | { |
2082 | return EV_VERSION_MINOR; |
2122 | return EV_VERSION_MINOR; |
2083 | } |
2123 | } |
2084 | |
2124 | |
2085 | /* 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 */ |
… | |
… | |
2093 | || getgid () != getegid (); |
2133 | || getgid () != getegid (); |
2094 | #endif |
2134 | #endif |
2095 | } |
2135 | } |
2096 | |
2136 | |
2097 | unsigned int ecb_cold |
2137 | unsigned int ecb_cold |
2098 | ev_supported_backends (void) |
2138 | ev_supported_backends (void) EV_THROW |
2099 | { |
2139 | { |
2100 | unsigned int flags = 0; |
2140 | unsigned int flags = 0; |
2101 | |
2141 | |
2102 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2142 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2103 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2143 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
… | |
… | |
2107 | |
2147 | |
2108 | return flags; |
2148 | return flags; |
2109 | } |
2149 | } |
2110 | |
2150 | |
2111 | unsigned int ecb_cold |
2151 | unsigned int ecb_cold |
2112 | ev_recommended_backends (void) |
2152 | ev_recommended_backends (void) EV_THROW |
2113 | { |
2153 | { |
2114 | unsigned int flags = ev_supported_backends (); |
2154 | unsigned int flags = ev_supported_backends (); |
2115 | |
2155 | |
2116 | #ifndef __NetBSD__ |
2156 | #ifndef __NetBSD__ |
2117 | /* kqueue is borked on everything but netbsd apparently */ |
2157 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2129 | |
2169 | |
2130 | return flags; |
2170 | return flags; |
2131 | } |
2171 | } |
2132 | |
2172 | |
2133 | unsigned int ecb_cold |
2173 | unsigned int ecb_cold |
2134 | ev_embeddable_backends (void) |
2174 | ev_embeddable_backends (void) EV_THROW |
2135 | { |
2175 | { |
2136 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2176 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2137 | |
2177 | |
2138 | /* 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 */ |
2139 | 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 */ |
… | |
… | |
2141 | |
2181 | |
2142 | return flags; |
2182 | return flags; |
2143 | } |
2183 | } |
2144 | |
2184 | |
2145 | unsigned int |
2185 | unsigned int |
2146 | ev_backend (EV_P) |
2186 | ev_backend (EV_P) EV_THROW |
2147 | { |
2187 | { |
2148 | return backend; |
2188 | return backend; |
2149 | } |
2189 | } |
2150 | |
2190 | |
2151 | #if EV_FEATURE_API |
2191 | #if EV_FEATURE_API |
2152 | unsigned int |
2192 | unsigned int |
2153 | ev_iteration (EV_P) |
2193 | ev_iteration (EV_P) EV_THROW |
2154 | { |
2194 | { |
2155 | return loop_count; |
2195 | return loop_count; |
2156 | } |
2196 | } |
2157 | |
2197 | |
2158 | unsigned int |
2198 | unsigned int |
2159 | ev_depth (EV_P) |
2199 | ev_depth (EV_P) EV_THROW |
2160 | { |
2200 | { |
2161 | return loop_depth; |
2201 | return loop_depth; |
2162 | } |
2202 | } |
2163 | |
2203 | |
2164 | void |
2204 | void |
2165 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) |
2205 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2166 | { |
2206 | { |
2167 | io_blocktime = interval; |
2207 | io_blocktime = interval; |
2168 | } |
2208 | } |
2169 | |
2209 | |
2170 | void |
2210 | void |
2171 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) |
2211 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2172 | { |
2212 | { |
2173 | timeout_blocktime = interval; |
2213 | timeout_blocktime = interval; |
2174 | } |
2214 | } |
2175 | |
2215 | |
2176 | void |
2216 | void |
2177 | ev_set_userdata (EV_P_ void *data) |
2217 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2178 | { |
2218 | { |
2179 | userdata = data; |
2219 | userdata = data; |
2180 | } |
2220 | } |
2181 | |
2221 | |
2182 | void * |
2222 | void * |
2183 | ev_userdata (EV_P) |
2223 | ev_userdata (EV_P) EV_THROW |
2184 | { |
2224 | { |
2185 | return userdata; |
2225 | return userdata; |
2186 | } |
2226 | } |
2187 | |
2227 | |
2188 | void |
2228 | void |
2189 | 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 |
2190 | { |
2230 | { |
2191 | invoke_cb = invoke_pending_cb; |
2231 | invoke_cb = invoke_pending_cb; |
2192 | } |
2232 | } |
2193 | |
2233 | |
2194 | void |
2234 | void |
2195 | 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 |
2196 | { |
2236 | { |
2197 | release_cb = release; |
2237 | release_cb = release; |
2198 | acquire_cb = acquire; |
2238 | acquire_cb = acquire; |
2199 | } |
2239 | } |
2200 | #endif |
2240 | #endif |
2201 | |
2241 | |
2202 | /* initialise a loop structure, must be zero-initialised */ |
2242 | /* initialise a loop structure, must be zero-initialised */ |
2203 | static void noinline ecb_cold |
2243 | static void noinline ecb_cold |
2204 | loop_init (EV_P_ unsigned int flags) |
2244 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2205 | { |
2245 | { |
2206 | if (!backend) |
2246 | if (!backend) |
2207 | { |
2247 | { |
2208 | origflags = flags; |
2248 | origflags = flags; |
2209 | |
2249 | |
… | |
… | |
2462 | } |
2502 | } |
2463 | |
2503 | |
2464 | #if EV_MULTIPLICITY |
2504 | #if EV_MULTIPLICITY |
2465 | |
2505 | |
2466 | struct ev_loop * ecb_cold |
2506 | struct ev_loop * ecb_cold |
2467 | ev_loop_new (unsigned int flags) |
2507 | ev_loop_new (unsigned int flags) EV_THROW |
2468 | { |
2508 | { |
2469 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2509 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2470 | |
2510 | |
2471 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2511 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2472 | loop_init (EV_A_ flags); |
2512 | loop_init (EV_A_ flags); |
… | |
… | |
2516 | } |
2556 | } |
2517 | #endif |
2557 | #endif |
2518 | |
2558 | |
2519 | #if EV_FEATURE_API |
2559 | #if EV_FEATURE_API |
2520 | void ecb_cold |
2560 | void ecb_cold |
2521 | ev_verify (EV_P) |
2561 | ev_verify (EV_P) EV_THROW |
2522 | { |
2562 | { |
2523 | #if EV_VERIFY |
2563 | #if EV_VERIFY |
2524 | int i; |
2564 | int i; |
2525 | WL w; |
2565 | WL w, w2; |
2526 | |
2566 | |
2527 | assert (activecnt >= -1); |
2567 | assert (activecnt >= -1); |
2528 | |
2568 | |
2529 | assert (fdchangemax >= fdchangecnt); |
2569 | assert (fdchangemax >= fdchangecnt); |
2530 | for (i = 0; i < fdchangecnt; ++i) |
2570 | for (i = 0; i < fdchangecnt; ++i) |
2531 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2571 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2532 | |
2572 | |
2533 | assert (anfdmax >= 0); |
2573 | assert (anfdmax >= 0); |
2534 | for (i = 0; i < anfdmax; ++i) |
2574 | for (i = 0; i < anfdmax; ++i) |
|
|
2575 | { |
|
|
2576 | int j = 0; |
|
|
2577 | |
2535 | for (w = anfds [i].head; w; w = w->next) |
2578 | for (w = w2 = anfds [i].head; w; w = w->next) |
2536 | { |
2579 | { |
2537 | 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 | |
2538 | 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)); |
2539 | 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)); |
2540 | } |
2590 | } |
|
|
2591 | } |
2541 | |
2592 | |
2542 | assert (timermax >= timercnt); |
2593 | assert (timermax >= timercnt); |
2543 | verify_heap (EV_A_ timers, timercnt); |
2594 | verify_heap (EV_A_ timers, timercnt); |
2544 | |
2595 | |
2545 | #if EV_PERIODIC_ENABLE |
2596 | #if EV_PERIODIC_ENABLE |
… | |
… | |
2595 | #if EV_MULTIPLICITY |
2646 | #if EV_MULTIPLICITY |
2596 | struct ev_loop * ecb_cold |
2647 | struct ev_loop * ecb_cold |
2597 | #else |
2648 | #else |
2598 | int |
2649 | int |
2599 | #endif |
2650 | #endif |
2600 | ev_default_loop (unsigned int flags) |
2651 | ev_default_loop (unsigned int flags) EV_THROW |
2601 | { |
2652 | { |
2602 | if (!ev_default_loop_ptr) |
2653 | if (!ev_default_loop_ptr) |
2603 | { |
2654 | { |
2604 | #if EV_MULTIPLICITY |
2655 | #if EV_MULTIPLICITY |
2605 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
2656 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
2624 | |
2675 | |
2625 | return ev_default_loop_ptr; |
2676 | return ev_default_loop_ptr; |
2626 | } |
2677 | } |
2627 | |
2678 | |
2628 | void |
2679 | void |
2629 | ev_loop_fork (EV_P) |
2680 | ev_loop_fork (EV_P) EV_THROW |
2630 | { |
2681 | { |
2631 | postfork = 1; /* must be in line with ev_default_fork */ |
2682 | postfork = 1; /* must be in line with ev_default_fork */ |
2632 | } |
2683 | } |
2633 | |
2684 | |
2634 | /*****************************************************************************/ |
2685 | /*****************************************************************************/ |
… | |
… | |
2638 | { |
2689 | { |
2639 | EV_CB_INVOKE ((W)w, revents); |
2690 | EV_CB_INVOKE ((W)w, revents); |
2640 | } |
2691 | } |
2641 | |
2692 | |
2642 | unsigned int |
2693 | unsigned int |
2643 | ev_pending_count (EV_P) |
2694 | ev_pending_count (EV_P) EV_THROW |
2644 | { |
2695 | { |
2645 | int pri; |
2696 | int pri; |
2646 | unsigned int count = 0; |
2697 | unsigned int count = 0; |
2647 | |
2698 | |
2648 | for (pri = NUMPRI; pri--; ) |
2699 | for (pri = NUMPRI; pri--; ) |
… | |
… | |
2652 | } |
2703 | } |
2653 | |
2704 | |
2654 | void noinline |
2705 | void noinline |
2655 | ev_invoke_pending (EV_P) |
2706 | ev_invoke_pending (EV_P) |
2656 | { |
2707 | { |
2657 | int pri; |
2708 | for (pendingpri = NUMPRI; pendingpri--; ) /* pendingpri is modified during the loop */ |
2658 | |
|
|
2659 | for (pri = NUMPRI; pri--; ) |
|
|
2660 | while (pendingcnt [pri]) |
2709 | while (pendingcnt [pendingpri]) |
2661 | { |
2710 | { |
2662 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
2711 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
2663 | |
2712 | |
2664 | p->w->pending = 0; |
2713 | p->w->pending = 0; |
2665 | EV_CB_INVOKE (p->w, p->events); |
2714 | EV_CB_INVOKE (p->w, p->events); |
2666 | EV_FREQUENT_CHECK; |
2715 | EV_FREQUENT_CHECK; |
2667 | } |
2716 | } |
… | |
… | |
2907 | |
2956 | |
2908 | mn_now = ev_rt_now; |
2957 | mn_now = ev_rt_now; |
2909 | } |
2958 | } |
2910 | } |
2959 | } |
2911 | |
2960 | |
2912 | void |
2961 | int |
2913 | ev_run (EV_P_ int flags) |
2962 | ev_run (EV_P_ int flags) |
2914 | { |
2963 | { |
2915 | #if EV_FEATURE_API |
2964 | #if EV_FEATURE_API |
2916 | ++loop_depth; |
2965 | ++loop_depth; |
2917 | #endif |
2966 | #endif |
… | |
… | |
3074 | loop_done = EVBREAK_CANCEL; |
3123 | loop_done = EVBREAK_CANCEL; |
3075 | |
3124 | |
3076 | #if EV_FEATURE_API |
3125 | #if EV_FEATURE_API |
3077 | --loop_depth; |
3126 | --loop_depth; |
3078 | #endif |
3127 | #endif |
|
|
3128 | |
|
|
3129 | return activecnt; |
3079 | } |
3130 | } |
3080 | |
3131 | |
3081 | void |
3132 | void |
3082 | ev_break (EV_P_ int how) |
3133 | ev_break (EV_P_ int how) EV_THROW |
3083 | { |
3134 | { |
3084 | loop_done = how; |
3135 | loop_done = how; |
3085 | } |
3136 | } |
3086 | |
3137 | |
3087 | void |
3138 | void |
3088 | ev_ref (EV_P) |
3139 | ev_ref (EV_P) EV_THROW |
3089 | { |
3140 | { |
3090 | ++activecnt; |
3141 | ++activecnt; |
3091 | } |
3142 | } |
3092 | |
3143 | |
3093 | void |
3144 | void |
3094 | ev_unref (EV_P) |
3145 | ev_unref (EV_P) EV_THROW |
3095 | { |
3146 | { |
3096 | --activecnt; |
3147 | --activecnt; |
3097 | } |
3148 | } |
3098 | |
3149 | |
3099 | void |
3150 | void |
3100 | ev_now_update (EV_P) |
3151 | ev_now_update (EV_P) EV_THROW |
3101 | { |
3152 | { |
3102 | time_update (EV_A_ 1e100); |
3153 | time_update (EV_A_ 1e100); |
3103 | } |
3154 | } |
3104 | |
3155 | |
3105 | void |
3156 | void |
3106 | ev_suspend (EV_P) |
3157 | ev_suspend (EV_P) EV_THROW |
3107 | { |
3158 | { |
3108 | ev_now_update (EV_A); |
3159 | ev_now_update (EV_A); |
3109 | } |
3160 | } |
3110 | |
3161 | |
3111 | void |
3162 | void |
3112 | ev_resume (EV_P) |
3163 | ev_resume (EV_P) EV_THROW |
3113 | { |
3164 | { |
3114 | ev_tstamp mn_prev = mn_now; |
3165 | ev_tstamp mn_prev = mn_now; |
3115 | |
3166 | |
3116 | ev_now_update (EV_A); |
3167 | ev_now_update (EV_A); |
3117 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3168 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3156 | w->pending = 0; |
3207 | w->pending = 0; |
3157 | } |
3208 | } |
3158 | } |
3209 | } |
3159 | |
3210 | |
3160 | int |
3211 | int |
3161 | ev_clear_pending (EV_P_ void *w) |
3212 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3162 | { |
3213 | { |
3163 | W w_ = (W)w; |
3214 | W w_ = (W)w; |
3164 | int pending = w_->pending; |
3215 | int pending = w_->pending; |
3165 | |
3216 | |
3166 | if (expect_true (pending)) |
3217 | if (expect_true (pending)) |
… | |
… | |
3199 | } |
3250 | } |
3200 | |
3251 | |
3201 | /*****************************************************************************/ |
3252 | /*****************************************************************************/ |
3202 | |
3253 | |
3203 | void noinline |
3254 | void noinline |
3204 | ev_io_start (EV_P_ ev_io *w) |
3255 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3205 | { |
3256 | { |
3206 | int fd = w->fd; |
3257 | int fd = w->fd; |
3207 | |
3258 | |
3208 | if (expect_false (ev_is_active (w))) |
3259 | if (expect_false (ev_is_active (w))) |
3209 | return; |
3260 | return; |
… | |
… | |
3215 | |
3266 | |
3216 | ev_start (EV_A_ (W)w, 1); |
3267 | ev_start (EV_A_ (W)w, 1); |
3217 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3268 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3218 | wlist_add (&anfds[fd].head, (WL)w); |
3269 | wlist_add (&anfds[fd].head, (WL)w); |
3219 | |
3270 | |
|
|
3271 | /* common bug, apparently */ |
|
|
3272 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
|
|
3273 | |
3220 | 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); |
3221 | w->events &= ~EV__IOFDSET; |
3275 | w->events &= ~EV__IOFDSET; |
3222 | |
3276 | |
3223 | EV_FREQUENT_CHECK; |
3277 | EV_FREQUENT_CHECK; |
3224 | } |
3278 | } |
3225 | |
3279 | |
3226 | void noinline |
3280 | void noinline |
3227 | ev_io_stop (EV_P_ ev_io *w) |
3281 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3228 | { |
3282 | { |
3229 | clear_pending (EV_A_ (W)w); |
3283 | clear_pending (EV_A_ (W)w); |
3230 | if (expect_false (!ev_is_active (w))) |
3284 | if (expect_false (!ev_is_active (w))) |
3231 | return; |
3285 | return; |
3232 | |
3286 | |
… | |
… | |
3241 | |
3295 | |
3242 | EV_FREQUENT_CHECK; |
3296 | EV_FREQUENT_CHECK; |
3243 | } |
3297 | } |
3244 | |
3298 | |
3245 | void noinline |
3299 | void noinline |
3246 | ev_timer_start (EV_P_ ev_timer *w) |
3300 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3247 | { |
3301 | { |
3248 | if (expect_false (ev_is_active (w))) |
3302 | if (expect_false (ev_is_active (w))) |
3249 | return; |
3303 | return; |
3250 | |
3304 | |
3251 | ev_at (w) += mn_now; |
3305 | ev_at (w) += mn_now; |
… | |
… | |
3265 | |
3319 | |
3266 | /*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));*/ |
3267 | } |
3321 | } |
3268 | |
3322 | |
3269 | void noinline |
3323 | void noinline |
3270 | ev_timer_stop (EV_P_ ev_timer *w) |
3324 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3271 | { |
3325 | { |
3272 | clear_pending (EV_A_ (W)w); |
3326 | clear_pending (EV_A_ (W)w); |
3273 | if (expect_false (!ev_is_active (w))) |
3327 | if (expect_false (!ev_is_active (w))) |
3274 | return; |
3328 | return; |
3275 | |
3329 | |
… | |
… | |
3295 | |
3349 | |
3296 | EV_FREQUENT_CHECK; |
3350 | EV_FREQUENT_CHECK; |
3297 | } |
3351 | } |
3298 | |
3352 | |
3299 | void noinline |
3353 | void noinline |
3300 | ev_timer_again (EV_P_ ev_timer *w) |
3354 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
3301 | { |
3355 | { |
3302 | EV_FREQUENT_CHECK; |
3356 | EV_FREQUENT_CHECK; |
3303 | |
3357 | |
3304 | clear_pending (EV_A_ (W)w); |
3358 | clear_pending (EV_A_ (W)w); |
3305 | |
3359 | |
… | |
… | |
3322 | |
3376 | |
3323 | EV_FREQUENT_CHECK; |
3377 | EV_FREQUENT_CHECK; |
3324 | } |
3378 | } |
3325 | |
3379 | |
3326 | ev_tstamp |
3380 | ev_tstamp |
3327 | ev_timer_remaining (EV_P_ ev_timer *w) |
3381 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
3328 | { |
3382 | { |
3329 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3383 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3330 | } |
3384 | } |
3331 | |
3385 | |
3332 | #if EV_PERIODIC_ENABLE |
3386 | #if EV_PERIODIC_ENABLE |
3333 | void noinline |
3387 | void noinline |
3334 | ev_periodic_start (EV_P_ ev_periodic *w) |
3388 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
3335 | { |
3389 | { |
3336 | if (expect_false (ev_is_active (w))) |
3390 | if (expect_false (ev_is_active (w))) |
3337 | return; |
3391 | return; |
3338 | |
3392 | |
3339 | if (w->reschedule_cb) |
3393 | if (w->reschedule_cb) |
… | |
… | |
3359 | |
3413 | |
3360 | /*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));*/ |
3361 | } |
3415 | } |
3362 | |
3416 | |
3363 | void noinline |
3417 | void noinline |
3364 | ev_periodic_stop (EV_P_ ev_periodic *w) |
3418 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
3365 | { |
3419 | { |
3366 | clear_pending (EV_A_ (W)w); |
3420 | clear_pending (EV_A_ (W)w); |
3367 | if (expect_false (!ev_is_active (w))) |
3421 | if (expect_false (!ev_is_active (w))) |
3368 | return; |
3422 | return; |
3369 | |
3423 | |
… | |
… | |
3387 | |
3441 | |
3388 | EV_FREQUENT_CHECK; |
3442 | EV_FREQUENT_CHECK; |
3389 | } |
3443 | } |
3390 | |
3444 | |
3391 | void noinline |
3445 | void noinline |
3392 | ev_periodic_again (EV_P_ ev_periodic *w) |
3446 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
3393 | { |
3447 | { |
3394 | /* TODO: use adjustheap and recalculation */ |
3448 | /* TODO: use adjustheap and recalculation */ |
3395 | ev_periodic_stop (EV_A_ w); |
3449 | ev_periodic_stop (EV_A_ w); |
3396 | ev_periodic_start (EV_A_ w); |
3450 | ev_periodic_start (EV_A_ w); |
3397 | } |
3451 | } |
… | |
… | |
3402 | #endif |
3456 | #endif |
3403 | |
3457 | |
3404 | #if EV_SIGNAL_ENABLE |
3458 | #if EV_SIGNAL_ENABLE |
3405 | |
3459 | |
3406 | void noinline |
3460 | void noinline |
3407 | ev_signal_start (EV_P_ ev_signal *w) |
3461 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
3408 | { |
3462 | { |
3409 | if (expect_false (ev_is_active (w))) |
3463 | if (expect_false (ev_is_active (w))) |
3410 | return; |
3464 | return; |
3411 | |
3465 | |
3412 | 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)); |
… | |
… | |
3483 | |
3537 | |
3484 | EV_FREQUENT_CHECK; |
3538 | EV_FREQUENT_CHECK; |
3485 | } |
3539 | } |
3486 | |
3540 | |
3487 | void noinline |
3541 | void noinline |
3488 | ev_signal_stop (EV_P_ ev_signal *w) |
3542 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
3489 | { |
3543 | { |
3490 | clear_pending (EV_A_ (W)w); |
3544 | clear_pending (EV_A_ (W)w); |
3491 | if (expect_false (!ev_is_active (w))) |
3545 | if (expect_false (!ev_is_active (w))) |
3492 | return; |
3546 | return; |
3493 | |
3547 | |
… | |
… | |
3524 | #endif |
3578 | #endif |
3525 | |
3579 | |
3526 | #if EV_CHILD_ENABLE |
3580 | #if EV_CHILD_ENABLE |
3527 | |
3581 | |
3528 | void |
3582 | void |
3529 | ev_child_start (EV_P_ ev_child *w) |
3583 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
3530 | { |
3584 | { |
3531 | #if EV_MULTIPLICITY |
3585 | #if EV_MULTIPLICITY |
3532 | 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)); |
3533 | #endif |
3587 | #endif |
3534 | if (expect_false (ev_is_active (w))) |
3588 | if (expect_false (ev_is_active (w))) |
… | |
… | |
3541 | |
3595 | |
3542 | EV_FREQUENT_CHECK; |
3596 | EV_FREQUENT_CHECK; |
3543 | } |
3597 | } |
3544 | |
3598 | |
3545 | void |
3599 | void |
3546 | ev_child_stop (EV_P_ ev_child *w) |
3600 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
3547 | { |
3601 | { |
3548 | clear_pending (EV_A_ (W)w); |
3602 | clear_pending (EV_A_ (W)w); |
3549 | if (expect_false (!ev_is_active (w))) |
3603 | if (expect_false (!ev_is_active (w))) |
3550 | return; |
3604 | return; |
3551 | |
3605 | |
… | |
… | |
3718 | } |
3772 | } |
3719 | |
3773 | |
3720 | inline_size int |
3774 | inline_size int |
3721 | infy_newfd (void) |
3775 | infy_newfd (void) |
3722 | { |
3776 | { |
3723 | #if defined (IN_CLOEXEC) && defined (IN_NONBLOCK) |
3777 | #if defined IN_CLOEXEC && defined IN_NONBLOCK |
3724 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3778 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3725 | if (fd >= 0) |
3779 | if (fd >= 0) |
3726 | return fd; |
3780 | return fd; |
3727 | #endif |
3781 | #endif |
3728 | return inotify_init (); |
3782 | return inotify_init (); |
… | |
… | |
3803 | #else |
3857 | #else |
3804 | # define EV_LSTAT(p,b) lstat (p, b) |
3858 | # define EV_LSTAT(p,b) lstat (p, b) |
3805 | #endif |
3859 | #endif |
3806 | |
3860 | |
3807 | void |
3861 | void |
3808 | ev_stat_stat (EV_P_ ev_stat *w) |
3862 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
3809 | { |
3863 | { |
3810 | if (lstat (w->path, &w->attr) < 0) |
3864 | if (lstat (w->path, &w->attr) < 0) |
3811 | w->attr.st_nlink = 0; |
3865 | w->attr.st_nlink = 0; |
3812 | else if (!w->attr.st_nlink) |
3866 | else if (!w->attr.st_nlink) |
3813 | w->attr.st_nlink = 1; |
3867 | w->attr.st_nlink = 1; |
… | |
… | |
3852 | ev_feed_event (EV_A_ w, EV_STAT); |
3906 | ev_feed_event (EV_A_ w, EV_STAT); |
3853 | } |
3907 | } |
3854 | } |
3908 | } |
3855 | |
3909 | |
3856 | void |
3910 | void |
3857 | ev_stat_start (EV_P_ ev_stat *w) |
3911 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
3858 | { |
3912 | { |
3859 | if (expect_false (ev_is_active (w))) |
3913 | if (expect_false (ev_is_active (w))) |
3860 | return; |
3914 | return; |
3861 | |
3915 | |
3862 | ev_stat_stat (EV_A_ w); |
3916 | ev_stat_stat (EV_A_ w); |
… | |
… | |
3883 | |
3937 | |
3884 | EV_FREQUENT_CHECK; |
3938 | EV_FREQUENT_CHECK; |
3885 | } |
3939 | } |
3886 | |
3940 | |
3887 | void |
3941 | void |
3888 | ev_stat_stop (EV_P_ ev_stat *w) |
3942 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
3889 | { |
3943 | { |
3890 | clear_pending (EV_A_ (W)w); |
3944 | clear_pending (EV_A_ (W)w); |
3891 | if (expect_false (!ev_is_active (w))) |
3945 | if (expect_false (!ev_is_active (w))) |
3892 | return; |
3946 | return; |
3893 | |
3947 | |
… | |
… | |
3909 | } |
3963 | } |
3910 | #endif |
3964 | #endif |
3911 | |
3965 | |
3912 | #if EV_IDLE_ENABLE |
3966 | #if EV_IDLE_ENABLE |
3913 | void |
3967 | void |
3914 | ev_idle_start (EV_P_ ev_idle *w) |
3968 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
3915 | { |
3969 | { |
3916 | if (expect_false (ev_is_active (w))) |
3970 | if (expect_false (ev_is_active (w))) |
3917 | return; |
3971 | return; |
3918 | |
3972 | |
3919 | pri_adjust (EV_A_ (W)w); |
3973 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
3932 | |
3986 | |
3933 | EV_FREQUENT_CHECK; |
3987 | EV_FREQUENT_CHECK; |
3934 | } |
3988 | } |
3935 | |
3989 | |
3936 | void |
3990 | void |
3937 | ev_idle_stop (EV_P_ ev_idle *w) |
3991 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
3938 | { |
3992 | { |
3939 | clear_pending (EV_A_ (W)w); |
3993 | clear_pending (EV_A_ (W)w); |
3940 | if (expect_false (!ev_is_active (w))) |
3994 | if (expect_false (!ev_is_active (w))) |
3941 | return; |
3995 | return; |
3942 | |
3996 | |
… | |
… | |
3956 | } |
4010 | } |
3957 | #endif |
4011 | #endif |
3958 | |
4012 | |
3959 | #if EV_PREPARE_ENABLE |
4013 | #if EV_PREPARE_ENABLE |
3960 | void |
4014 | void |
3961 | ev_prepare_start (EV_P_ ev_prepare *w) |
4015 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
3962 | { |
4016 | { |
3963 | if (expect_false (ev_is_active (w))) |
4017 | if (expect_false (ev_is_active (w))) |
3964 | return; |
4018 | return; |
3965 | |
4019 | |
3966 | EV_FREQUENT_CHECK; |
4020 | EV_FREQUENT_CHECK; |
… | |
… | |
3971 | |
4025 | |
3972 | EV_FREQUENT_CHECK; |
4026 | EV_FREQUENT_CHECK; |
3973 | } |
4027 | } |
3974 | |
4028 | |
3975 | void |
4029 | void |
3976 | ev_prepare_stop (EV_P_ ev_prepare *w) |
4030 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
3977 | { |
4031 | { |
3978 | clear_pending (EV_A_ (W)w); |
4032 | clear_pending (EV_A_ (W)w); |
3979 | if (expect_false (!ev_is_active (w))) |
4033 | if (expect_false (!ev_is_active (w))) |
3980 | return; |
4034 | return; |
3981 | |
4035 | |
… | |
… | |
3994 | } |
4048 | } |
3995 | #endif |
4049 | #endif |
3996 | |
4050 | |
3997 | #if EV_CHECK_ENABLE |
4051 | #if EV_CHECK_ENABLE |
3998 | void |
4052 | void |
3999 | ev_check_start (EV_P_ ev_check *w) |
4053 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
4000 | { |
4054 | { |
4001 | if (expect_false (ev_is_active (w))) |
4055 | if (expect_false (ev_is_active (w))) |
4002 | return; |
4056 | return; |
4003 | |
4057 | |
4004 | EV_FREQUENT_CHECK; |
4058 | EV_FREQUENT_CHECK; |
… | |
… | |
4009 | |
4063 | |
4010 | EV_FREQUENT_CHECK; |
4064 | EV_FREQUENT_CHECK; |
4011 | } |
4065 | } |
4012 | |
4066 | |
4013 | void |
4067 | void |
4014 | ev_check_stop (EV_P_ ev_check *w) |
4068 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
4015 | { |
4069 | { |
4016 | clear_pending (EV_A_ (W)w); |
4070 | clear_pending (EV_A_ (W)w); |
4017 | if (expect_false (!ev_is_active (w))) |
4071 | if (expect_false (!ev_is_active (w))) |
4018 | return; |
4072 | return; |
4019 | |
4073 | |
… | |
… | |
4032 | } |
4086 | } |
4033 | #endif |
4087 | #endif |
4034 | |
4088 | |
4035 | #if EV_EMBED_ENABLE |
4089 | #if EV_EMBED_ENABLE |
4036 | void noinline |
4090 | void noinline |
4037 | ev_embed_sweep (EV_P_ ev_embed *w) |
4091 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4038 | { |
4092 | { |
4039 | ev_run (w->other, EVRUN_NOWAIT); |
4093 | ev_run (w->other, EVRUN_NOWAIT); |
4040 | } |
4094 | } |
4041 | |
4095 | |
4042 | static void |
4096 | static void |
… | |
… | |
4090 | ev_idle_stop (EV_A_ idle); |
4144 | ev_idle_stop (EV_A_ idle); |
4091 | } |
4145 | } |
4092 | #endif |
4146 | #endif |
4093 | |
4147 | |
4094 | void |
4148 | void |
4095 | ev_embed_start (EV_P_ ev_embed *w) |
4149 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4096 | { |
4150 | { |
4097 | if (expect_false (ev_is_active (w))) |
4151 | if (expect_false (ev_is_active (w))) |
4098 | return; |
4152 | return; |
4099 | |
4153 | |
4100 | { |
4154 | { |
… | |
… | |
4121 | |
4175 | |
4122 | EV_FREQUENT_CHECK; |
4176 | EV_FREQUENT_CHECK; |
4123 | } |
4177 | } |
4124 | |
4178 | |
4125 | void |
4179 | void |
4126 | ev_embed_stop (EV_P_ ev_embed *w) |
4180 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4127 | { |
4181 | { |
4128 | clear_pending (EV_A_ (W)w); |
4182 | clear_pending (EV_A_ (W)w); |
4129 | if (expect_false (!ev_is_active (w))) |
4183 | if (expect_false (!ev_is_active (w))) |
4130 | return; |
4184 | return; |
4131 | |
4185 | |
… | |
… | |
4141 | } |
4195 | } |
4142 | #endif |
4196 | #endif |
4143 | |
4197 | |
4144 | #if EV_FORK_ENABLE |
4198 | #if EV_FORK_ENABLE |
4145 | void |
4199 | void |
4146 | ev_fork_start (EV_P_ ev_fork *w) |
4200 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4147 | { |
4201 | { |
4148 | if (expect_false (ev_is_active (w))) |
4202 | if (expect_false (ev_is_active (w))) |
4149 | return; |
4203 | return; |
4150 | |
4204 | |
4151 | EV_FREQUENT_CHECK; |
4205 | EV_FREQUENT_CHECK; |
… | |
… | |
4156 | |
4210 | |
4157 | EV_FREQUENT_CHECK; |
4211 | EV_FREQUENT_CHECK; |
4158 | } |
4212 | } |
4159 | |
4213 | |
4160 | void |
4214 | void |
4161 | ev_fork_stop (EV_P_ ev_fork *w) |
4215 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4162 | { |
4216 | { |
4163 | clear_pending (EV_A_ (W)w); |
4217 | clear_pending (EV_A_ (W)w); |
4164 | if (expect_false (!ev_is_active (w))) |
4218 | if (expect_false (!ev_is_active (w))) |
4165 | return; |
4219 | return; |
4166 | |
4220 | |
… | |
… | |
4179 | } |
4233 | } |
4180 | #endif |
4234 | #endif |
4181 | |
4235 | |
4182 | #if EV_CLEANUP_ENABLE |
4236 | #if EV_CLEANUP_ENABLE |
4183 | void |
4237 | void |
4184 | ev_cleanup_start (EV_P_ ev_cleanup *w) |
4238 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4185 | { |
4239 | { |
4186 | if (expect_false (ev_is_active (w))) |
4240 | if (expect_false (ev_is_active (w))) |
4187 | return; |
4241 | return; |
4188 | |
4242 | |
4189 | EV_FREQUENT_CHECK; |
4243 | EV_FREQUENT_CHECK; |
… | |
… | |
4196 | ev_unref (EV_A); |
4250 | ev_unref (EV_A); |
4197 | EV_FREQUENT_CHECK; |
4251 | EV_FREQUENT_CHECK; |
4198 | } |
4252 | } |
4199 | |
4253 | |
4200 | void |
4254 | void |
4201 | ev_cleanup_stop (EV_P_ ev_cleanup *w) |
4255 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4202 | { |
4256 | { |
4203 | clear_pending (EV_A_ (W)w); |
4257 | clear_pending (EV_A_ (W)w); |
4204 | if (expect_false (!ev_is_active (w))) |
4258 | if (expect_false (!ev_is_active (w))) |
4205 | return; |
4259 | return; |
4206 | |
4260 | |
… | |
… | |
4220 | } |
4274 | } |
4221 | #endif |
4275 | #endif |
4222 | |
4276 | |
4223 | #if EV_ASYNC_ENABLE |
4277 | #if EV_ASYNC_ENABLE |
4224 | void |
4278 | void |
4225 | ev_async_start (EV_P_ ev_async *w) |
4279 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4226 | { |
4280 | { |
4227 | if (expect_false (ev_is_active (w))) |
4281 | if (expect_false (ev_is_active (w))) |
4228 | return; |
4282 | return; |
4229 | |
4283 | |
4230 | w->sent = 0; |
4284 | w->sent = 0; |
… | |
… | |
4239 | |
4293 | |
4240 | EV_FREQUENT_CHECK; |
4294 | EV_FREQUENT_CHECK; |
4241 | } |
4295 | } |
4242 | |
4296 | |
4243 | void |
4297 | void |
4244 | ev_async_stop (EV_P_ ev_async *w) |
4298 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4245 | { |
4299 | { |
4246 | clear_pending (EV_A_ (W)w); |
4300 | clear_pending (EV_A_ (W)w); |
4247 | if (expect_false (!ev_is_active (w))) |
4301 | if (expect_false (!ev_is_active (w))) |
4248 | return; |
4302 | return; |
4249 | |
4303 | |
… | |
… | |
4260 | |
4314 | |
4261 | EV_FREQUENT_CHECK; |
4315 | EV_FREQUENT_CHECK; |
4262 | } |
4316 | } |
4263 | |
4317 | |
4264 | void |
4318 | void |
4265 | ev_async_send (EV_P_ ev_async *w) |
4319 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
4266 | { |
4320 | { |
4267 | w->sent = 1; |
4321 | w->sent = 1; |
4268 | evpipe_write (EV_A_ &async_pending); |
4322 | evpipe_write (EV_A_ &async_pending); |
4269 | } |
4323 | } |
4270 | #endif |
4324 | #endif |
… | |
… | |
4307 | |
4361 | |
4308 | 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)); |
4309 | } |
4363 | } |
4310 | |
4364 | |
4311 | void |
4365 | void |
4312 | 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 |
4313 | { |
4367 | { |
4314 | 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)); |
4315 | |
4369 | |
4316 | if (expect_false (!once)) |
4370 | if (expect_false (!once)) |
4317 | { |
4371 | { |
… | |
… | |
4339 | |
4393 | |
4340 | /*****************************************************************************/ |
4394 | /*****************************************************************************/ |
4341 | |
4395 | |
4342 | #if EV_WALK_ENABLE |
4396 | #if EV_WALK_ENABLE |
4343 | void ecb_cold |
4397 | void ecb_cold |
4344 | 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 |
4345 | { |
4399 | { |
4346 | int i, j; |
4400 | int i, j; |
4347 | ev_watcher_list *wl, *wn; |
4401 | ev_watcher_list *wl, *wn; |
4348 | |
4402 | |
4349 | if (types & (EV_IO | EV_EMBED)) |
4403 | if (types & (EV_IO | EV_EMBED)) |