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 |
|
|
206 | # include <winsock2.h> |
195 | # include <windows.h> |
207 | # include <windows.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 |
… | |
… | |
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 | #StoreLoad | #LoadLoad | #StoreStore" : : : "memory") |
574 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad | " : : : "memory") |
563 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadLoad" : : : "memory") |
575 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") |
564 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #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 | DWORD flags = 0; |
|
|
1916 | buf.buf = dummy; |
|
|
1917 | buf.len = sizeof (dummy); |
|
|
1918 | WSARecv (EV_FD_TO_WIN32_HANDLE (evpipe [0]), &buf, 1, &recvd, &flags, 0, 0); |
|
|
1919 | #else |
1886 | read (evpipe [0], &dummy, 1); |
1920 | read (evpipe [0], &dummy, sizeof (dummy)); |
|
|
1921 | #endif |
1887 | } |
1922 | } |
1888 | } |
1923 | } |
1889 | |
1924 | |
1890 | pipe_write_skipped = 0; |
1925 | pipe_write_skipped = 0; |
|
|
1926 | |
|
|
1927 | ECB_MEMORY_FENCE; /* push out skipped, acquire flags */ |
1891 | |
1928 | |
1892 | #if EV_SIGNAL_ENABLE |
1929 | #if EV_SIGNAL_ENABLE |
1893 | if (sig_pending) |
1930 | if (sig_pending) |
1894 | { |
1931 | { |
1895 | sig_pending = 0; |
1932 | sig_pending = 0; |
|
|
1933 | |
|
|
1934 | ECB_MEMORY_FENCE_RELEASE; |
1896 | |
1935 | |
1897 | for (i = EV_NSIG - 1; i--; ) |
1936 | for (i = EV_NSIG - 1; i--; ) |
1898 | if (expect_false (signals [i].pending)) |
1937 | if (expect_false (signals [i].pending)) |
1899 | ev_feed_signal_event (EV_A_ i + 1); |
1938 | ev_feed_signal_event (EV_A_ i + 1); |
1900 | } |
1939 | } |
… | |
… | |
1902 | |
1941 | |
1903 | #if EV_ASYNC_ENABLE |
1942 | #if EV_ASYNC_ENABLE |
1904 | if (async_pending) |
1943 | if (async_pending) |
1905 | { |
1944 | { |
1906 | async_pending = 0; |
1945 | async_pending = 0; |
|
|
1946 | |
|
|
1947 | ECB_MEMORY_FENCE_RELEASE; |
1907 | |
1948 | |
1908 | for (i = asynccnt; i--; ) |
1949 | for (i = asynccnt; i--; ) |
1909 | if (asyncs [i]->sent) |
1950 | if (asyncs [i]->sent) |
1910 | { |
1951 | { |
1911 | asyncs [i]->sent = 0; |
1952 | asyncs [i]->sent = 0; |
… | |
… | |
1916 | } |
1957 | } |
1917 | |
1958 | |
1918 | /*****************************************************************************/ |
1959 | /*****************************************************************************/ |
1919 | |
1960 | |
1920 | void |
1961 | void |
1921 | ev_feed_signal (int signum) |
1962 | ev_feed_signal (int signum) EV_THROW |
1922 | { |
1963 | { |
1923 | #if EV_MULTIPLICITY |
1964 | #if EV_MULTIPLICITY |
1924 | EV_P = signals [signum - 1].loop; |
1965 | EV_P = signals [signum - 1].loop; |
1925 | |
1966 | |
1926 | if (!EV_A) |
1967 | if (!EV_A) |
… | |
… | |
1943 | |
1984 | |
1944 | ev_feed_signal (signum); |
1985 | ev_feed_signal (signum); |
1945 | } |
1986 | } |
1946 | |
1987 | |
1947 | void noinline |
1988 | void noinline |
1948 | ev_feed_signal_event (EV_P_ int signum) |
1989 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
1949 | { |
1990 | { |
1950 | WL w; |
1991 | WL w; |
1951 | |
1992 | |
1952 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
1993 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
1953 | return; |
1994 | return; |
… | |
… | |
2069 | #if EV_USE_SELECT |
2110 | #if EV_USE_SELECT |
2070 | # include "ev_select.c" |
2111 | # include "ev_select.c" |
2071 | #endif |
2112 | #endif |
2072 | |
2113 | |
2073 | int ecb_cold |
2114 | int ecb_cold |
2074 | ev_version_major (void) |
2115 | ev_version_major (void) EV_THROW |
2075 | { |
2116 | { |
2076 | return EV_VERSION_MAJOR; |
2117 | return EV_VERSION_MAJOR; |
2077 | } |
2118 | } |
2078 | |
2119 | |
2079 | int ecb_cold |
2120 | int ecb_cold |
2080 | ev_version_minor (void) |
2121 | ev_version_minor (void) EV_THROW |
2081 | { |
2122 | { |
2082 | return EV_VERSION_MINOR; |
2123 | return EV_VERSION_MINOR; |
2083 | } |
2124 | } |
2084 | |
2125 | |
2085 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2126 | /* return true if we are running with elevated privileges and should ignore env variables */ |
… | |
… | |
2093 | || getgid () != getegid (); |
2134 | || getgid () != getegid (); |
2094 | #endif |
2135 | #endif |
2095 | } |
2136 | } |
2096 | |
2137 | |
2097 | unsigned int ecb_cold |
2138 | unsigned int ecb_cold |
2098 | ev_supported_backends (void) |
2139 | ev_supported_backends (void) EV_THROW |
2099 | { |
2140 | { |
2100 | unsigned int flags = 0; |
2141 | unsigned int flags = 0; |
2101 | |
2142 | |
2102 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2143 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2103 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2144 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
… | |
… | |
2107 | |
2148 | |
2108 | return flags; |
2149 | return flags; |
2109 | } |
2150 | } |
2110 | |
2151 | |
2111 | unsigned int ecb_cold |
2152 | unsigned int ecb_cold |
2112 | ev_recommended_backends (void) |
2153 | ev_recommended_backends (void) EV_THROW |
2113 | { |
2154 | { |
2114 | unsigned int flags = ev_supported_backends (); |
2155 | unsigned int flags = ev_supported_backends (); |
2115 | |
2156 | |
2116 | #ifndef __NetBSD__ |
2157 | #ifndef __NetBSD__ |
2117 | /* kqueue is borked on everything but netbsd apparently */ |
2158 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2129 | |
2170 | |
2130 | return flags; |
2171 | return flags; |
2131 | } |
2172 | } |
2132 | |
2173 | |
2133 | unsigned int ecb_cold |
2174 | unsigned int ecb_cold |
2134 | ev_embeddable_backends (void) |
2175 | ev_embeddable_backends (void) EV_THROW |
2135 | { |
2176 | { |
2136 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2177 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2137 | |
2178 | |
2138 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2179 | /* 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 */ |
2180 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
… | |
… | |
2141 | |
2182 | |
2142 | return flags; |
2183 | return flags; |
2143 | } |
2184 | } |
2144 | |
2185 | |
2145 | unsigned int |
2186 | unsigned int |
2146 | ev_backend (EV_P) |
2187 | ev_backend (EV_P) EV_THROW |
2147 | { |
2188 | { |
2148 | return backend; |
2189 | return backend; |
2149 | } |
2190 | } |
2150 | |
2191 | |
2151 | #if EV_FEATURE_API |
2192 | #if EV_FEATURE_API |
2152 | unsigned int |
2193 | unsigned int |
2153 | ev_iteration (EV_P) |
2194 | ev_iteration (EV_P) EV_THROW |
2154 | { |
2195 | { |
2155 | return loop_count; |
2196 | return loop_count; |
2156 | } |
2197 | } |
2157 | |
2198 | |
2158 | unsigned int |
2199 | unsigned int |
2159 | ev_depth (EV_P) |
2200 | ev_depth (EV_P) EV_THROW |
2160 | { |
2201 | { |
2161 | return loop_depth; |
2202 | return loop_depth; |
2162 | } |
2203 | } |
2163 | |
2204 | |
2164 | void |
2205 | void |
2165 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) |
2206 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2166 | { |
2207 | { |
2167 | io_blocktime = interval; |
2208 | io_blocktime = interval; |
2168 | } |
2209 | } |
2169 | |
2210 | |
2170 | void |
2211 | void |
2171 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) |
2212 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2172 | { |
2213 | { |
2173 | timeout_blocktime = interval; |
2214 | timeout_blocktime = interval; |
2174 | } |
2215 | } |
2175 | |
2216 | |
2176 | void |
2217 | void |
2177 | ev_set_userdata (EV_P_ void *data) |
2218 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2178 | { |
2219 | { |
2179 | userdata = data; |
2220 | userdata = data; |
2180 | } |
2221 | } |
2181 | |
2222 | |
2182 | void * |
2223 | void * |
2183 | ev_userdata (EV_P) |
2224 | ev_userdata (EV_P) EV_THROW |
2184 | { |
2225 | { |
2185 | return userdata; |
2226 | return userdata; |
2186 | } |
2227 | } |
2187 | |
2228 | |
2188 | void |
2229 | void |
2189 | ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) |
2230 | ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) EV_THROW |
2190 | { |
2231 | { |
2191 | invoke_cb = invoke_pending_cb; |
2232 | invoke_cb = invoke_pending_cb; |
2192 | } |
2233 | } |
2193 | |
2234 | |
2194 | void |
2235 | void |
2195 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) |
2236 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW |
2196 | { |
2237 | { |
2197 | release_cb = release; |
2238 | release_cb = release; |
2198 | acquire_cb = acquire; |
2239 | acquire_cb = acquire; |
2199 | } |
2240 | } |
2200 | #endif |
2241 | #endif |
2201 | |
2242 | |
2202 | /* initialise a loop structure, must be zero-initialised */ |
2243 | /* initialise a loop structure, must be zero-initialised */ |
2203 | static void noinline ecb_cold |
2244 | static void noinline ecb_cold |
2204 | loop_init (EV_P_ unsigned int flags) |
2245 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2205 | { |
2246 | { |
2206 | if (!backend) |
2247 | if (!backend) |
2207 | { |
2248 | { |
2208 | origflags = flags; |
2249 | origflags = flags; |
2209 | |
2250 | |
… | |
… | |
2462 | } |
2503 | } |
2463 | |
2504 | |
2464 | #if EV_MULTIPLICITY |
2505 | #if EV_MULTIPLICITY |
2465 | |
2506 | |
2466 | struct ev_loop * ecb_cold |
2507 | struct ev_loop * ecb_cold |
2467 | ev_loop_new (unsigned int flags) |
2508 | ev_loop_new (unsigned int flags) EV_THROW |
2468 | { |
2509 | { |
2469 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2510 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2470 | |
2511 | |
2471 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2512 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2472 | loop_init (EV_A_ flags); |
2513 | loop_init (EV_A_ flags); |
… | |
… | |
2516 | } |
2557 | } |
2517 | #endif |
2558 | #endif |
2518 | |
2559 | |
2519 | #if EV_FEATURE_API |
2560 | #if EV_FEATURE_API |
2520 | void ecb_cold |
2561 | void ecb_cold |
2521 | ev_verify (EV_P) |
2562 | ev_verify (EV_P) EV_THROW |
2522 | { |
2563 | { |
2523 | #if EV_VERIFY |
2564 | #if EV_VERIFY |
2524 | int i; |
2565 | int i; |
2525 | WL w; |
2566 | WL w, w2; |
2526 | |
2567 | |
2527 | assert (activecnt >= -1); |
2568 | assert (activecnt >= -1); |
2528 | |
2569 | |
2529 | assert (fdchangemax >= fdchangecnt); |
2570 | assert (fdchangemax >= fdchangecnt); |
2530 | for (i = 0; i < fdchangecnt; ++i) |
2571 | for (i = 0; i < fdchangecnt; ++i) |
2531 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2572 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2532 | |
2573 | |
2533 | assert (anfdmax >= 0); |
2574 | assert (anfdmax >= 0); |
2534 | for (i = 0; i < anfdmax; ++i) |
2575 | for (i = 0; i < anfdmax; ++i) |
|
|
2576 | { |
|
|
2577 | int j = 0; |
|
|
2578 | |
2535 | for (w = anfds [i].head; w; w = w->next) |
2579 | for (w = w2 = anfds [i].head; w; w = w->next) |
2536 | { |
2580 | { |
2537 | verify_watcher (EV_A_ (W)w); |
2581 | verify_watcher (EV_A_ (W)w); |
|
|
2582 | |
|
|
2583 | if (j++ & 1) |
|
|
2584 | { |
|
|
2585 | assert (("libev: io watcher list contains a loop", w != w2)); |
|
|
2586 | w2 = w2->next; |
|
|
2587 | } |
|
|
2588 | |
2538 | assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); |
2589 | 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)); |
2590 | assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); |
2540 | } |
2591 | } |
|
|
2592 | } |
2541 | |
2593 | |
2542 | assert (timermax >= timercnt); |
2594 | assert (timermax >= timercnt); |
2543 | verify_heap (EV_A_ timers, timercnt); |
2595 | verify_heap (EV_A_ timers, timercnt); |
2544 | |
2596 | |
2545 | #if EV_PERIODIC_ENABLE |
2597 | #if EV_PERIODIC_ENABLE |
… | |
… | |
2595 | #if EV_MULTIPLICITY |
2647 | #if EV_MULTIPLICITY |
2596 | struct ev_loop * ecb_cold |
2648 | struct ev_loop * ecb_cold |
2597 | #else |
2649 | #else |
2598 | int |
2650 | int |
2599 | #endif |
2651 | #endif |
2600 | ev_default_loop (unsigned int flags) |
2652 | ev_default_loop (unsigned int flags) EV_THROW |
2601 | { |
2653 | { |
2602 | if (!ev_default_loop_ptr) |
2654 | if (!ev_default_loop_ptr) |
2603 | { |
2655 | { |
2604 | #if EV_MULTIPLICITY |
2656 | #if EV_MULTIPLICITY |
2605 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
2657 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
2624 | |
2676 | |
2625 | return ev_default_loop_ptr; |
2677 | return ev_default_loop_ptr; |
2626 | } |
2678 | } |
2627 | |
2679 | |
2628 | void |
2680 | void |
2629 | ev_loop_fork (EV_P) |
2681 | ev_loop_fork (EV_P) EV_THROW |
2630 | { |
2682 | { |
2631 | postfork = 1; /* must be in line with ev_default_fork */ |
2683 | postfork = 1; /* must be in line with ev_default_fork */ |
2632 | } |
2684 | } |
2633 | |
2685 | |
2634 | /*****************************************************************************/ |
2686 | /*****************************************************************************/ |
… | |
… | |
2638 | { |
2690 | { |
2639 | EV_CB_INVOKE ((W)w, revents); |
2691 | EV_CB_INVOKE ((W)w, revents); |
2640 | } |
2692 | } |
2641 | |
2693 | |
2642 | unsigned int |
2694 | unsigned int |
2643 | ev_pending_count (EV_P) |
2695 | ev_pending_count (EV_P) EV_THROW |
2644 | { |
2696 | { |
2645 | int pri; |
2697 | int pri; |
2646 | unsigned int count = 0; |
2698 | unsigned int count = 0; |
2647 | |
2699 | |
2648 | for (pri = NUMPRI; pri--; ) |
2700 | for (pri = NUMPRI; pri--; ) |
… | |
… | |
2652 | } |
2704 | } |
2653 | |
2705 | |
2654 | void noinline |
2706 | void noinline |
2655 | ev_invoke_pending (EV_P) |
2707 | ev_invoke_pending (EV_P) |
2656 | { |
2708 | { |
2657 | int pri; |
2709 | for (pendingpri = NUMPRI; pendingpri--; ) /* pendingpri is modified during the loop */ |
2658 | |
|
|
2659 | for (pri = NUMPRI; pri--; ) |
|
|
2660 | while (pendingcnt [pri]) |
2710 | while (pendingcnt [pendingpri]) |
2661 | { |
2711 | { |
2662 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
2712 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
2663 | |
2713 | |
2664 | p->w->pending = 0; |
2714 | p->w->pending = 0; |
2665 | EV_CB_INVOKE (p->w, p->events); |
2715 | EV_CB_INVOKE (p->w, p->events); |
2666 | EV_FREQUENT_CHECK; |
2716 | EV_FREQUENT_CHECK; |
2667 | } |
2717 | } |
… | |
… | |
2907 | |
2957 | |
2908 | mn_now = ev_rt_now; |
2958 | mn_now = ev_rt_now; |
2909 | } |
2959 | } |
2910 | } |
2960 | } |
2911 | |
2961 | |
2912 | void |
2962 | int |
2913 | ev_run (EV_P_ int flags) |
2963 | ev_run (EV_P_ int flags) |
2914 | { |
2964 | { |
2915 | #if EV_FEATURE_API |
2965 | #if EV_FEATURE_API |
2916 | ++loop_depth; |
2966 | ++loop_depth; |
2917 | #endif |
2967 | #endif |
… | |
… | |
3074 | loop_done = EVBREAK_CANCEL; |
3124 | loop_done = EVBREAK_CANCEL; |
3075 | |
3125 | |
3076 | #if EV_FEATURE_API |
3126 | #if EV_FEATURE_API |
3077 | --loop_depth; |
3127 | --loop_depth; |
3078 | #endif |
3128 | #endif |
|
|
3129 | |
|
|
3130 | return activecnt; |
3079 | } |
3131 | } |
3080 | |
3132 | |
3081 | void |
3133 | void |
3082 | ev_break (EV_P_ int how) |
3134 | ev_break (EV_P_ int how) EV_THROW |
3083 | { |
3135 | { |
3084 | loop_done = how; |
3136 | loop_done = how; |
3085 | } |
3137 | } |
3086 | |
3138 | |
3087 | void |
3139 | void |
3088 | ev_ref (EV_P) |
3140 | ev_ref (EV_P) EV_THROW |
3089 | { |
3141 | { |
3090 | ++activecnt; |
3142 | ++activecnt; |
3091 | } |
3143 | } |
3092 | |
3144 | |
3093 | void |
3145 | void |
3094 | ev_unref (EV_P) |
3146 | ev_unref (EV_P) EV_THROW |
3095 | { |
3147 | { |
3096 | --activecnt; |
3148 | --activecnt; |
3097 | } |
3149 | } |
3098 | |
3150 | |
3099 | void |
3151 | void |
3100 | ev_now_update (EV_P) |
3152 | ev_now_update (EV_P) EV_THROW |
3101 | { |
3153 | { |
3102 | time_update (EV_A_ 1e100); |
3154 | time_update (EV_A_ 1e100); |
3103 | } |
3155 | } |
3104 | |
3156 | |
3105 | void |
3157 | void |
3106 | ev_suspend (EV_P) |
3158 | ev_suspend (EV_P) EV_THROW |
3107 | { |
3159 | { |
3108 | ev_now_update (EV_A); |
3160 | ev_now_update (EV_A); |
3109 | } |
3161 | } |
3110 | |
3162 | |
3111 | void |
3163 | void |
3112 | ev_resume (EV_P) |
3164 | ev_resume (EV_P) EV_THROW |
3113 | { |
3165 | { |
3114 | ev_tstamp mn_prev = mn_now; |
3166 | ev_tstamp mn_prev = mn_now; |
3115 | |
3167 | |
3116 | ev_now_update (EV_A); |
3168 | ev_now_update (EV_A); |
3117 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3169 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3156 | w->pending = 0; |
3208 | w->pending = 0; |
3157 | } |
3209 | } |
3158 | } |
3210 | } |
3159 | |
3211 | |
3160 | int |
3212 | int |
3161 | ev_clear_pending (EV_P_ void *w) |
3213 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3162 | { |
3214 | { |
3163 | W w_ = (W)w; |
3215 | W w_ = (W)w; |
3164 | int pending = w_->pending; |
3216 | int pending = w_->pending; |
3165 | |
3217 | |
3166 | if (expect_true (pending)) |
3218 | if (expect_true (pending)) |
… | |
… | |
3199 | } |
3251 | } |
3200 | |
3252 | |
3201 | /*****************************************************************************/ |
3253 | /*****************************************************************************/ |
3202 | |
3254 | |
3203 | void noinline |
3255 | void noinline |
3204 | ev_io_start (EV_P_ ev_io *w) |
3256 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3205 | { |
3257 | { |
3206 | int fd = w->fd; |
3258 | int fd = w->fd; |
3207 | |
3259 | |
3208 | if (expect_false (ev_is_active (w))) |
3260 | if (expect_false (ev_is_active (w))) |
3209 | return; |
3261 | return; |
… | |
… | |
3215 | |
3267 | |
3216 | ev_start (EV_A_ (W)w, 1); |
3268 | ev_start (EV_A_ (W)w, 1); |
3217 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3269 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3218 | wlist_add (&anfds[fd].head, (WL)w); |
3270 | wlist_add (&anfds[fd].head, (WL)w); |
3219 | |
3271 | |
|
|
3272 | /* common bug, apparently */ |
|
|
3273 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
|
|
3274 | |
3220 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3275 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3221 | w->events &= ~EV__IOFDSET; |
3276 | w->events &= ~EV__IOFDSET; |
3222 | |
3277 | |
3223 | EV_FREQUENT_CHECK; |
3278 | EV_FREQUENT_CHECK; |
3224 | } |
3279 | } |
3225 | |
3280 | |
3226 | void noinline |
3281 | void noinline |
3227 | ev_io_stop (EV_P_ ev_io *w) |
3282 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3228 | { |
3283 | { |
3229 | clear_pending (EV_A_ (W)w); |
3284 | clear_pending (EV_A_ (W)w); |
3230 | if (expect_false (!ev_is_active (w))) |
3285 | if (expect_false (!ev_is_active (w))) |
3231 | return; |
3286 | return; |
3232 | |
3287 | |
… | |
… | |
3241 | |
3296 | |
3242 | EV_FREQUENT_CHECK; |
3297 | EV_FREQUENT_CHECK; |
3243 | } |
3298 | } |
3244 | |
3299 | |
3245 | void noinline |
3300 | void noinline |
3246 | ev_timer_start (EV_P_ ev_timer *w) |
3301 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3247 | { |
3302 | { |
3248 | if (expect_false (ev_is_active (w))) |
3303 | if (expect_false (ev_is_active (w))) |
3249 | return; |
3304 | return; |
3250 | |
3305 | |
3251 | ev_at (w) += mn_now; |
3306 | ev_at (w) += mn_now; |
… | |
… | |
3265 | |
3320 | |
3266 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3321 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3267 | } |
3322 | } |
3268 | |
3323 | |
3269 | void noinline |
3324 | void noinline |
3270 | ev_timer_stop (EV_P_ ev_timer *w) |
3325 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3271 | { |
3326 | { |
3272 | clear_pending (EV_A_ (W)w); |
3327 | clear_pending (EV_A_ (W)w); |
3273 | if (expect_false (!ev_is_active (w))) |
3328 | if (expect_false (!ev_is_active (w))) |
3274 | return; |
3329 | return; |
3275 | |
3330 | |
… | |
… | |
3295 | |
3350 | |
3296 | EV_FREQUENT_CHECK; |
3351 | EV_FREQUENT_CHECK; |
3297 | } |
3352 | } |
3298 | |
3353 | |
3299 | void noinline |
3354 | void noinline |
3300 | ev_timer_again (EV_P_ ev_timer *w) |
3355 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
3301 | { |
3356 | { |
3302 | EV_FREQUENT_CHECK; |
3357 | EV_FREQUENT_CHECK; |
|
|
3358 | |
|
|
3359 | clear_pending (EV_A_ (W)w); |
3303 | |
3360 | |
3304 | if (ev_is_active (w)) |
3361 | if (ev_is_active (w)) |
3305 | { |
3362 | { |
3306 | if (w->repeat) |
3363 | if (w->repeat) |
3307 | { |
3364 | { |
… | |
… | |
3320 | |
3377 | |
3321 | EV_FREQUENT_CHECK; |
3378 | EV_FREQUENT_CHECK; |
3322 | } |
3379 | } |
3323 | |
3380 | |
3324 | ev_tstamp |
3381 | ev_tstamp |
3325 | ev_timer_remaining (EV_P_ ev_timer *w) |
3382 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
3326 | { |
3383 | { |
3327 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3384 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3328 | } |
3385 | } |
3329 | |
3386 | |
3330 | #if EV_PERIODIC_ENABLE |
3387 | #if EV_PERIODIC_ENABLE |
3331 | void noinline |
3388 | void noinline |
3332 | ev_periodic_start (EV_P_ ev_periodic *w) |
3389 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
3333 | { |
3390 | { |
3334 | if (expect_false (ev_is_active (w))) |
3391 | if (expect_false (ev_is_active (w))) |
3335 | return; |
3392 | return; |
3336 | |
3393 | |
3337 | if (w->reschedule_cb) |
3394 | if (w->reschedule_cb) |
… | |
… | |
3357 | |
3414 | |
3358 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3415 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3359 | } |
3416 | } |
3360 | |
3417 | |
3361 | void noinline |
3418 | void noinline |
3362 | ev_periodic_stop (EV_P_ ev_periodic *w) |
3419 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
3363 | { |
3420 | { |
3364 | clear_pending (EV_A_ (W)w); |
3421 | clear_pending (EV_A_ (W)w); |
3365 | if (expect_false (!ev_is_active (w))) |
3422 | if (expect_false (!ev_is_active (w))) |
3366 | return; |
3423 | return; |
3367 | |
3424 | |
… | |
… | |
3385 | |
3442 | |
3386 | EV_FREQUENT_CHECK; |
3443 | EV_FREQUENT_CHECK; |
3387 | } |
3444 | } |
3388 | |
3445 | |
3389 | void noinline |
3446 | void noinline |
3390 | ev_periodic_again (EV_P_ ev_periodic *w) |
3447 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
3391 | { |
3448 | { |
3392 | /* TODO: use adjustheap and recalculation */ |
3449 | /* TODO: use adjustheap and recalculation */ |
3393 | ev_periodic_stop (EV_A_ w); |
3450 | ev_periodic_stop (EV_A_ w); |
3394 | ev_periodic_start (EV_A_ w); |
3451 | ev_periodic_start (EV_A_ w); |
3395 | } |
3452 | } |
… | |
… | |
3400 | #endif |
3457 | #endif |
3401 | |
3458 | |
3402 | #if EV_SIGNAL_ENABLE |
3459 | #if EV_SIGNAL_ENABLE |
3403 | |
3460 | |
3404 | void noinline |
3461 | void noinline |
3405 | ev_signal_start (EV_P_ ev_signal *w) |
3462 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
3406 | { |
3463 | { |
3407 | if (expect_false (ev_is_active (w))) |
3464 | if (expect_false (ev_is_active (w))) |
3408 | return; |
3465 | return; |
3409 | |
3466 | |
3410 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
3467 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
… | |
… | |
3481 | |
3538 | |
3482 | EV_FREQUENT_CHECK; |
3539 | EV_FREQUENT_CHECK; |
3483 | } |
3540 | } |
3484 | |
3541 | |
3485 | void noinline |
3542 | void noinline |
3486 | ev_signal_stop (EV_P_ ev_signal *w) |
3543 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
3487 | { |
3544 | { |
3488 | clear_pending (EV_A_ (W)w); |
3545 | clear_pending (EV_A_ (W)w); |
3489 | if (expect_false (!ev_is_active (w))) |
3546 | if (expect_false (!ev_is_active (w))) |
3490 | return; |
3547 | return; |
3491 | |
3548 | |
… | |
… | |
3522 | #endif |
3579 | #endif |
3523 | |
3580 | |
3524 | #if EV_CHILD_ENABLE |
3581 | #if EV_CHILD_ENABLE |
3525 | |
3582 | |
3526 | void |
3583 | void |
3527 | ev_child_start (EV_P_ ev_child *w) |
3584 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
3528 | { |
3585 | { |
3529 | #if EV_MULTIPLICITY |
3586 | #if EV_MULTIPLICITY |
3530 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
3587 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
3531 | #endif |
3588 | #endif |
3532 | if (expect_false (ev_is_active (w))) |
3589 | if (expect_false (ev_is_active (w))) |
… | |
… | |
3539 | |
3596 | |
3540 | EV_FREQUENT_CHECK; |
3597 | EV_FREQUENT_CHECK; |
3541 | } |
3598 | } |
3542 | |
3599 | |
3543 | void |
3600 | void |
3544 | ev_child_stop (EV_P_ ev_child *w) |
3601 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
3545 | { |
3602 | { |
3546 | clear_pending (EV_A_ (W)w); |
3603 | clear_pending (EV_A_ (W)w); |
3547 | if (expect_false (!ev_is_active (w))) |
3604 | if (expect_false (!ev_is_active (w))) |
3548 | return; |
3605 | return; |
3549 | |
3606 | |
… | |
… | |
3716 | } |
3773 | } |
3717 | |
3774 | |
3718 | inline_size int |
3775 | inline_size int |
3719 | infy_newfd (void) |
3776 | infy_newfd (void) |
3720 | { |
3777 | { |
3721 | #if defined (IN_CLOEXEC) && defined (IN_NONBLOCK) |
3778 | #if defined IN_CLOEXEC && defined IN_NONBLOCK |
3722 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3779 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3723 | if (fd >= 0) |
3780 | if (fd >= 0) |
3724 | return fd; |
3781 | return fd; |
3725 | #endif |
3782 | #endif |
3726 | return inotify_init (); |
3783 | return inotify_init (); |
… | |
… | |
3801 | #else |
3858 | #else |
3802 | # define EV_LSTAT(p,b) lstat (p, b) |
3859 | # define EV_LSTAT(p,b) lstat (p, b) |
3803 | #endif |
3860 | #endif |
3804 | |
3861 | |
3805 | void |
3862 | void |
3806 | ev_stat_stat (EV_P_ ev_stat *w) |
3863 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
3807 | { |
3864 | { |
3808 | if (lstat (w->path, &w->attr) < 0) |
3865 | if (lstat (w->path, &w->attr) < 0) |
3809 | w->attr.st_nlink = 0; |
3866 | w->attr.st_nlink = 0; |
3810 | else if (!w->attr.st_nlink) |
3867 | else if (!w->attr.st_nlink) |
3811 | w->attr.st_nlink = 1; |
3868 | w->attr.st_nlink = 1; |
… | |
… | |
3850 | ev_feed_event (EV_A_ w, EV_STAT); |
3907 | ev_feed_event (EV_A_ w, EV_STAT); |
3851 | } |
3908 | } |
3852 | } |
3909 | } |
3853 | |
3910 | |
3854 | void |
3911 | void |
3855 | ev_stat_start (EV_P_ ev_stat *w) |
3912 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
3856 | { |
3913 | { |
3857 | if (expect_false (ev_is_active (w))) |
3914 | if (expect_false (ev_is_active (w))) |
3858 | return; |
3915 | return; |
3859 | |
3916 | |
3860 | ev_stat_stat (EV_A_ w); |
3917 | ev_stat_stat (EV_A_ w); |
… | |
… | |
3881 | |
3938 | |
3882 | EV_FREQUENT_CHECK; |
3939 | EV_FREQUENT_CHECK; |
3883 | } |
3940 | } |
3884 | |
3941 | |
3885 | void |
3942 | void |
3886 | ev_stat_stop (EV_P_ ev_stat *w) |
3943 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
3887 | { |
3944 | { |
3888 | clear_pending (EV_A_ (W)w); |
3945 | clear_pending (EV_A_ (W)w); |
3889 | if (expect_false (!ev_is_active (w))) |
3946 | if (expect_false (!ev_is_active (w))) |
3890 | return; |
3947 | return; |
3891 | |
3948 | |
… | |
… | |
3907 | } |
3964 | } |
3908 | #endif |
3965 | #endif |
3909 | |
3966 | |
3910 | #if EV_IDLE_ENABLE |
3967 | #if EV_IDLE_ENABLE |
3911 | void |
3968 | void |
3912 | ev_idle_start (EV_P_ ev_idle *w) |
3969 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
3913 | { |
3970 | { |
3914 | if (expect_false (ev_is_active (w))) |
3971 | if (expect_false (ev_is_active (w))) |
3915 | return; |
3972 | return; |
3916 | |
3973 | |
3917 | pri_adjust (EV_A_ (W)w); |
3974 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
3930 | |
3987 | |
3931 | EV_FREQUENT_CHECK; |
3988 | EV_FREQUENT_CHECK; |
3932 | } |
3989 | } |
3933 | |
3990 | |
3934 | void |
3991 | void |
3935 | ev_idle_stop (EV_P_ ev_idle *w) |
3992 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
3936 | { |
3993 | { |
3937 | clear_pending (EV_A_ (W)w); |
3994 | clear_pending (EV_A_ (W)w); |
3938 | if (expect_false (!ev_is_active (w))) |
3995 | if (expect_false (!ev_is_active (w))) |
3939 | return; |
3996 | return; |
3940 | |
3997 | |
… | |
… | |
3954 | } |
4011 | } |
3955 | #endif |
4012 | #endif |
3956 | |
4013 | |
3957 | #if EV_PREPARE_ENABLE |
4014 | #if EV_PREPARE_ENABLE |
3958 | void |
4015 | void |
3959 | ev_prepare_start (EV_P_ ev_prepare *w) |
4016 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
3960 | { |
4017 | { |
3961 | if (expect_false (ev_is_active (w))) |
4018 | if (expect_false (ev_is_active (w))) |
3962 | return; |
4019 | return; |
3963 | |
4020 | |
3964 | EV_FREQUENT_CHECK; |
4021 | EV_FREQUENT_CHECK; |
… | |
… | |
3969 | |
4026 | |
3970 | EV_FREQUENT_CHECK; |
4027 | EV_FREQUENT_CHECK; |
3971 | } |
4028 | } |
3972 | |
4029 | |
3973 | void |
4030 | void |
3974 | ev_prepare_stop (EV_P_ ev_prepare *w) |
4031 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
3975 | { |
4032 | { |
3976 | clear_pending (EV_A_ (W)w); |
4033 | clear_pending (EV_A_ (W)w); |
3977 | if (expect_false (!ev_is_active (w))) |
4034 | if (expect_false (!ev_is_active (w))) |
3978 | return; |
4035 | return; |
3979 | |
4036 | |
… | |
… | |
3992 | } |
4049 | } |
3993 | #endif |
4050 | #endif |
3994 | |
4051 | |
3995 | #if EV_CHECK_ENABLE |
4052 | #if EV_CHECK_ENABLE |
3996 | void |
4053 | void |
3997 | ev_check_start (EV_P_ ev_check *w) |
4054 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
3998 | { |
4055 | { |
3999 | if (expect_false (ev_is_active (w))) |
4056 | if (expect_false (ev_is_active (w))) |
4000 | return; |
4057 | return; |
4001 | |
4058 | |
4002 | EV_FREQUENT_CHECK; |
4059 | EV_FREQUENT_CHECK; |
… | |
… | |
4007 | |
4064 | |
4008 | EV_FREQUENT_CHECK; |
4065 | EV_FREQUENT_CHECK; |
4009 | } |
4066 | } |
4010 | |
4067 | |
4011 | void |
4068 | void |
4012 | ev_check_stop (EV_P_ ev_check *w) |
4069 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
4013 | { |
4070 | { |
4014 | clear_pending (EV_A_ (W)w); |
4071 | clear_pending (EV_A_ (W)w); |
4015 | if (expect_false (!ev_is_active (w))) |
4072 | if (expect_false (!ev_is_active (w))) |
4016 | return; |
4073 | return; |
4017 | |
4074 | |
… | |
… | |
4030 | } |
4087 | } |
4031 | #endif |
4088 | #endif |
4032 | |
4089 | |
4033 | #if EV_EMBED_ENABLE |
4090 | #if EV_EMBED_ENABLE |
4034 | void noinline |
4091 | void noinline |
4035 | ev_embed_sweep (EV_P_ ev_embed *w) |
4092 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4036 | { |
4093 | { |
4037 | ev_run (w->other, EVRUN_NOWAIT); |
4094 | ev_run (w->other, EVRUN_NOWAIT); |
4038 | } |
4095 | } |
4039 | |
4096 | |
4040 | static void |
4097 | static void |
… | |
… | |
4088 | ev_idle_stop (EV_A_ idle); |
4145 | ev_idle_stop (EV_A_ idle); |
4089 | } |
4146 | } |
4090 | #endif |
4147 | #endif |
4091 | |
4148 | |
4092 | void |
4149 | void |
4093 | ev_embed_start (EV_P_ ev_embed *w) |
4150 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4094 | { |
4151 | { |
4095 | if (expect_false (ev_is_active (w))) |
4152 | if (expect_false (ev_is_active (w))) |
4096 | return; |
4153 | return; |
4097 | |
4154 | |
4098 | { |
4155 | { |
… | |
… | |
4119 | |
4176 | |
4120 | EV_FREQUENT_CHECK; |
4177 | EV_FREQUENT_CHECK; |
4121 | } |
4178 | } |
4122 | |
4179 | |
4123 | void |
4180 | void |
4124 | ev_embed_stop (EV_P_ ev_embed *w) |
4181 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4125 | { |
4182 | { |
4126 | clear_pending (EV_A_ (W)w); |
4183 | clear_pending (EV_A_ (W)w); |
4127 | if (expect_false (!ev_is_active (w))) |
4184 | if (expect_false (!ev_is_active (w))) |
4128 | return; |
4185 | return; |
4129 | |
4186 | |
… | |
… | |
4139 | } |
4196 | } |
4140 | #endif |
4197 | #endif |
4141 | |
4198 | |
4142 | #if EV_FORK_ENABLE |
4199 | #if EV_FORK_ENABLE |
4143 | void |
4200 | void |
4144 | ev_fork_start (EV_P_ ev_fork *w) |
4201 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4145 | { |
4202 | { |
4146 | if (expect_false (ev_is_active (w))) |
4203 | if (expect_false (ev_is_active (w))) |
4147 | return; |
4204 | return; |
4148 | |
4205 | |
4149 | EV_FREQUENT_CHECK; |
4206 | EV_FREQUENT_CHECK; |
… | |
… | |
4154 | |
4211 | |
4155 | EV_FREQUENT_CHECK; |
4212 | EV_FREQUENT_CHECK; |
4156 | } |
4213 | } |
4157 | |
4214 | |
4158 | void |
4215 | void |
4159 | ev_fork_stop (EV_P_ ev_fork *w) |
4216 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4160 | { |
4217 | { |
4161 | clear_pending (EV_A_ (W)w); |
4218 | clear_pending (EV_A_ (W)w); |
4162 | if (expect_false (!ev_is_active (w))) |
4219 | if (expect_false (!ev_is_active (w))) |
4163 | return; |
4220 | return; |
4164 | |
4221 | |
… | |
… | |
4177 | } |
4234 | } |
4178 | #endif |
4235 | #endif |
4179 | |
4236 | |
4180 | #if EV_CLEANUP_ENABLE |
4237 | #if EV_CLEANUP_ENABLE |
4181 | void |
4238 | void |
4182 | ev_cleanup_start (EV_P_ ev_cleanup *w) |
4239 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4183 | { |
4240 | { |
4184 | if (expect_false (ev_is_active (w))) |
4241 | if (expect_false (ev_is_active (w))) |
4185 | return; |
4242 | return; |
4186 | |
4243 | |
4187 | EV_FREQUENT_CHECK; |
4244 | EV_FREQUENT_CHECK; |
… | |
… | |
4194 | ev_unref (EV_A); |
4251 | ev_unref (EV_A); |
4195 | EV_FREQUENT_CHECK; |
4252 | EV_FREQUENT_CHECK; |
4196 | } |
4253 | } |
4197 | |
4254 | |
4198 | void |
4255 | void |
4199 | ev_cleanup_stop (EV_P_ ev_cleanup *w) |
4256 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4200 | { |
4257 | { |
4201 | clear_pending (EV_A_ (W)w); |
4258 | clear_pending (EV_A_ (W)w); |
4202 | if (expect_false (!ev_is_active (w))) |
4259 | if (expect_false (!ev_is_active (w))) |
4203 | return; |
4260 | return; |
4204 | |
4261 | |
… | |
… | |
4218 | } |
4275 | } |
4219 | #endif |
4276 | #endif |
4220 | |
4277 | |
4221 | #if EV_ASYNC_ENABLE |
4278 | #if EV_ASYNC_ENABLE |
4222 | void |
4279 | void |
4223 | ev_async_start (EV_P_ ev_async *w) |
4280 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4224 | { |
4281 | { |
4225 | if (expect_false (ev_is_active (w))) |
4282 | if (expect_false (ev_is_active (w))) |
4226 | return; |
4283 | return; |
4227 | |
4284 | |
4228 | w->sent = 0; |
4285 | w->sent = 0; |
… | |
… | |
4237 | |
4294 | |
4238 | EV_FREQUENT_CHECK; |
4295 | EV_FREQUENT_CHECK; |
4239 | } |
4296 | } |
4240 | |
4297 | |
4241 | void |
4298 | void |
4242 | ev_async_stop (EV_P_ ev_async *w) |
4299 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4243 | { |
4300 | { |
4244 | clear_pending (EV_A_ (W)w); |
4301 | clear_pending (EV_A_ (W)w); |
4245 | if (expect_false (!ev_is_active (w))) |
4302 | if (expect_false (!ev_is_active (w))) |
4246 | return; |
4303 | return; |
4247 | |
4304 | |
… | |
… | |
4258 | |
4315 | |
4259 | EV_FREQUENT_CHECK; |
4316 | EV_FREQUENT_CHECK; |
4260 | } |
4317 | } |
4261 | |
4318 | |
4262 | void |
4319 | void |
4263 | ev_async_send (EV_P_ ev_async *w) |
4320 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
4264 | { |
4321 | { |
4265 | w->sent = 1; |
4322 | w->sent = 1; |
4266 | evpipe_write (EV_A_ &async_pending); |
4323 | evpipe_write (EV_A_ &async_pending); |
4267 | } |
4324 | } |
4268 | #endif |
4325 | #endif |
… | |
… | |
4305 | |
4362 | |
4306 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4363 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4307 | } |
4364 | } |
4308 | |
4365 | |
4309 | void |
4366 | void |
4310 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
4367 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW |
4311 | { |
4368 | { |
4312 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4369 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4313 | |
4370 | |
4314 | if (expect_false (!once)) |
4371 | if (expect_false (!once)) |
4315 | { |
4372 | { |
… | |
… | |
4337 | |
4394 | |
4338 | /*****************************************************************************/ |
4395 | /*****************************************************************************/ |
4339 | |
4396 | |
4340 | #if EV_WALK_ENABLE |
4397 | #if EV_WALK_ENABLE |
4341 | void ecb_cold |
4398 | void ecb_cold |
4342 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) |
4399 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
4343 | { |
4400 | { |
4344 | int i, j; |
4401 | int i, j; |
4345 | ev_watcher_list *wl, *wn; |
4402 | ev_watcher_list *wl, *wn; |
4346 | |
4403 | |
4347 | if (types & (EV_IO | EV_EMBED)) |
4404 | if (types & (EV_IO | EV_EMBED)) |