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 | EV_CPP(extern "C" {) |
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 |
189 | |
198 | |
190 | #ifndef _WIN32 |
199 | #ifndef _WIN32 |
191 | # include <sys/time.h> |
200 | # include <sys/time.h> |
192 | # include <sys/wait.h> |
201 | # include <sys/wait.h> |
193 | # include <unistd.h> |
202 | # include <unistd.h> |
… | |
… | |
210 | #define _DARWIN_UNLIMITED_SELECT 1 |
219 | #define _DARWIN_UNLIMITED_SELECT 1 |
211 | |
220 | |
212 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
221 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
213 | |
222 | |
214 | /* try to deduce the maximum number of signals on this platform */ |
223 | /* try to deduce the maximum number of signals on this platform */ |
215 | #if defined (EV_NSIG) |
224 | #if defined EV_NSIG |
216 | /* use what's provided */ |
225 | /* use what's provided */ |
217 | #elif defined (NSIG) |
226 | #elif defined NSIG |
218 | # define EV_NSIG (NSIG) |
227 | # define EV_NSIG (NSIG) |
219 | #elif defined(_NSIG) |
228 | #elif defined _NSIG |
220 | # define EV_NSIG (_NSIG) |
229 | # define EV_NSIG (_NSIG) |
221 | #elif defined (SIGMAX) |
230 | #elif defined SIGMAX |
222 | # define EV_NSIG (SIGMAX+1) |
231 | # define EV_NSIG (SIGMAX+1) |
223 | #elif defined (SIG_MAX) |
232 | #elif defined SIG_MAX |
224 | # define EV_NSIG (SIG_MAX+1) |
233 | # define EV_NSIG (SIG_MAX+1) |
225 | #elif defined (_SIG_MAX) |
234 | #elif defined _SIG_MAX |
226 | # define EV_NSIG (_SIG_MAX+1) |
235 | # define EV_NSIG (_SIG_MAX+1) |
227 | #elif defined (MAXSIG) |
236 | #elif defined MAXSIG |
228 | # define EV_NSIG (MAXSIG+1) |
237 | # define EV_NSIG (MAXSIG+1) |
229 | #elif defined (MAX_SIG) |
238 | #elif defined MAX_SIG |
230 | # define EV_NSIG (MAX_SIG+1) |
239 | # define EV_NSIG (MAX_SIG+1) |
231 | #elif defined (SIGARRAYSIZE) |
240 | #elif defined SIGARRAYSIZE |
232 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
241 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
233 | #elif defined (_sys_nsig) |
242 | #elif defined _sys_nsig |
234 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
243 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
235 | #else |
244 | #else |
236 | # error "unable to find value for NSIG, please report" |
245 | # error "unable to find value for NSIG, please report" |
237 | /* to make it compile regardless, just remove the above line, */ |
246 | /* to make it compile regardless, just remove the above line, */ |
238 | /* but consider reporting it, too! :) */ |
247 | /* but consider reporting it, too! :) */ |
… | |
… | |
250 | # define EV_USE_CLOCK_SYSCALL 0 |
259 | # define EV_USE_CLOCK_SYSCALL 0 |
251 | # endif |
260 | # endif |
252 | #endif |
261 | #endif |
253 | |
262 | |
254 | #ifndef EV_USE_MONOTONIC |
263 | #ifndef EV_USE_MONOTONIC |
255 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
264 | # if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0 |
256 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
265 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
257 | # else |
266 | # else |
258 | # define EV_USE_MONOTONIC 0 |
267 | # define EV_USE_MONOTONIC 0 |
259 | # endif |
268 | # endif |
260 | #endif |
269 | #endif |
… | |
… | |
350 | #endif |
359 | #endif |
351 | |
360 | |
352 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
361 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
353 | /* which makes programs even slower. might work on other unices, too. */ |
362 | /* which makes programs even slower. might work on other unices, too. */ |
354 | #if EV_USE_CLOCK_SYSCALL |
363 | #if EV_USE_CLOCK_SYSCALL |
355 | # include <syscall.h> |
364 | # include <sys/syscall.h> |
356 | # ifdef SYS_clock_gettime |
365 | # ifdef SYS_clock_gettime |
357 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
366 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
358 | # undef EV_USE_MONOTONIC |
367 | # undef EV_USE_MONOTONIC |
359 | # define EV_USE_MONOTONIC 1 |
368 | # define EV_USE_MONOTONIC 1 |
360 | # else |
369 | # else |
… | |
… | |
386 | # define EV_USE_INOTIFY 0 |
395 | # define EV_USE_INOTIFY 0 |
387 | #endif |
396 | #endif |
388 | |
397 | |
389 | #if !EV_USE_NANOSLEEP |
398 | #if !EV_USE_NANOSLEEP |
390 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
399 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
391 | # if !defined(_WIN32) && !defined(__hpux) |
400 | # if !defined _WIN32 && !defined __hpux |
392 | # include <sys/select.h> |
401 | # include <sys/select.h> |
393 | # endif |
402 | # endif |
394 | #endif |
403 | #endif |
395 | |
404 | |
396 | #if EV_USE_INOTIFY |
405 | #if EV_USE_INOTIFY |
… | |
… | |
469 | /* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ |
478 | /* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ |
470 | /* ECB.H BEGIN */ |
479 | /* ECB.H BEGIN */ |
471 | /* |
480 | /* |
472 | * libecb - http://software.schmorp.de/pkg/libecb |
481 | * libecb - http://software.schmorp.de/pkg/libecb |
473 | * |
482 | * |
474 | * Copyright (©) 2009-2011 Marc Alexander Lehmann <libecb@schmorp.de> |
483 | * Copyright (©) 2009-2012 Marc Alexander Lehmann <libecb@schmorp.de> |
475 | * Copyright (©) 2011 Emanuele Giaquinta |
484 | * Copyright (©) 2011 Emanuele Giaquinta |
476 | * All rights reserved. |
485 | * All rights reserved. |
477 | * |
486 | * |
478 | * Redistribution and use in source and binary forms, with or without modifica- |
487 | * Redistribution and use in source and binary forms, with or without modifica- |
479 | * tion, are permitted provided that the following conditions are met: |
488 | * tion, are permitted provided that the following conditions are met: |
… | |
… | |
524 | * or so. |
533 | * or so. |
525 | * we try to detect these and simply assume they are not gcc - if they have |
534 | * we try to detect these and simply assume they are not gcc - if they have |
526 | * an issue with that they should have done it right in the first place. |
535 | * an issue with that they should have done it right in the first place. |
527 | */ |
536 | */ |
528 | #ifndef ECB_GCC_VERSION |
537 | #ifndef ECB_GCC_VERSION |
529 | #if !defined(__GNUC_MINOR__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__llvm__) || defined(__clang__) |
538 | #if !defined __GNUC_MINOR__ || defined __INTEL_COMPILER || defined __SUNPRO_C || defined __SUNPRO_CC || defined __llvm__ || defined __clang__ |
530 | #define ECB_GCC_VERSION(major,minor) 0 |
539 | #define ECB_GCC_VERSION(major,minor) 0 |
531 | #else |
540 | #else |
532 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
541 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
533 | #endif |
542 | #endif |
534 | #endif |
543 | #endif |
… | |
… | |
536 | /*****************************************************************************/ |
545 | /*****************************************************************************/ |
537 | |
546 | |
538 | /* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ |
547 | /* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ |
539 | /* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ |
548 | /* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ |
540 | |
549 | |
|
|
550 | #if ECB_NO_THREADS |
|
|
551 | # define ECB_NO_SMP 1 |
|
|
552 | #endif |
|
|
553 | |
541 | #if ECB_NO_THREADS || ECB_NO_SMP |
554 | #if ECB_NO_THREADS || ECB_NO_SMP |
542 | #define ECB_MEMORY_FENCE do { } while (0) |
555 | #define ECB_MEMORY_FENCE do { } while (0) |
543 | #endif |
556 | #endif |
544 | |
557 | |
545 | #ifndef ECB_MEMORY_FENCE |
558 | #ifndef ECB_MEMORY_FENCE |
546 | #if ECB_GCC_VERSION(2,5) |
559 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
547 | #if __i386__ |
560 | #if __i386 || __i386__ |
548 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
561 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
549 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */ |
562 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */ |
550 | #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ |
563 | #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ |
551 | #elif __amd64 |
564 | #elif __amd64 || __amd64__ || __x86_64 || __x86_64__ |
552 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
565 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
553 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") |
566 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") |
554 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */ |
567 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */ |
555 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
568 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
556 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
569 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
557 | #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \ |
570 | #elif defined __ARM_ARCH_6__ || defined __ARM_ARCH_6J__ \ |
558 | || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) |
571 | || defined __ARM_ARCH_6K__ || defined __ARM_ARCH_6ZK__ |
559 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory") |
572 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory") |
560 | #elif defined(__ARM_ARCH_7__ ) || defined(__ARM_ARCH_7A__ ) \ |
573 | #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \ |
561 | || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ ) |
574 | || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__ |
562 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
575 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
|
|
576 | #elif __sparc || __sparc__ |
|
|
577 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad | " : : : "memory") |
|
|
578 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") |
|
|
579 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") |
|
|
580 | #elif defined __s390__ || defined __s390x__ |
|
|
581 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") |
|
|
582 | #elif defined __mips__ |
|
|
583 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
|
|
584 | #elif defined __alpha__ |
|
|
585 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mb" : : : "memory") |
563 | #endif |
586 | #endif |
564 | #endif |
587 | #endif |
565 | #endif |
588 | #endif |
566 | |
589 | |
567 | #ifndef ECB_MEMORY_FENCE |
590 | #ifndef ECB_MEMORY_FENCE |
568 | #if ECB_GCC_VERSION(4,4) || defined(__INTEL_COMPILER) |
591 | #if ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
569 | #define ECB_MEMORY_FENCE __sync_synchronize () |
592 | #define ECB_MEMORY_FENCE __sync_synchronize () |
570 | /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */ |
593 | /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */ |
571 | /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */ |
594 | /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */ |
572 | #elif _MSC_VER >= 1400 /* VC++ 2005 */ |
595 | #elif _MSC_VER >= 1400 /* VC++ 2005 */ |
573 | #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) |
596 | #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) |
574 | #define ECB_MEMORY_FENCE _ReadWriteBarrier () |
597 | #define ECB_MEMORY_FENCE _ReadWriteBarrier () |
575 | #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ |
598 | #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ |
576 | #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () |
599 | #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () |
577 | #elif defined(_WIN32) |
600 | #elif defined _WIN32 |
578 | #include <WinNT.h> |
601 | #include <WinNT.h> |
579 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
602 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
|
|
603 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
|
|
604 | #include <mbarrier.h> |
|
|
605 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
|
|
606 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () |
|
|
607 | #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () |
|
|
608 | #elif __xlC__ |
|
|
609 | #define ECB_MEMORY_FENCE __sync () |
580 | #endif |
610 | #endif |
581 | #endif |
611 | #endif |
582 | |
612 | |
583 | #ifndef ECB_MEMORY_FENCE |
613 | #ifndef ECB_MEMORY_FENCE |
584 | #if !ECB_AVOID_PTHREADS |
614 | #if !ECB_AVOID_PTHREADS |
… | |
… | |
596 | static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; |
626 | static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; |
597 | #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0) |
627 | #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0) |
598 | #endif |
628 | #endif |
599 | #endif |
629 | #endif |
600 | |
630 | |
601 | #if !defined(ECB_MEMORY_FENCE_ACQUIRE) && defined(ECB_MEMORY_FENCE) |
631 | #if !defined ECB_MEMORY_FENCE_ACQUIRE && defined ECB_MEMORY_FENCE |
602 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
632 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
603 | #endif |
633 | #endif |
604 | |
634 | |
605 | #if !defined(ECB_MEMORY_FENCE_RELEASE) && defined(ECB_MEMORY_FENCE) |
635 | #if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE |
606 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
636 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
607 | #endif |
637 | #endif |
608 | |
638 | |
609 | /*****************************************************************************/ |
639 | /*****************************************************************************/ |
610 | |
640 | |
… | |
… | |
759 | |
789 | |
760 | return r + ecb_ld32 (x); |
790 | return r + ecb_ld32 (x); |
761 | } |
791 | } |
762 | #endif |
792 | #endif |
763 | |
793 | |
|
|
794 | ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) ecb_const; |
|
|
795 | ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) |
|
|
796 | { |
|
|
797 | return ( (x * 0x0802U & 0x22110U) |
|
|
798 | | (x * 0x8020U & 0x88440U)) * 0x10101U >> 16; |
|
|
799 | } |
|
|
800 | |
|
|
801 | ecb_function_ uint16_t ecb_bitrev16 (uint16_t x) ecb_const; |
|
|
802 | ecb_function_ uint16_t ecb_bitrev16 (uint16_t x) |
|
|
803 | { |
|
|
804 | x = ((x >> 1) & 0x5555) | ((x & 0x5555) << 1); |
|
|
805 | x = ((x >> 2) & 0x3333) | ((x & 0x3333) << 2); |
|
|
806 | x = ((x >> 4) & 0x0f0f) | ((x & 0x0f0f) << 4); |
|
|
807 | x = ( x >> 8 ) | ( x << 8); |
|
|
808 | |
|
|
809 | return x; |
|
|
810 | } |
|
|
811 | |
|
|
812 | ecb_function_ uint32_t ecb_bitrev32 (uint32_t x) ecb_const; |
|
|
813 | ecb_function_ uint32_t ecb_bitrev32 (uint32_t x) |
|
|
814 | { |
|
|
815 | x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1); |
|
|
816 | x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2); |
|
|
817 | x = ((x >> 4) & 0x0f0f0f0f) | ((x & 0x0f0f0f0f) << 4); |
|
|
818 | x = ((x >> 8) & 0x00ff00ff) | ((x & 0x00ff00ff) << 8); |
|
|
819 | x = ( x >> 16 ) | ( x << 16); |
|
|
820 | |
|
|
821 | return x; |
|
|
822 | } |
|
|
823 | |
764 | /* popcount64 is only available on 64 bit cpus as gcc builtin */ |
824 | /* popcount64 is only available on 64 bit cpus as gcc builtin */ |
765 | /* so for this version we are lazy */ |
825 | /* so for this version we are lazy */ |
766 | ecb_function_ int ecb_popcount64 (uint64_t x) ecb_const; |
826 | ecb_function_ int ecb_popcount64 (uint64_t x) ecb_const; |
767 | ecb_function_ int |
827 | ecb_function_ int |
768 | ecb_popcount64 (uint64_t x) |
828 | ecb_popcount64 (uint64_t x) |
… | |
… | |
817 | |
877 | |
818 | #if ECB_GCC_VERSION(4,5) |
878 | #if ECB_GCC_VERSION(4,5) |
819 | #define ecb_unreachable() __builtin_unreachable () |
879 | #define ecb_unreachable() __builtin_unreachable () |
820 | #else |
880 | #else |
821 | /* this seems to work fine, but gcc always emits a warning for it :/ */ |
881 | /* this seems to work fine, but gcc always emits a warning for it :/ */ |
822 | ecb_function_ void ecb_unreachable (void) ecb_noreturn; |
882 | ecb_inline void ecb_unreachable (void) ecb_noreturn; |
823 | ecb_function_ void ecb_unreachable (void) { } |
883 | ecb_inline void ecb_unreachable (void) { } |
824 | #endif |
884 | #endif |
825 | |
885 | |
826 | /* try to tell the compiler that some condition is definitely true */ |
886 | /* try to tell the compiler that some condition is definitely true */ |
827 | #define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) |
887 | #define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) |
828 | |
888 | |
829 | ecb_function_ unsigned char ecb_byteorder_helper (void) ecb_const; |
889 | ecb_inline unsigned char ecb_byteorder_helper (void) ecb_const; |
830 | ecb_function_ unsigned char |
890 | ecb_inline unsigned char |
831 | ecb_byteorder_helper (void) |
891 | ecb_byteorder_helper (void) |
832 | { |
892 | { |
833 | const uint32_t u = 0x11223344; |
893 | const uint32_t u = 0x11223344; |
834 | return *(unsigned char *)&u; |
894 | return *(unsigned char *)&u; |
835 | } |
895 | } |
836 | |
896 | |
837 | ecb_function_ ecb_bool ecb_big_endian (void) ecb_const; |
897 | ecb_inline ecb_bool ecb_big_endian (void) ecb_const; |
838 | ecb_function_ ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } |
898 | ecb_inline ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } |
839 | ecb_function_ ecb_bool ecb_little_endian (void) ecb_const; |
899 | ecb_inline ecb_bool ecb_little_endian (void) ecb_const; |
840 | ecb_function_ ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; } |
900 | ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; } |
841 | |
901 | |
842 | #if ECB_GCC_VERSION(3,0) || ECB_C99 |
902 | #if ECB_GCC_VERSION(3,0) || ECB_C99 |
843 | #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) |
903 | #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) |
844 | #else |
904 | #else |
845 | #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) |
905 | #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) |
|
|
906 | #endif |
|
|
907 | |
|
|
908 | #if __cplusplus |
|
|
909 | template<typename T> |
|
|
910 | static inline T ecb_div_rd (T val, T div) |
|
|
911 | { |
|
|
912 | return val < 0 ? - ((-val + div - 1) / div) : (val ) / div; |
|
|
913 | } |
|
|
914 | template<typename T> |
|
|
915 | static inline T ecb_div_ru (T val, T div) |
|
|
916 | { |
|
|
917 | return val < 0 ? - ((-val ) / div) : (val + div - 1) / div; |
|
|
918 | } |
|
|
919 | #else |
|
|
920 | #define ecb_div_rd(val,div) ((val) < 0 ? - ((-(val) + (div) - 1) / (div)) : ((val) ) / (div)) |
|
|
921 | #define ecb_div_ru(val,div) ((val) < 0 ? - ((-(val) ) / (div)) : ((val) + (div) - 1) / (div)) |
846 | #endif |
922 | #endif |
847 | |
923 | |
848 | #if ecb_cplusplus_does_not_suck |
924 | #if ecb_cplusplus_does_not_suck |
849 | /* does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm) */ |
925 | /* does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm) */ |
850 | template<typename T, int N> |
926 | template<typename T, int N> |
… | |
… | |
862 | |
938 | |
863 | #if ECB_MEMORY_FENCE_NEEDS_PTHREADS |
939 | #if ECB_MEMORY_FENCE_NEEDS_PTHREADS |
864 | /* if your architecture doesn't need memory fences, e.g. because it is |
940 | /* if your architecture doesn't need memory fences, e.g. because it is |
865 | * single-cpu/core, or if you use libev in a project that doesn't use libev |
941 | * single-cpu/core, or if you use libev in a project that doesn't use libev |
866 | * from multiple threads, then you can define ECB_AVOID_PTHREADS when compiling |
942 | * from multiple threads, then you can define ECB_AVOID_PTHREADS when compiling |
867 | * libev, in which casess the memory fences become nops. |
943 | * libev, in which cases the memory fences become nops. |
868 | * alternatively, you can remove this #error and link against libpthread, |
944 | * alternatively, you can remove this #error and link against libpthread, |
869 | * which will then provide the memory fences. |
945 | * which will then provide the memory fences. |
870 | */ |
946 | */ |
871 | # error "memory fences not defined for your architecture, please report" |
947 | # error "memory fences not defined for your architecture, please report" |
872 | #endif |
948 | #endif |
… | |
… | |
1029 | { |
1105 | { |
1030 | write (STDERR_FILENO, msg, strlen (msg)); |
1106 | write (STDERR_FILENO, msg, strlen (msg)); |
1031 | } |
1107 | } |
1032 | #endif |
1108 | #endif |
1033 | |
1109 | |
1034 | static void (*syserr_cb)(const char *msg); |
1110 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1035 | |
1111 | |
1036 | void ecb_cold |
1112 | void ecb_cold |
1037 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
1113 | ev_set_syserr_cb (void (*cb)(const char *msg)) EV_THROW |
1038 | { |
1114 | { |
1039 | syserr_cb = cb; |
1115 | syserr_cb = cb; |
1040 | } |
1116 | } |
1041 | |
1117 | |
1042 | static void noinline ecb_cold |
1118 | static void noinline ecb_cold |
… | |
… | |
1078 | free (ptr); |
1154 | free (ptr); |
1079 | return 0; |
1155 | return 0; |
1080 | #endif |
1156 | #endif |
1081 | } |
1157 | } |
1082 | |
1158 | |
1083 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
1159 | static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; |
1084 | |
1160 | |
1085 | void ecb_cold |
1161 | void ecb_cold |
1086 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
1162 | ev_set_allocator (void *(*cb)(void *ptr, long size)) EV_THROW |
1087 | { |
1163 | { |
1088 | alloc = cb; |
1164 | alloc = cb; |
1089 | } |
1165 | } |
1090 | |
1166 | |
1091 | inline_speed void * |
1167 | inline_speed void * |
… | |
… | |
1179 | #undef VAR |
1255 | #undef VAR |
1180 | }; |
1256 | }; |
1181 | #include "ev_wrap.h" |
1257 | #include "ev_wrap.h" |
1182 | |
1258 | |
1183 | static struct ev_loop default_loop_struct; |
1259 | static struct ev_loop default_loop_struct; |
1184 | struct ev_loop *ev_default_loop_ptr; |
1260 | EV_API_DECL struct ev_loop *ev_default_loop_ptr = 0; /* needs to be initialised to make it a definition despite extern */ |
1185 | |
1261 | |
1186 | #else |
1262 | #else |
1187 | |
1263 | |
1188 | ev_tstamp ev_rt_now; |
1264 | EV_API_DECL ev_tstamp ev_rt_now = 0; /* needs to be initialised to make it a definition despite extern */ |
1189 | #define VAR(name,decl) static decl; |
1265 | #define VAR(name,decl) static decl; |
1190 | #include "ev_vars.h" |
1266 | #include "ev_vars.h" |
1191 | #undef VAR |
1267 | #undef VAR |
1192 | |
1268 | |
1193 | static int ev_default_loop_ptr; |
1269 | static int ev_default_loop_ptr; |
… | |
… | |
1208 | |
1284 | |
1209 | /*****************************************************************************/ |
1285 | /*****************************************************************************/ |
1210 | |
1286 | |
1211 | #ifndef EV_HAVE_EV_TIME |
1287 | #ifndef EV_HAVE_EV_TIME |
1212 | ev_tstamp |
1288 | ev_tstamp |
1213 | ev_time (void) |
1289 | ev_time (void) EV_THROW |
1214 | { |
1290 | { |
1215 | #if EV_USE_REALTIME |
1291 | #if EV_USE_REALTIME |
1216 | if (expect_true (have_realtime)) |
1292 | if (expect_true (have_realtime)) |
1217 | { |
1293 | { |
1218 | struct timespec ts; |
1294 | struct timespec ts; |
… | |
… | |
1242 | return ev_time (); |
1318 | return ev_time (); |
1243 | } |
1319 | } |
1244 | |
1320 | |
1245 | #if EV_MULTIPLICITY |
1321 | #if EV_MULTIPLICITY |
1246 | ev_tstamp |
1322 | ev_tstamp |
1247 | ev_now (EV_P) |
1323 | ev_now (EV_P) EV_THROW |
1248 | { |
1324 | { |
1249 | return ev_rt_now; |
1325 | return ev_rt_now; |
1250 | } |
1326 | } |
1251 | #endif |
1327 | #endif |
1252 | |
1328 | |
1253 | void |
1329 | void |
1254 | ev_sleep (ev_tstamp delay) |
1330 | ev_sleep (ev_tstamp delay) EV_THROW |
1255 | { |
1331 | { |
1256 | if (delay > 0.) |
1332 | if (delay > 0.) |
1257 | { |
1333 | { |
1258 | #if EV_USE_NANOSLEEP |
1334 | #if EV_USE_NANOSLEEP |
1259 | struct timespec ts; |
1335 | struct timespec ts; |
1260 | |
1336 | |
1261 | EV_TS_SET (ts, delay); |
1337 | EV_TS_SET (ts, delay); |
1262 | nanosleep (&ts, 0); |
1338 | nanosleep (&ts, 0); |
1263 | #elif defined(_WIN32) |
1339 | #elif defined _WIN32 |
1264 | Sleep ((unsigned long)(delay * 1e3)); |
1340 | Sleep ((unsigned long)(delay * 1e3)); |
1265 | #else |
1341 | #else |
1266 | struct timeval tv; |
1342 | struct timeval tv; |
1267 | |
1343 | |
1268 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
1344 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
… | |
… | |
1287 | |
1363 | |
1288 | do |
1364 | do |
1289 | ncur <<= 1; |
1365 | ncur <<= 1; |
1290 | while (cnt > ncur); |
1366 | while (cnt > ncur); |
1291 | |
1367 | |
1292 | /* if size is large, round to MALLOC_ROUND - 4 * longs to accomodate malloc overhead */ |
1368 | /* if size is large, round to MALLOC_ROUND - 4 * longs to accommodate malloc overhead */ |
1293 | if (elem * ncur > MALLOC_ROUND - sizeof (void *) * 4) |
1369 | if (elem * ncur > MALLOC_ROUND - sizeof (void *) * 4) |
1294 | { |
1370 | { |
1295 | ncur *= elem; |
1371 | ncur *= elem; |
1296 | ncur = (ncur + elem + (MALLOC_ROUND - 1) + sizeof (void *) * 4) & ~(MALLOC_ROUND - 1); |
1372 | ncur = (ncur + elem + (MALLOC_ROUND - 1) + sizeof (void *) * 4) & ~(MALLOC_ROUND - 1); |
1297 | ncur = ncur - sizeof (void *) * 4; |
1373 | ncur = ncur - sizeof (void *) * 4; |
… | |
… | |
1340 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1416 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1341 | { |
1417 | { |
1342 | } |
1418 | } |
1343 | |
1419 | |
1344 | void noinline |
1420 | void noinline |
1345 | ev_feed_event (EV_P_ void *w, int revents) |
1421 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
1346 | { |
1422 | { |
1347 | W w_ = (W)w; |
1423 | W w_ = (W)w; |
1348 | int pri = ABSPRI (w_); |
1424 | int pri = ABSPRI (w_); |
1349 | |
1425 | |
1350 | if (expect_false (w_->pending)) |
1426 | if (expect_false (w_->pending)) |
… | |
… | |
1409 | if (expect_true (!anfd->reify)) |
1485 | if (expect_true (!anfd->reify)) |
1410 | fd_event_nocheck (EV_A_ fd, revents); |
1486 | fd_event_nocheck (EV_A_ fd, revents); |
1411 | } |
1487 | } |
1412 | |
1488 | |
1413 | void |
1489 | void |
1414 | ev_feed_fd_event (EV_P_ int fd, int revents) |
1490 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW |
1415 | { |
1491 | { |
1416 | if (fd >= 0 && fd < anfdmax) |
1492 | if (fd >= 0 && fd < anfdmax) |
1417 | fd_event_nocheck (EV_A_ fd, revents); |
1493 | fd_event_nocheck (EV_A_ fd, revents); |
1418 | } |
1494 | } |
1419 | |
1495 | |
… | |
… | |
1801 | /* win32 people keep sending patches that change this write() to send() */ |
1877 | /* win32 people keep sending patches that change this write() to send() */ |
1802 | /* and then run away. but send() is wrong, it wants a socket handle on win32 */ |
1878 | /* and then run away. but send() is wrong, it wants a socket handle on win32 */ |
1803 | /* so when you think this write should be a send instead, please find out */ |
1879 | /* so when you think this write should be a send instead, please find out */ |
1804 | /* where your send() is from - it's definitely not the microsoft send, and */ |
1880 | /* where your send() is from - it's definitely not the microsoft send, and */ |
1805 | /* tell me. thank you. */ |
1881 | /* tell me. thank you. */ |
|
|
1882 | /* it might be that your problem is that your environment needs EV_USE_WSASOCKET */ |
|
|
1883 | /* check the ev documentation on how to use this flag */ |
1806 | write (evpipe [1], &(evpipe [1]), 1); |
1884 | write (evpipe [1], &(evpipe [1]), 1); |
1807 | } |
1885 | } |
1808 | |
1886 | |
1809 | errno = old_errno; |
1887 | errno = old_errno; |
1810 | } |
1888 | } |
… | |
… | |
1863 | } |
1941 | } |
1864 | |
1942 | |
1865 | /*****************************************************************************/ |
1943 | /*****************************************************************************/ |
1866 | |
1944 | |
1867 | void |
1945 | void |
1868 | ev_feed_signal (int signum) |
1946 | ev_feed_signal (int signum) EV_THROW |
1869 | { |
1947 | { |
1870 | #if EV_MULTIPLICITY |
1948 | #if EV_MULTIPLICITY |
1871 | EV_P = signals [signum - 1].loop; |
1949 | EV_P = signals [signum - 1].loop; |
1872 | |
1950 | |
1873 | if (!EV_A) |
1951 | if (!EV_A) |
… | |
… | |
1890 | |
1968 | |
1891 | ev_feed_signal (signum); |
1969 | ev_feed_signal (signum); |
1892 | } |
1970 | } |
1893 | |
1971 | |
1894 | void noinline |
1972 | void noinline |
1895 | ev_feed_signal_event (EV_P_ int signum) |
1973 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
1896 | { |
1974 | { |
1897 | WL w; |
1975 | WL w; |
1898 | |
1976 | |
1899 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
1977 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
1900 | return; |
1978 | return; |
… | |
… | |
2016 | #if EV_USE_SELECT |
2094 | #if EV_USE_SELECT |
2017 | # include "ev_select.c" |
2095 | # include "ev_select.c" |
2018 | #endif |
2096 | #endif |
2019 | |
2097 | |
2020 | int ecb_cold |
2098 | int ecb_cold |
2021 | ev_version_major (void) |
2099 | ev_version_major (void) EV_THROW |
2022 | { |
2100 | { |
2023 | return EV_VERSION_MAJOR; |
2101 | return EV_VERSION_MAJOR; |
2024 | } |
2102 | } |
2025 | |
2103 | |
2026 | int ecb_cold |
2104 | int ecb_cold |
2027 | ev_version_minor (void) |
2105 | ev_version_minor (void) EV_THROW |
2028 | { |
2106 | { |
2029 | return EV_VERSION_MINOR; |
2107 | return EV_VERSION_MINOR; |
2030 | } |
2108 | } |
2031 | |
2109 | |
2032 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2110 | /* return true if we are running with elevated privileges and should ignore env variables */ |
… | |
… | |
2040 | || getgid () != getegid (); |
2118 | || getgid () != getegid (); |
2041 | #endif |
2119 | #endif |
2042 | } |
2120 | } |
2043 | |
2121 | |
2044 | unsigned int ecb_cold |
2122 | unsigned int ecb_cold |
2045 | ev_supported_backends (void) |
2123 | ev_supported_backends (void) EV_THROW |
2046 | { |
2124 | { |
2047 | unsigned int flags = 0; |
2125 | unsigned int flags = 0; |
2048 | |
2126 | |
2049 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2127 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2050 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2128 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
… | |
… | |
2054 | |
2132 | |
2055 | return flags; |
2133 | return flags; |
2056 | } |
2134 | } |
2057 | |
2135 | |
2058 | unsigned int ecb_cold |
2136 | unsigned int ecb_cold |
2059 | ev_recommended_backends (void) |
2137 | ev_recommended_backends (void) EV_THROW |
2060 | { |
2138 | { |
2061 | unsigned int flags = ev_supported_backends (); |
2139 | unsigned int flags = ev_supported_backends (); |
2062 | |
2140 | |
2063 | #ifndef __NetBSD__ |
2141 | #ifndef __NetBSD__ |
2064 | /* kqueue is borked on everything but netbsd apparently */ |
2142 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2076 | |
2154 | |
2077 | return flags; |
2155 | return flags; |
2078 | } |
2156 | } |
2079 | |
2157 | |
2080 | unsigned int ecb_cold |
2158 | unsigned int ecb_cold |
2081 | ev_embeddable_backends (void) |
2159 | ev_embeddable_backends (void) EV_THROW |
2082 | { |
2160 | { |
2083 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2161 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2084 | |
2162 | |
2085 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2163 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2086 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
2164 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
… | |
… | |
2088 | |
2166 | |
2089 | return flags; |
2167 | return flags; |
2090 | } |
2168 | } |
2091 | |
2169 | |
2092 | unsigned int |
2170 | unsigned int |
2093 | ev_backend (EV_P) |
2171 | ev_backend (EV_P) EV_THROW |
2094 | { |
2172 | { |
2095 | return backend; |
2173 | return backend; |
2096 | } |
2174 | } |
2097 | |
2175 | |
2098 | #if EV_FEATURE_API |
2176 | #if EV_FEATURE_API |
2099 | unsigned int |
2177 | unsigned int |
2100 | ev_iteration (EV_P) |
2178 | ev_iteration (EV_P) EV_THROW |
2101 | { |
2179 | { |
2102 | return loop_count; |
2180 | return loop_count; |
2103 | } |
2181 | } |
2104 | |
2182 | |
2105 | unsigned int |
2183 | unsigned int |
2106 | ev_depth (EV_P) |
2184 | ev_depth (EV_P) EV_THROW |
2107 | { |
2185 | { |
2108 | return loop_depth; |
2186 | return loop_depth; |
2109 | } |
2187 | } |
2110 | |
2188 | |
2111 | void |
2189 | void |
2112 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) |
2190 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2113 | { |
2191 | { |
2114 | io_blocktime = interval; |
2192 | io_blocktime = interval; |
2115 | } |
2193 | } |
2116 | |
2194 | |
2117 | void |
2195 | void |
2118 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) |
2196 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2119 | { |
2197 | { |
2120 | timeout_blocktime = interval; |
2198 | timeout_blocktime = interval; |
2121 | } |
2199 | } |
2122 | |
2200 | |
2123 | void |
2201 | void |
2124 | ev_set_userdata (EV_P_ void *data) |
2202 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2125 | { |
2203 | { |
2126 | userdata = data; |
2204 | userdata = data; |
2127 | } |
2205 | } |
2128 | |
2206 | |
2129 | void * |
2207 | void * |
2130 | ev_userdata (EV_P) |
2208 | ev_userdata (EV_P) EV_THROW |
2131 | { |
2209 | { |
2132 | return userdata; |
2210 | return userdata; |
2133 | } |
2211 | } |
2134 | |
2212 | |
2135 | void |
2213 | void |
2136 | ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) |
2214 | ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) EV_THROW |
2137 | { |
2215 | { |
2138 | invoke_cb = invoke_pending_cb; |
2216 | invoke_cb = invoke_pending_cb; |
2139 | } |
2217 | } |
2140 | |
2218 | |
2141 | void |
2219 | void |
2142 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) |
2220 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW |
2143 | { |
2221 | { |
2144 | release_cb = release; |
2222 | release_cb = release; |
2145 | acquire_cb = acquire; |
2223 | acquire_cb = acquire; |
2146 | } |
2224 | } |
2147 | #endif |
2225 | #endif |
2148 | |
2226 | |
2149 | /* initialise a loop structure, must be zero-initialised */ |
2227 | /* initialise a loop structure, must be zero-initialised */ |
2150 | static void noinline ecb_cold |
2228 | static void noinline ecb_cold |
2151 | loop_init (EV_P_ unsigned int flags) |
2229 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2152 | { |
2230 | { |
2153 | if (!backend) |
2231 | if (!backend) |
2154 | { |
2232 | { |
2155 | origflags = flags; |
2233 | origflags = flags; |
2156 | |
2234 | |
… | |
… | |
2409 | } |
2487 | } |
2410 | |
2488 | |
2411 | #if EV_MULTIPLICITY |
2489 | #if EV_MULTIPLICITY |
2412 | |
2490 | |
2413 | struct ev_loop * ecb_cold |
2491 | struct ev_loop * ecb_cold |
2414 | ev_loop_new (unsigned int flags) |
2492 | ev_loop_new (unsigned int flags) EV_THROW |
2415 | { |
2493 | { |
2416 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2494 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2417 | |
2495 | |
2418 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2496 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2419 | loop_init (EV_A_ flags); |
2497 | loop_init (EV_A_ flags); |
… | |
… | |
2463 | } |
2541 | } |
2464 | #endif |
2542 | #endif |
2465 | |
2543 | |
2466 | #if EV_FEATURE_API |
2544 | #if EV_FEATURE_API |
2467 | void ecb_cold |
2545 | void ecb_cold |
2468 | ev_verify (EV_P) |
2546 | ev_verify (EV_P) EV_THROW |
2469 | { |
2547 | { |
2470 | #if EV_VERIFY |
2548 | #if EV_VERIFY |
2471 | int i; |
2549 | int i; |
2472 | WL w; |
2550 | WL w; |
2473 | |
2551 | |
… | |
… | |
2542 | #if EV_MULTIPLICITY |
2620 | #if EV_MULTIPLICITY |
2543 | struct ev_loop * ecb_cold |
2621 | struct ev_loop * ecb_cold |
2544 | #else |
2622 | #else |
2545 | int |
2623 | int |
2546 | #endif |
2624 | #endif |
2547 | ev_default_loop (unsigned int flags) |
2625 | ev_default_loop (unsigned int flags) EV_THROW |
2548 | { |
2626 | { |
2549 | if (!ev_default_loop_ptr) |
2627 | if (!ev_default_loop_ptr) |
2550 | { |
2628 | { |
2551 | #if EV_MULTIPLICITY |
2629 | #if EV_MULTIPLICITY |
2552 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
2630 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
2571 | |
2649 | |
2572 | return ev_default_loop_ptr; |
2650 | return ev_default_loop_ptr; |
2573 | } |
2651 | } |
2574 | |
2652 | |
2575 | void |
2653 | void |
2576 | ev_loop_fork (EV_P) |
2654 | ev_loop_fork (EV_P) EV_THROW |
2577 | { |
2655 | { |
2578 | postfork = 1; /* must be in line with ev_default_fork */ |
2656 | postfork = 1; /* must be in line with ev_default_fork */ |
2579 | } |
2657 | } |
2580 | |
2658 | |
2581 | /*****************************************************************************/ |
2659 | /*****************************************************************************/ |
… | |
… | |
2585 | { |
2663 | { |
2586 | EV_CB_INVOKE ((W)w, revents); |
2664 | EV_CB_INVOKE ((W)w, revents); |
2587 | } |
2665 | } |
2588 | |
2666 | |
2589 | unsigned int |
2667 | unsigned int |
2590 | ev_pending_count (EV_P) |
2668 | ev_pending_count (EV_P) EV_THROW |
2591 | { |
2669 | { |
2592 | int pri; |
2670 | int pri; |
2593 | unsigned int count = 0; |
2671 | unsigned int count = 0; |
2594 | |
2672 | |
2595 | for (pri = NUMPRI; pri--; ) |
2673 | for (pri = NUMPRI; pri--; ) |
… | |
… | |
2854 | |
2932 | |
2855 | mn_now = ev_rt_now; |
2933 | mn_now = ev_rt_now; |
2856 | } |
2934 | } |
2857 | } |
2935 | } |
2858 | |
2936 | |
2859 | void |
2937 | int |
2860 | ev_run (EV_P_ int flags) |
2938 | ev_run (EV_P_ int flags) |
2861 | { |
2939 | { |
2862 | #if EV_FEATURE_API |
2940 | #if EV_FEATURE_API |
2863 | ++loop_depth; |
2941 | ++loop_depth; |
2864 | #endif |
2942 | #endif |
… | |
… | |
2977 | #endif |
3055 | #endif |
2978 | assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */ |
3056 | assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */ |
2979 | backend_poll (EV_A_ waittime); |
3057 | backend_poll (EV_A_ waittime); |
2980 | assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ |
3058 | assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ |
2981 | |
3059 | |
2982 | pipe_write_wanted = 0; /* just an optimsiation, no fence needed */ |
3060 | pipe_write_wanted = 0; /* just an optimisation, no fence needed */ |
2983 | |
3061 | |
2984 | if (pipe_write_skipped) |
3062 | if (pipe_write_skipped) |
2985 | { |
3063 | { |
2986 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
3064 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
2987 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
3065 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
… | |
… | |
3021 | loop_done = EVBREAK_CANCEL; |
3099 | loop_done = EVBREAK_CANCEL; |
3022 | |
3100 | |
3023 | #if EV_FEATURE_API |
3101 | #if EV_FEATURE_API |
3024 | --loop_depth; |
3102 | --loop_depth; |
3025 | #endif |
3103 | #endif |
|
|
3104 | |
|
|
3105 | return activecnt; |
3026 | } |
3106 | } |
3027 | |
3107 | |
3028 | void |
3108 | void |
3029 | ev_break (EV_P_ int how) |
3109 | ev_break (EV_P_ int how) EV_THROW |
3030 | { |
3110 | { |
3031 | loop_done = how; |
3111 | loop_done = how; |
3032 | } |
3112 | } |
3033 | |
3113 | |
3034 | void |
3114 | void |
3035 | ev_ref (EV_P) |
3115 | ev_ref (EV_P) EV_THROW |
3036 | { |
3116 | { |
3037 | ++activecnt; |
3117 | ++activecnt; |
3038 | } |
3118 | } |
3039 | |
3119 | |
3040 | void |
3120 | void |
3041 | ev_unref (EV_P) |
3121 | ev_unref (EV_P) EV_THROW |
3042 | { |
3122 | { |
3043 | --activecnt; |
3123 | --activecnt; |
3044 | } |
3124 | } |
3045 | |
3125 | |
3046 | void |
3126 | void |
3047 | ev_now_update (EV_P) |
3127 | ev_now_update (EV_P) EV_THROW |
3048 | { |
3128 | { |
3049 | time_update (EV_A_ 1e100); |
3129 | time_update (EV_A_ 1e100); |
3050 | } |
3130 | } |
3051 | |
3131 | |
3052 | void |
3132 | void |
3053 | ev_suspend (EV_P) |
3133 | ev_suspend (EV_P) EV_THROW |
3054 | { |
3134 | { |
3055 | ev_now_update (EV_A); |
3135 | ev_now_update (EV_A); |
3056 | } |
3136 | } |
3057 | |
3137 | |
3058 | void |
3138 | void |
3059 | ev_resume (EV_P) |
3139 | ev_resume (EV_P) EV_THROW |
3060 | { |
3140 | { |
3061 | ev_tstamp mn_prev = mn_now; |
3141 | ev_tstamp mn_prev = mn_now; |
3062 | |
3142 | |
3063 | ev_now_update (EV_A); |
3143 | ev_now_update (EV_A); |
3064 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3144 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3103 | w->pending = 0; |
3183 | w->pending = 0; |
3104 | } |
3184 | } |
3105 | } |
3185 | } |
3106 | |
3186 | |
3107 | int |
3187 | int |
3108 | ev_clear_pending (EV_P_ void *w) |
3188 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3109 | { |
3189 | { |
3110 | W w_ = (W)w; |
3190 | W w_ = (W)w; |
3111 | int pending = w_->pending; |
3191 | int pending = w_->pending; |
3112 | |
3192 | |
3113 | if (expect_true (pending)) |
3193 | if (expect_true (pending)) |
… | |
… | |
3146 | } |
3226 | } |
3147 | |
3227 | |
3148 | /*****************************************************************************/ |
3228 | /*****************************************************************************/ |
3149 | |
3229 | |
3150 | void noinline |
3230 | void noinline |
3151 | ev_io_start (EV_P_ ev_io *w) |
3231 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3152 | { |
3232 | { |
3153 | int fd = w->fd; |
3233 | int fd = w->fd; |
3154 | |
3234 | |
3155 | if (expect_false (ev_is_active (w))) |
3235 | if (expect_false (ev_is_active (w))) |
3156 | return; |
3236 | return; |
… | |
… | |
3169 | |
3249 | |
3170 | EV_FREQUENT_CHECK; |
3250 | EV_FREQUENT_CHECK; |
3171 | } |
3251 | } |
3172 | |
3252 | |
3173 | void noinline |
3253 | void noinline |
3174 | ev_io_stop (EV_P_ ev_io *w) |
3254 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3175 | { |
3255 | { |
3176 | clear_pending (EV_A_ (W)w); |
3256 | clear_pending (EV_A_ (W)w); |
3177 | if (expect_false (!ev_is_active (w))) |
3257 | if (expect_false (!ev_is_active (w))) |
3178 | return; |
3258 | return; |
3179 | |
3259 | |
… | |
… | |
3188 | |
3268 | |
3189 | EV_FREQUENT_CHECK; |
3269 | EV_FREQUENT_CHECK; |
3190 | } |
3270 | } |
3191 | |
3271 | |
3192 | void noinline |
3272 | void noinline |
3193 | ev_timer_start (EV_P_ ev_timer *w) |
3273 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3194 | { |
3274 | { |
3195 | if (expect_false (ev_is_active (w))) |
3275 | if (expect_false (ev_is_active (w))) |
3196 | return; |
3276 | return; |
3197 | |
3277 | |
3198 | ev_at (w) += mn_now; |
3278 | ev_at (w) += mn_now; |
… | |
… | |
3212 | |
3292 | |
3213 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3293 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3214 | } |
3294 | } |
3215 | |
3295 | |
3216 | void noinline |
3296 | void noinline |
3217 | ev_timer_stop (EV_P_ ev_timer *w) |
3297 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3218 | { |
3298 | { |
3219 | clear_pending (EV_A_ (W)w); |
3299 | clear_pending (EV_A_ (W)w); |
3220 | if (expect_false (!ev_is_active (w))) |
3300 | if (expect_false (!ev_is_active (w))) |
3221 | return; |
3301 | return; |
3222 | |
3302 | |
… | |
… | |
3242 | |
3322 | |
3243 | EV_FREQUENT_CHECK; |
3323 | EV_FREQUENT_CHECK; |
3244 | } |
3324 | } |
3245 | |
3325 | |
3246 | void noinline |
3326 | void noinline |
3247 | ev_timer_again (EV_P_ ev_timer *w) |
3327 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
3248 | { |
3328 | { |
3249 | EV_FREQUENT_CHECK; |
3329 | EV_FREQUENT_CHECK; |
|
|
3330 | |
|
|
3331 | clear_pending (EV_A_ (W)w); |
3250 | |
3332 | |
3251 | if (ev_is_active (w)) |
3333 | if (ev_is_active (w)) |
3252 | { |
3334 | { |
3253 | if (w->repeat) |
3335 | if (w->repeat) |
3254 | { |
3336 | { |
… | |
… | |
3267 | |
3349 | |
3268 | EV_FREQUENT_CHECK; |
3350 | EV_FREQUENT_CHECK; |
3269 | } |
3351 | } |
3270 | |
3352 | |
3271 | ev_tstamp |
3353 | ev_tstamp |
3272 | ev_timer_remaining (EV_P_ ev_timer *w) |
3354 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
3273 | { |
3355 | { |
3274 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3356 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3275 | } |
3357 | } |
3276 | |
3358 | |
3277 | #if EV_PERIODIC_ENABLE |
3359 | #if EV_PERIODIC_ENABLE |
3278 | void noinline |
3360 | void noinline |
3279 | ev_periodic_start (EV_P_ ev_periodic *w) |
3361 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
3280 | { |
3362 | { |
3281 | if (expect_false (ev_is_active (w))) |
3363 | if (expect_false (ev_is_active (w))) |
3282 | return; |
3364 | return; |
3283 | |
3365 | |
3284 | if (w->reschedule_cb) |
3366 | if (w->reschedule_cb) |
… | |
… | |
3304 | |
3386 | |
3305 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3387 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3306 | } |
3388 | } |
3307 | |
3389 | |
3308 | void noinline |
3390 | void noinline |
3309 | ev_periodic_stop (EV_P_ ev_periodic *w) |
3391 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
3310 | { |
3392 | { |
3311 | clear_pending (EV_A_ (W)w); |
3393 | clear_pending (EV_A_ (W)w); |
3312 | if (expect_false (!ev_is_active (w))) |
3394 | if (expect_false (!ev_is_active (w))) |
3313 | return; |
3395 | return; |
3314 | |
3396 | |
… | |
… | |
3332 | |
3414 | |
3333 | EV_FREQUENT_CHECK; |
3415 | EV_FREQUENT_CHECK; |
3334 | } |
3416 | } |
3335 | |
3417 | |
3336 | void noinline |
3418 | void noinline |
3337 | ev_periodic_again (EV_P_ ev_periodic *w) |
3419 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
3338 | { |
3420 | { |
3339 | /* TODO: use adjustheap and recalculation */ |
3421 | /* TODO: use adjustheap and recalculation */ |
3340 | ev_periodic_stop (EV_A_ w); |
3422 | ev_periodic_stop (EV_A_ w); |
3341 | ev_periodic_start (EV_A_ w); |
3423 | ev_periodic_start (EV_A_ w); |
3342 | } |
3424 | } |
… | |
… | |
3347 | #endif |
3429 | #endif |
3348 | |
3430 | |
3349 | #if EV_SIGNAL_ENABLE |
3431 | #if EV_SIGNAL_ENABLE |
3350 | |
3432 | |
3351 | void noinline |
3433 | void noinline |
3352 | ev_signal_start (EV_P_ ev_signal *w) |
3434 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
3353 | { |
3435 | { |
3354 | if (expect_false (ev_is_active (w))) |
3436 | if (expect_false (ev_is_active (w))) |
3355 | return; |
3437 | return; |
3356 | |
3438 | |
3357 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
3439 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
… | |
… | |
3428 | |
3510 | |
3429 | EV_FREQUENT_CHECK; |
3511 | EV_FREQUENT_CHECK; |
3430 | } |
3512 | } |
3431 | |
3513 | |
3432 | void noinline |
3514 | void noinline |
3433 | ev_signal_stop (EV_P_ ev_signal *w) |
3515 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
3434 | { |
3516 | { |
3435 | clear_pending (EV_A_ (W)w); |
3517 | clear_pending (EV_A_ (W)w); |
3436 | if (expect_false (!ev_is_active (w))) |
3518 | if (expect_false (!ev_is_active (w))) |
3437 | return; |
3519 | return; |
3438 | |
3520 | |
… | |
… | |
3469 | #endif |
3551 | #endif |
3470 | |
3552 | |
3471 | #if EV_CHILD_ENABLE |
3553 | #if EV_CHILD_ENABLE |
3472 | |
3554 | |
3473 | void |
3555 | void |
3474 | ev_child_start (EV_P_ ev_child *w) |
3556 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
3475 | { |
3557 | { |
3476 | #if EV_MULTIPLICITY |
3558 | #if EV_MULTIPLICITY |
3477 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
3559 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
3478 | #endif |
3560 | #endif |
3479 | if (expect_false (ev_is_active (w))) |
3561 | if (expect_false (ev_is_active (w))) |
… | |
… | |
3486 | |
3568 | |
3487 | EV_FREQUENT_CHECK; |
3569 | EV_FREQUENT_CHECK; |
3488 | } |
3570 | } |
3489 | |
3571 | |
3490 | void |
3572 | void |
3491 | ev_child_stop (EV_P_ ev_child *w) |
3573 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
3492 | { |
3574 | { |
3493 | clear_pending (EV_A_ (W)w); |
3575 | clear_pending (EV_A_ (W)w); |
3494 | if (expect_false (!ev_is_active (w))) |
3576 | if (expect_false (!ev_is_active (w))) |
3495 | return; |
3577 | return; |
3496 | |
3578 | |
… | |
… | |
3663 | } |
3745 | } |
3664 | |
3746 | |
3665 | inline_size int |
3747 | inline_size int |
3666 | infy_newfd (void) |
3748 | infy_newfd (void) |
3667 | { |
3749 | { |
3668 | #if defined (IN_CLOEXEC) && defined (IN_NONBLOCK) |
3750 | #if defined IN_CLOEXEC && defined IN_NONBLOCK |
3669 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3751 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3670 | if (fd >= 0) |
3752 | if (fd >= 0) |
3671 | return fd; |
3753 | return fd; |
3672 | #endif |
3754 | #endif |
3673 | return inotify_init (); |
3755 | return inotify_init (); |
… | |
… | |
3748 | #else |
3830 | #else |
3749 | # define EV_LSTAT(p,b) lstat (p, b) |
3831 | # define EV_LSTAT(p,b) lstat (p, b) |
3750 | #endif |
3832 | #endif |
3751 | |
3833 | |
3752 | void |
3834 | void |
3753 | ev_stat_stat (EV_P_ ev_stat *w) |
3835 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
3754 | { |
3836 | { |
3755 | if (lstat (w->path, &w->attr) < 0) |
3837 | if (lstat (w->path, &w->attr) < 0) |
3756 | w->attr.st_nlink = 0; |
3838 | w->attr.st_nlink = 0; |
3757 | else if (!w->attr.st_nlink) |
3839 | else if (!w->attr.st_nlink) |
3758 | w->attr.st_nlink = 1; |
3840 | w->attr.st_nlink = 1; |
… | |
… | |
3797 | ev_feed_event (EV_A_ w, EV_STAT); |
3879 | ev_feed_event (EV_A_ w, EV_STAT); |
3798 | } |
3880 | } |
3799 | } |
3881 | } |
3800 | |
3882 | |
3801 | void |
3883 | void |
3802 | ev_stat_start (EV_P_ ev_stat *w) |
3884 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
3803 | { |
3885 | { |
3804 | if (expect_false (ev_is_active (w))) |
3886 | if (expect_false (ev_is_active (w))) |
3805 | return; |
3887 | return; |
3806 | |
3888 | |
3807 | ev_stat_stat (EV_A_ w); |
3889 | ev_stat_stat (EV_A_ w); |
… | |
… | |
3828 | |
3910 | |
3829 | EV_FREQUENT_CHECK; |
3911 | EV_FREQUENT_CHECK; |
3830 | } |
3912 | } |
3831 | |
3913 | |
3832 | void |
3914 | void |
3833 | ev_stat_stop (EV_P_ ev_stat *w) |
3915 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
3834 | { |
3916 | { |
3835 | clear_pending (EV_A_ (W)w); |
3917 | clear_pending (EV_A_ (W)w); |
3836 | if (expect_false (!ev_is_active (w))) |
3918 | if (expect_false (!ev_is_active (w))) |
3837 | return; |
3919 | return; |
3838 | |
3920 | |
… | |
… | |
3854 | } |
3936 | } |
3855 | #endif |
3937 | #endif |
3856 | |
3938 | |
3857 | #if EV_IDLE_ENABLE |
3939 | #if EV_IDLE_ENABLE |
3858 | void |
3940 | void |
3859 | ev_idle_start (EV_P_ ev_idle *w) |
3941 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
3860 | { |
3942 | { |
3861 | if (expect_false (ev_is_active (w))) |
3943 | if (expect_false (ev_is_active (w))) |
3862 | return; |
3944 | return; |
3863 | |
3945 | |
3864 | pri_adjust (EV_A_ (W)w); |
3946 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
3877 | |
3959 | |
3878 | EV_FREQUENT_CHECK; |
3960 | EV_FREQUENT_CHECK; |
3879 | } |
3961 | } |
3880 | |
3962 | |
3881 | void |
3963 | void |
3882 | ev_idle_stop (EV_P_ ev_idle *w) |
3964 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
3883 | { |
3965 | { |
3884 | clear_pending (EV_A_ (W)w); |
3966 | clear_pending (EV_A_ (W)w); |
3885 | if (expect_false (!ev_is_active (w))) |
3967 | if (expect_false (!ev_is_active (w))) |
3886 | return; |
3968 | return; |
3887 | |
3969 | |
… | |
… | |
3901 | } |
3983 | } |
3902 | #endif |
3984 | #endif |
3903 | |
3985 | |
3904 | #if EV_PREPARE_ENABLE |
3986 | #if EV_PREPARE_ENABLE |
3905 | void |
3987 | void |
3906 | ev_prepare_start (EV_P_ ev_prepare *w) |
3988 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
3907 | { |
3989 | { |
3908 | if (expect_false (ev_is_active (w))) |
3990 | if (expect_false (ev_is_active (w))) |
3909 | return; |
3991 | return; |
3910 | |
3992 | |
3911 | EV_FREQUENT_CHECK; |
3993 | EV_FREQUENT_CHECK; |
… | |
… | |
3916 | |
3998 | |
3917 | EV_FREQUENT_CHECK; |
3999 | EV_FREQUENT_CHECK; |
3918 | } |
4000 | } |
3919 | |
4001 | |
3920 | void |
4002 | void |
3921 | ev_prepare_stop (EV_P_ ev_prepare *w) |
4003 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
3922 | { |
4004 | { |
3923 | clear_pending (EV_A_ (W)w); |
4005 | clear_pending (EV_A_ (W)w); |
3924 | if (expect_false (!ev_is_active (w))) |
4006 | if (expect_false (!ev_is_active (w))) |
3925 | return; |
4007 | return; |
3926 | |
4008 | |
… | |
… | |
3939 | } |
4021 | } |
3940 | #endif |
4022 | #endif |
3941 | |
4023 | |
3942 | #if EV_CHECK_ENABLE |
4024 | #if EV_CHECK_ENABLE |
3943 | void |
4025 | void |
3944 | ev_check_start (EV_P_ ev_check *w) |
4026 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
3945 | { |
4027 | { |
3946 | if (expect_false (ev_is_active (w))) |
4028 | if (expect_false (ev_is_active (w))) |
3947 | return; |
4029 | return; |
3948 | |
4030 | |
3949 | EV_FREQUENT_CHECK; |
4031 | EV_FREQUENT_CHECK; |
… | |
… | |
3954 | |
4036 | |
3955 | EV_FREQUENT_CHECK; |
4037 | EV_FREQUENT_CHECK; |
3956 | } |
4038 | } |
3957 | |
4039 | |
3958 | void |
4040 | void |
3959 | ev_check_stop (EV_P_ ev_check *w) |
4041 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
3960 | { |
4042 | { |
3961 | clear_pending (EV_A_ (W)w); |
4043 | clear_pending (EV_A_ (W)w); |
3962 | if (expect_false (!ev_is_active (w))) |
4044 | if (expect_false (!ev_is_active (w))) |
3963 | return; |
4045 | return; |
3964 | |
4046 | |
… | |
… | |
3977 | } |
4059 | } |
3978 | #endif |
4060 | #endif |
3979 | |
4061 | |
3980 | #if EV_EMBED_ENABLE |
4062 | #if EV_EMBED_ENABLE |
3981 | void noinline |
4063 | void noinline |
3982 | ev_embed_sweep (EV_P_ ev_embed *w) |
4064 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
3983 | { |
4065 | { |
3984 | ev_run (w->other, EVRUN_NOWAIT); |
4066 | ev_run (w->other, EVRUN_NOWAIT); |
3985 | } |
4067 | } |
3986 | |
4068 | |
3987 | static void |
4069 | static void |
… | |
… | |
4035 | ev_idle_stop (EV_A_ idle); |
4117 | ev_idle_stop (EV_A_ idle); |
4036 | } |
4118 | } |
4037 | #endif |
4119 | #endif |
4038 | |
4120 | |
4039 | void |
4121 | void |
4040 | ev_embed_start (EV_P_ ev_embed *w) |
4122 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4041 | { |
4123 | { |
4042 | if (expect_false (ev_is_active (w))) |
4124 | if (expect_false (ev_is_active (w))) |
4043 | return; |
4125 | return; |
4044 | |
4126 | |
4045 | { |
4127 | { |
… | |
… | |
4066 | |
4148 | |
4067 | EV_FREQUENT_CHECK; |
4149 | EV_FREQUENT_CHECK; |
4068 | } |
4150 | } |
4069 | |
4151 | |
4070 | void |
4152 | void |
4071 | ev_embed_stop (EV_P_ ev_embed *w) |
4153 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4072 | { |
4154 | { |
4073 | clear_pending (EV_A_ (W)w); |
4155 | clear_pending (EV_A_ (W)w); |
4074 | if (expect_false (!ev_is_active (w))) |
4156 | if (expect_false (!ev_is_active (w))) |
4075 | return; |
4157 | return; |
4076 | |
4158 | |
… | |
… | |
4086 | } |
4168 | } |
4087 | #endif |
4169 | #endif |
4088 | |
4170 | |
4089 | #if EV_FORK_ENABLE |
4171 | #if EV_FORK_ENABLE |
4090 | void |
4172 | void |
4091 | ev_fork_start (EV_P_ ev_fork *w) |
4173 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4092 | { |
4174 | { |
4093 | if (expect_false (ev_is_active (w))) |
4175 | if (expect_false (ev_is_active (w))) |
4094 | return; |
4176 | return; |
4095 | |
4177 | |
4096 | EV_FREQUENT_CHECK; |
4178 | EV_FREQUENT_CHECK; |
… | |
… | |
4101 | |
4183 | |
4102 | EV_FREQUENT_CHECK; |
4184 | EV_FREQUENT_CHECK; |
4103 | } |
4185 | } |
4104 | |
4186 | |
4105 | void |
4187 | void |
4106 | ev_fork_stop (EV_P_ ev_fork *w) |
4188 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4107 | { |
4189 | { |
4108 | clear_pending (EV_A_ (W)w); |
4190 | clear_pending (EV_A_ (W)w); |
4109 | if (expect_false (!ev_is_active (w))) |
4191 | if (expect_false (!ev_is_active (w))) |
4110 | return; |
4192 | return; |
4111 | |
4193 | |
… | |
… | |
4124 | } |
4206 | } |
4125 | #endif |
4207 | #endif |
4126 | |
4208 | |
4127 | #if EV_CLEANUP_ENABLE |
4209 | #if EV_CLEANUP_ENABLE |
4128 | void |
4210 | void |
4129 | ev_cleanup_start (EV_P_ ev_cleanup *w) |
4211 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4130 | { |
4212 | { |
4131 | if (expect_false (ev_is_active (w))) |
4213 | if (expect_false (ev_is_active (w))) |
4132 | return; |
4214 | return; |
4133 | |
4215 | |
4134 | EV_FREQUENT_CHECK; |
4216 | EV_FREQUENT_CHECK; |
… | |
… | |
4141 | ev_unref (EV_A); |
4223 | ev_unref (EV_A); |
4142 | EV_FREQUENT_CHECK; |
4224 | EV_FREQUENT_CHECK; |
4143 | } |
4225 | } |
4144 | |
4226 | |
4145 | void |
4227 | void |
4146 | ev_cleanup_stop (EV_P_ ev_cleanup *w) |
4228 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4147 | { |
4229 | { |
4148 | clear_pending (EV_A_ (W)w); |
4230 | clear_pending (EV_A_ (W)w); |
4149 | if (expect_false (!ev_is_active (w))) |
4231 | if (expect_false (!ev_is_active (w))) |
4150 | return; |
4232 | return; |
4151 | |
4233 | |
… | |
… | |
4165 | } |
4247 | } |
4166 | #endif |
4248 | #endif |
4167 | |
4249 | |
4168 | #if EV_ASYNC_ENABLE |
4250 | #if EV_ASYNC_ENABLE |
4169 | void |
4251 | void |
4170 | ev_async_start (EV_P_ ev_async *w) |
4252 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4171 | { |
4253 | { |
4172 | if (expect_false (ev_is_active (w))) |
4254 | if (expect_false (ev_is_active (w))) |
4173 | return; |
4255 | return; |
4174 | |
4256 | |
4175 | w->sent = 0; |
4257 | w->sent = 0; |
… | |
… | |
4184 | |
4266 | |
4185 | EV_FREQUENT_CHECK; |
4267 | EV_FREQUENT_CHECK; |
4186 | } |
4268 | } |
4187 | |
4269 | |
4188 | void |
4270 | void |
4189 | ev_async_stop (EV_P_ ev_async *w) |
4271 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4190 | { |
4272 | { |
4191 | clear_pending (EV_A_ (W)w); |
4273 | clear_pending (EV_A_ (W)w); |
4192 | if (expect_false (!ev_is_active (w))) |
4274 | if (expect_false (!ev_is_active (w))) |
4193 | return; |
4275 | return; |
4194 | |
4276 | |
… | |
… | |
4205 | |
4287 | |
4206 | EV_FREQUENT_CHECK; |
4288 | EV_FREQUENT_CHECK; |
4207 | } |
4289 | } |
4208 | |
4290 | |
4209 | void |
4291 | void |
4210 | ev_async_send (EV_P_ ev_async *w) |
4292 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
4211 | { |
4293 | { |
4212 | w->sent = 1; |
4294 | w->sent = 1; |
4213 | evpipe_write (EV_A_ &async_pending); |
4295 | evpipe_write (EV_A_ &async_pending); |
4214 | } |
4296 | } |
4215 | #endif |
4297 | #endif |
… | |
… | |
4252 | |
4334 | |
4253 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4335 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4254 | } |
4336 | } |
4255 | |
4337 | |
4256 | void |
4338 | void |
4257 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
4339 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW |
4258 | { |
4340 | { |
4259 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4341 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4260 | |
4342 | |
4261 | if (expect_false (!once)) |
4343 | if (expect_false (!once)) |
4262 | { |
4344 | { |
… | |
… | |
4284 | |
4366 | |
4285 | /*****************************************************************************/ |
4367 | /*****************************************************************************/ |
4286 | |
4368 | |
4287 | #if EV_WALK_ENABLE |
4369 | #if EV_WALK_ENABLE |
4288 | void ecb_cold |
4370 | void ecb_cold |
4289 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) |
4371 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
4290 | { |
4372 | { |
4291 | int i, j; |
4373 | int i, j; |
4292 | ev_watcher_list *wl, *wn; |
4374 | ev_watcher_list *wl, *wn; |
4293 | |
4375 | |
4294 | if (types & (EV_IO | EV_EMBED)) |
4376 | if (types & (EV_IO | EV_EMBED)) |
… | |
… | |
4400 | |
4482 | |
4401 | #if EV_MULTIPLICITY |
4483 | #if EV_MULTIPLICITY |
4402 | #include "ev_wrap.h" |
4484 | #include "ev_wrap.h" |
4403 | #endif |
4485 | #endif |
4404 | |
4486 | |
4405 | EV_CPP(}) |
|
|
4406 | |
|
|