ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.427 by root, Sun May 6 19:29:59 2012 UTC vs.
Revision 1.451 by root, Tue Jan 22 05:18:28 2013 UTC

201# include <sys/wait.h> 201# include <sys/wait.h>
202# include <unistd.h> 202# include <unistd.h>
203#else 203#else
204# include <io.h> 204# include <io.h>
205# define WIN32_LEAN_AND_MEAN 205# define WIN32_LEAN_AND_MEAN
206# include <winsock2.h>
206# include <windows.h> 207# include <windows.h>
207# ifndef EV_SELECT_IS_WINSOCKET 208# ifndef EV_SELECT_IS_WINSOCKET
208# define EV_SELECT_IS_WINSOCKET 1 209# define EV_SELECT_IS_WINSOCKET 1
209# endif 210# endif
210# undef EV_AVOID_STDIO 211# undef EV_AVOID_STDIO
408/* some very old inotify.h headers don't have IN_DONT_FOLLOW */ 409/* some very old inotify.h headers don't have IN_DONT_FOLLOW */
409# ifndef IN_DONT_FOLLOW 410# ifndef IN_DONT_FOLLOW
410# undef EV_USE_INOTIFY 411# undef EV_USE_INOTIFY
411# define EV_USE_INOTIFY 0 412# define EV_USE_INOTIFY 0
412# endif 413# endif
413#endif
414
415#if EV_SELECT_IS_WINSOCKET
416# include <winsock.h>
417#endif 414#endif
418 415
419#if EV_USE_EVENTFD 416#if EV_USE_EVENTFD
420/* our minimum requirement is glibc 2.7 which has the stub, but not the header */ 417/* our minimum requirement is glibc 2.7 which has the stub, but not the header */
421# include <stdint.h> 418# include <stdint.h>
507 */ 504 */
508 505
509#ifndef ECB_H 506#ifndef ECB_H
510#define ECB_H 507#define ECB_H
511 508
509/* 16 bits major, 16 bits minor */
510#define ECB_VERSION 0x00010002
511
512#ifdef _WIN32 512#ifdef _WIN32
513 typedef signed char int8_t; 513 typedef signed char int8_t;
514 typedef unsigned char uint8_t; 514 typedef unsigned char uint8_t;
515 typedef signed short int16_t; 515 typedef signed short int16_t;
516 typedef unsigned short uint16_t; 516 typedef unsigned short uint16_t;
521 typedef unsigned long long uint64_t; 521 typedef unsigned long long uint64_t;
522 #else /* _MSC_VER || __BORLANDC__ */ 522 #else /* _MSC_VER || __BORLANDC__ */
523 typedef signed __int64 int64_t; 523 typedef signed __int64 int64_t;
524 typedef unsigned __int64 uint64_t; 524 typedef unsigned __int64 uint64_t;
525 #endif 525 #endif
526 #ifdef _WIN64
527 #define ECB_PTRSIZE 8
528 typedef uint64_t uintptr_t;
529 typedef int64_t intptr_t;
530 #else
531 #define ECB_PTRSIZE 4
532 typedef uint32_t uintptr_t;
533 typedef int32_t intptr_t;
534 #endif
526#else 535#else
527 #include <inttypes.h> 536 #include <inttypes.h>
537 #if UINTMAX_MAX > 0xffffffffU
538 #define ECB_PTRSIZE 8
539 #else
540 #define ECB_PTRSIZE 4
541 #endif
528#endif 542#endif
529 543
530/* many compilers define _GNUC_ to some versions but then only implement 544/* many compilers define _GNUC_ to some versions but then only implement
531 * what their idiot authors think are the "more important" extensions, 545 * what their idiot authors think are the "more important" extensions,
532 * causing enormous grief in return for some better fake benchmark numbers. 546 * causing enormous grief in return for some better fake benchmark numbers.
540 #else 554 #else
541 #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) 555 #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
542 #endif 556 #endif
543#endif 557#endif
544 558
559#define ECB_C (__STDC__+0) /* this assumes that __STDC__ is either empty or a number */
560#define ECB_C99 (__STDC_VERSION__ >= 199901L)
561#define ECB_C11 (__STDC_VERSION__ >= 201112L)
562#define ECB_CPP (__cplusplus+0)
563#define ECB_CPP11 (__cplusplus >= 201103L)
564
565#if ECB_CPP
566 #define ECB_EXTERN_C extern "C"
567 #define ECB_EXTERN_C_BEG ECB_EXTERN_C {
568 #define ECB_EXTERN_C_END }
569#else
570 #define ECB_EXTERN_C extern
571 #define ECB_EXTERN_C_BEG
572 #define ECB_EXTERN_C_END
573#endif
574
545/*****************************************************************************/ 575/*****************************************************************************/
546 576
547/* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ 577/* ECB_NO_THREADS - ecb is not used by multiple threads, ever */
548/* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ 578/* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */
549 579
550#if ECB_NO_THREADS 580#if ECB_NO_THREADS
551# define ECB_NO_SMP 1 581 #define ECB_NO_SMP 1
552#endif 582#endif
553 583
554#if ECB_NO_THREADS || ECB_NO_SMP 584#if ECB_NO_SMP
555 #define ECB_MEMORY_FENCE do { } while (0) 585 #define ECB_MEMORY_FENCE do { } while (0)
556#endif 586#endif
557 587
558#ifndef ECB_MEMORY_FENCE 588#ifndef ECB_MEMORY_FENCE
559 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 589 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
560 #if __i386 || __i386__ 590 #if __i386 || __i386__
561 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") 591 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
562 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */ 592 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
563 #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ 593 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("")
564 #elif __amd64 || __amd64__ || __x86_64 || __x86_64__ 594 #elif __amd64 || __amd64__ || __x86_64 || __x86_64__
565 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") 595 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
566 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") 596 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
567 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */ 597 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("")
568 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ 598 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__
569 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 599 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
570 #elif defined __ARM_ARCH_6__ || defined __ARM_ARCH_6J__ \ 600 #elif defined __ARM_ARCH_6__ || defined __ARM_ARCH_6J__ \
571 || defined __ARM_ARCH_6K__ || defined __ARM_ARCH_6ZK__ 601 || defined __ARM_ARCH_6K__ || defined __ARM_ARCH_6ZK__
572 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory") 602 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory")
573 #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \ 603 #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \
574 || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__ 604 || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__
575 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") 605 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory")
576 #elif __sparc || __sparc__ 606 #elif __sparc || __sparc__
577 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad | " : : : "memory") 607 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad" : : : "memory")
578 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") 608 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory")
579 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") 609 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore")
580 #elif defined __s390__ || defined __s390x__ 610 #elif defined __s390__ || defined __s390x__
581 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") 611 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory")
582 #elif defined __mips__ 612 #elif defined __mips__
583 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 613 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
584 #elif defined __alpha__ 614 #elif defined __alpha__
585 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mb" : : : "memory") 615 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mb" : : : "memory")
616 #elif defined __hppa__
617 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("" : : : "memory")
618 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("")
619 #elif defined __ia64__
620 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mf" : : : "memory")
586 #endif 621 #endif
587 #endif 622 #endif
588#endif 623#endif
589 624
590#ifndef ECB_MEMORY_FENCE 625#ifndef ECB_MEMORY_FENCE
626 #if ECB_GCC_VERSION(4,7)
627 /* see comment below (stdatomic.h) about the C11 memory model. */
628 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST)
629
630 /* The __has_feature syntax from clang is so misdesigned that we cannot use it
631 * without risking compile time errors with other compilers. We *could*
632 * define our own ecb_clang_has_feature, but I just can't be bothered to work
633 * around this shit time and again.
634 * #elif defined __clang && __has_feature (cxx_atomic)
635 * // see comment below (stdatomic.h) about the C11 memory model.
636 * #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST)
637 */
638
591 #if ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ 639 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__
592 #define ECB_MEMORY_FENCE __sync_synchronize () 640 #define ECB_MEMORY_FENCE __sync_synchronize ()
593 /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */
594 /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */
595 #elif _MSC_VER >= 1400 /* VC++ 2005 */ 641 #elif _MSC_VER >= 1400 /* VC++ 2005 */
596 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) 642 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier)
597 #define ECB_MEMORY_FENCE _ReadWriteBarrier () 643 #define ECB_MEMORY_FENCE _ReadWriteBarrier ()
598 #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ 644 #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */
599 #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () 645 #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier ()
609 #define ECB_MEMORY_FENCE __sync () 655 #define ECB_MEMORY_FENCE __sync ()
610 #endif 656 #endif
611#endif 657#endif
612 658
613#ifndef ECB_MEMORY_FENCE 659#ifndef ECB_MEMORY_FENCE
660 #if ECB_C11 && !defined __STDC_NO_ATOMICS__
661 /* we assume that these memory fences work on all variables/all memory accesses, */
662 /* not just C11 atomics and atomic accesses */
663 #include <stdatomic.h>
664 /* Unfortunately, neither gcc 4.7 nor clang 3.1 generate any instructions for */
665 /* any fence other than seq_cst, which isn't very efficient for us. */
666 /* Why that is, we don't know - either the C11 memory model is quite useless */
667 /* for most usages, or gcc and clang have a bug */
668 /* I *currently* lean towards the latter, and inefficiently implement */
669 /* all three of ecb's fences as a seq_cst fence */
670 #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst)
671 #endif
672#endif
673
674#ifndef ECB_MEMORY_FENCE
614 #if !ECB_AVOID_PTHREADS 675 #if !ECB_AVOID_PTHREADS
615 /* 676 /*
616 * if you get undefined symbol references to pthread_mutex_lock, 677 * if you get undefined symbol references to pthread_mutex_lock,
617 * or failure to find pthread.h, then you should implement 678 * or failure to find pthread.h, then you should implement
618 * the ECB_MEMORY_FENCE operations for your cpu/compiler 679 * the ECB_MEMORY_FENCE operations for your cpu/compiler
636 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE 697 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
637#endif 698#endif
638 699
639/*****************************************************************************/ 700/*****************************************************************************/
640 701
641#define ECB_C99 (__STDC_VERSION__ >= 199901L)
642
643#if __cplusplus 702#if __cplusplus
644 #define ecb_inline static inline 703 #define ecb_inline static inline
645#elif ECB_GCC_VERSION(2,5) 704#elif ECB_GCC_VERSION(2,5)
646 #define ecb_inline static __inline__ 705 #define ecb_inline static __inline__
647#elif ECB_C99 706#elif ECB_C99
685#elif ECB_GCC_VERSION(3,0) 744#elif ECB_GCC_VERSION(3,0)
686 #define ecb_decltype(x) __typeof(x) 745 #define ecb_decltype(x) __typeof(x)
687#endif 746#endif
688 747
689#define ecb_noinline ecb_attribute ((__noinline__)) 748#define ecb_noinline ecb_attribute ((__noinline__))
690#define ecb_noreturn ecb_attribute ((__noreturn__))
691#define ecb_unused ecb_attribute ((__unused__)) 749#define ecb_unused ecb_attribute ((__unused__))
692#define ecb_const ecb_attribute ((__const__)) 750#define ecb_const ecb_attribute ((__const__))
693#define ecb_pure ecb_attribute ((__pure__)) 751#define ecb_pure ecb_attribute ((__pure__))
752
753#if ECB_C11
754 #define ecb_noreturn _Noreturn
755#else
756 #define ecb_noreturn ecb_attribute ((__noreturn__))
757#endif
694 758
695#if ECB_GCC_VERSION(4,3) 759#if ECB_GCC_VERSION(4,3)
696 #define ecb_artificial ecb_attribute ((__artificial__)) 760 #define ecb_artificial ecb_attribute ((__artificial__))
697 #define ecb_hot ecb_attribute ((__hot__)) 761 #define ecb_hot ecb_attribute ((__hot__))
698 #define ecb_cold ecb_attribute ((__cold__)) 762 #define ecb_cold ecb_attribute ((__cold__))
789 853
790 return r + ecb_ld32 (x); 854 return r + ecb_ld32 (x);
791 } 855 }
792#endif 856#endif
793 857
858ecb_function_ ecb_bool ecb_is_pot32 (uint32_t x) ecb_const;
859ecb_function_ ecb_bool ecb_is_pot32 (uint32_t x) { return !(x & (x - 1)); }
860ecb_function_ ecb_bool ecb_is_pot64 (uint64_t x) ecb_const;
861ecb_function_ ecb_bool ecb_is_pot64 (uint64_t x) { return !(x & (x - 1)); }
862
794ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) ecb_const; 863ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) ecb_const;
795ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) 864ecb_function_ uint8_t ecb_bitrev8 (uint8_t x)
796{ 865{
797 return ( (x * 0x0802U & 0x22110U) 866 return ( (x * 0x0802U & 0x22110U)
798 | (x * 0x8020U & 0x88440U)) * 0x10101U >> 16; 867 | (x * 0x8020U & 0x88440U)) * 0x10101U >> 16;
882 ecb_inline void ecb_unreachable (void) ecb_noreturn; 951 ecb_inline void ecb_unreachable (void) ecb_noreturn;
883 ecb_inline void ecb_unreachable (void) { } 952 ecb_inline void ecb_unreachable (void) { }
884#endif 953#endif
885 954
886/* try to tell the compiler that some condition is definitely true */ 955/* try to tell the compiler that some condition is definitely true */
887#define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) 956#define ecb_assume(cond) if (!(cond)) ecb_unreachable (); else 0
888 957
889ecb_inline unsigned char ecb_byteorder_helper (void) ecb_const; 958ecb_inline unsigned char ecb_byteorder_helper (void) ecb_const;
890ecb_inline unsigned char 959ecb_inline unsigned char
891ecb_byteorder_helper (void) 960ecb_byteorder_helper (void)
892{ 961{
893 const uint32_t u = 0x11223344; 962 /* the union code still generates code under pressure in gcc, */
894 return *(unsigned char *)&u; 963 /* but less than using pointers, and always seems to */
964 /* successfully return a constant. */
965 /* the reason why we have this horrible preprocessor mess */
966 /* is to avoid it in all cases, at least on common architectures */
967 /* or when using a recent enough gcc version (>= 4.6) */
968#if __i386 || __i386__ || _M_X86 || __amd64 || __amd64__ || _M_X64
969 return 0x44;
970#elif __BYTE_ORDER__ && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
971 return 0x44;
972#elif __BYTE_ORDER__ && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
973 return 0x11;
974#else
975 union
976 {
977 uint32_t i;
978 uint8_t c;
979 } u = { 0x11223344 };
980 return u.c;
981#endif
895} 982}
896 983
897ecb_inline ecb_bool ecb_big_endian (void) ecb_const; 984ecb_inline ecb_bool ecb_big_endian (void) ecb_const;
898ecb_inline ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } 985ecb_inline ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; }
899ecb_inline ecb_bool ecb_little_endian (void) ecb_const; 986ecb_inline ecb_bool ecb_little_endian (void) ecb_const;
930 } 1017 }
931#else 1018#else
932 #define ecb_array_length(name) (sizeof (name) / sizeof (name [0])) 1019 #define ecb_array_length(name) (sizeof (name) / sizeof (name [0]))
933#endif 1020#endif
934 1021
1022/*******************************************************************************/
1023/* floating point stuff, can be disabled by defining ECB_NO_LIBM */
1024
1025/* basically, everything uses "ieee pure-endian" floating point numbers */
1026/* the only noteworthy exception is ancient armle, which uses order 43218765 */
1027#if 0 \
1028 || __i386 || __i386__ \
1029 || __amd64 || __amd64__ || __x86_64 || __x86_64__ \
1030 || __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ \
1031 || defined __arm__ && defined __ARM_EABI__ \
1032 || defined __s390__ || defined __s390x__ \
1033 || defined __mips__ \
1034 || defined __alpha__ \
1035 || defined __hppa__ \
1036 || defined __ia64__ \
1037 || defined _M_IX86 || defined _M_AMD64 || defined _M_IA64
1038 #define ECB_STDFP 1
1039 #include <string.h> /* for memcpy */
1040#else
1041 #define ECB_STDFP 0
1042 #include <math.h> /* for frexp*, ldexp* */
1043#endif
1044
1045#ifndef ECB_NO_LIBM
1046
1047 /* convert a float to ieee single/binary32 */
1048 ecb_function_ uint32_t ecb_float_to_binary32 (float x) ecb_const;
1049 ecb_function_ uint32_t
1050 ecb_float_to_binary32 (float x)
1051 {
1052 uint32_t r;
1053
1054 #if ECB_STDFP
1055 memcpy (&r, &x, 4);
1056 #else
1057 /* slow emulation, works for anything but -0 */
1058 uint32_t m;
1059 int e;
1060
1061 if (x == 0e0f ) return 0x00000000U;
1062 if (x > +3.40282346638528860e+38f) return 0x7f800000U;
1063 if (x < -3.40282346638528860e+38f) return 0xff800000U;
1064 if (x != x ) return 0x7fbfffffU;
1065
1066 m = frexpf (x, &e) * 0x1000000U;
1067
1068 r = m & 0x80000000U;
1069
1070 if (r)
1071 m = -m;
1072
1073 if (e <= -126)
1074 {
1075 m &= 0xffffffU;
1076 m >>= (-125 - e);
1077 e = -126;
1078 }
1079
1080 r |= (e + 126) << 23;
1081 r |= m & 0x7fffffU;
1082 #endif
1083
1084 return r;
1085 }
1086
1087 /* converts an ieee single/binary32 to a float */
1088 ecb_function_ float ecb_binary32_to_float (uint32_t x) ecb_const;
1089 ecb_function_ float
1090 ecb_binary32_to_float (uint32_t x)
1091 {
1092 float r;
1093
1094 #if ECB_STDFP
1095 memcpy (&r, &x, 4);
1096 #else
1097 /* emulation, only works for normals and subnormals and +0 */
1098 int neg = x >> 31;
1099 int e = (x >> 23) & 0xffU;
1100
1101 x &= 0x7fffffU;
1102
1103 if (e)
1104 x |= 0x800000U;
1105 else
1106 e = 1;
1107
1108 /* we distrust ldexpf a bit and do the 2**-24 scaling by an extra multiply */
1109 r = ldexpf (x * (0.5f / 0x800000U), e - 126);
1110
1111 r = neg ? -r : r;
1112 #endif
1113
1114 return r;
1115 }
1116
1117 /* convert a double to ieee double/binary64 */
1118 ecb_function_ uint64_t ecb_double_to_binary64 (double x) ecb_const;
1119 ecb_function_ uint64_t
1120 ecb_double_to_binary64 (double x)
1121 {
1122 uint64_t r;
1123
1124 #if ECB_STDFP
1125 memcpy (&r, &x, 8);
1126 #else
1127 /* slow emulation, works for anything but -0 */
1128 uint64_t m;
1129 int e;
1130
1131 if (x == 0e0 ) return 0x0000000000000000U;
1132 if (x > +1.79769313486231470e+308) return 0x7ff0000000000000U;
1133 if (x < -1.79769313486231470e+308) return 0xfff0000000000000U;
1134 if (x != x ) return 0X7ff7ffffffffffffU;
1135
1136 m = frexp (x, &e) * 0x20000000000000U;
1137
1138 r = m & 0x8000000000000000;;
1139
1140 if (r)
1141 m = -m;
1142
1143 if (e <= -1022)
1144 {
1145 m &= 0x1fffffffffffffU;
1146 m >>= (-1021 - e);
1147 e = -1022;
1148 }
1149
1150 r |= ((uint64_t)(e + 1022)) << 52;
1151 r |= m & 0xfffffffffffffU;
1152 #endif
1153
1154 return r;
1155 }
1156
1157 /* converts an ieee double/binary64 to a double */
1158 ecb_function_ double ecb_binary64_to_double (uint64_t x) ecb_const;
1159 ecb_function_ double
1160 ecb_binary64_to_double (uint64_t x)
1161 {
1162 double r;
1163
1164 #if ECB_STDFP
1165 memcpy (&r, &x, 8);
1166 #else
1167 /* emulation, only works for normals and subnormals and +0 */
1168 int neg = x >> 63;
1169 int e = (x >> 52) & 0x7ffU;
1170
1171 x &= 0xfffffffffffffU;
1172
1173 if (e)
1174 x |= 0x10000000000000U;
1175 else
1176 e = 1;
1177
1178 /* we distrust ldexp a bit and do the 2**-53 scaling by an extra multiply */
1179 r = ldexp (x * (0.5 / 0x10000000000000U), e - 1022);
1180
1181 r = neg ? -r : r;
1182 #endif
1183
1184 return r;
1185 }
1186
1187#endif
1188
935#endif 1189#endif
936 1190
937/* ECB.H END */ 1191/* ECB.H END */
938 1192
939#if ECB_MEMORY_FENCE_NEEDS_PTHREADS 1193#if ECB_MEMORY_FENCE_NEEDS_PTHREADS
1108#endif 1362#endif
1109 1363
1110static void (*syserr_cb)(const char *msg) EV_THROW; 1364static void (*syserr_cb)(const char *msg) EV_THROW;
1111 1365
1112void ecb_cold 1366void ecb_cold
1113ev_set_syserr_cb (void (*cb)(const char *msg)) EV_THROW 1367ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW
1114{ 1368{
1115 syserr_cb = cb; 1369 syserr_cb = cb;
1116} 1370}
1117 1371
1118static void noinline ecb_cold 1372static void noinline ecb_cold
1136 abort (); 1390 abort ();
1137 } 1391 }
1138} 1392}
1139 1393
1140static void * 1394static void *
1141ev_realloc_emul (void *ptr, long size) 1395ev_realloc_emul (void *ptr, long size) EV_THROW
1142{ 1396{
1143#if __GLIBC__
1144 return realloc (ptr, size);
1145#else
1146 /* some systems, notably openbsd and darwin, fail to properly 1397 /* some systems, notably openbsd and darwin, fail to properly
1147 * implement realloc (x, 0) (as required by both ansi c-89 and 1398 * implement realloc (x, 0) (as required by both ansi c-89 and
1148 * the single unix specification, so work around them here. 1399 * the single unix specification, so work around them here.
1400 * recently, also (at least) fedora and debian started breaking it,
1401 * despite documenting it otherwise.
1149 */ 1402 */
1150 1403
1151 if (size) 1404 if (size)
1152 return realloc (ptr, size); 1405 return realloc (ptr, size);
1153 1406
1154 free (ptr); 1407 free (ptr);
1155 return 0; 1408 return 0;
1156#endif
1157} 1409}
1158 1410
1159static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; 1411static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul;
1160 1412
1161void ecb_cold 1413void ecb_cold
1162ev_set_allocator (void *(*cb)(void *ptr, long size)) EV_THROW 1414ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW
1163{ 1415{
1164 alloc = cb; 1416 alloc = cb;
1165} 1417}
1166 1418
1167inline_speed void * 1419inline_speed void *
1816static void noinline ecb_cold 2068static void noinline ecb_cold
1817evpipe_init (EV_P) 2069evpipe_init (EV_P)
1818{ 2070{
1819 if (!ev_is_active (&pipe_w)) 2071 if (!ev_is_active (&pipe_w))
1820 { 2072 {
2073 int fds [2];
2074
1821# if EV_USE_EVENTFD 2075# if EV_USE_EVENTFD
2076 fds [0] = -1;
1822 evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); 2077 fds [1] = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC);
1823 if (evfd < 0 && errno == EINVAL) 2078 if (fds [1] < 0 && errno == EINVAL)
1824 evfd = eventfd (0, 0); 2079 fds [1] = eventfd (0, 0);
1825 2080
1826 if (evfd >= 0) 2081 if (fds [1] < 0)
1827 {
1828 evpipe [0] = -1;
1829 fd_intern (evfd); /* doing it twice doesn't hurt */
1830 ev_io_set (&pipe_w, evfd, EV_READ);
1831 }
1832 else
1833# endif 2082# endif
1834 { 2083 {
1835 while (pipe (evpipe)) 2084 while (pipe (fds))
1836 ev_syserr ("(libev) error creating signal/async pipe"); 2085 ev_syserr ("(libev) error creating signal/async pipe");
1837 2086
1838 fd_intern (evpipe [0]); 2087 fd_intern (fds [0]);
1839 fd_intern (evpipe [1]);
1840 ev_io_set (&pipe_w, evpipe [0], EV_READ);
1841 } 2088 }
1842 2089
2090 fd_intern (fds [1]);
2091
2092 evpipe [0] = fds [0];
2093
2094 if (evpipe [1] < 0)
2095 evpipe [1] = fds [1]; /* first call, set write fd */
2096 else
2097 {
2098 /* on subsequent calls, do not change evpipe [1] */
2099 /* so that evpipe_write can always rely on its value. */
2100 /* this branch does not do anything sensible on windows, */
2101 /* so must not be executed on windows */
2102
2103 dup2 (fds [1], evpipe [1]);
2104 close (fds [1]);
2105 }
2106
2107 ev_io_set (&pipe_w, evpipe [0] < 0 ? evpipe [1] : evpipe [0], EV_READ);
1843 ev_io_start (EV_A_ &pipe_w); 2108 ev_io_start (EV_A_ &pipe_w);
1844 ev_unref (EV_A); /* watcher should not keep loop alive */ 2109 ev_unref (EV_A); /* watcher should not keep loop alive */
1845 } 2110 }
1846} 2111}
1847 2112
1852 2117
1853 if (expect_true (*flag)) 2118 if (expect_true (*flag))
1854 return; 2119 return;
1855 2120
1856 *flag = 1; 2121 *flag = 1;
1857
1858 ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */ 2122 ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */
1859 2123
1860 pipe_write_skipped = 1; 2124 pipe_write_skipped = 1;
1861 2125
1862 ECB_MEMORY_FENCE; /* make sure pipe_write_skipped is visible before we check pipe_write_wanted */ 2126 ECB_MEMORY_FENCE; /* make sure pipe_write_skipped is visible before we check pipe_write_wanted */
1863 2127
1864 if (pipe_write_wanted) 2128 if (pipe_write_wanted)
1865 { 2129 {
1866 int old_errno; 2130 int old_errno;
1867 2131
1868 pipe_write_skipped = 0; /* just an optimisation, no fence needed */ 2132 pipe_write_skipped = 0;
2133 ECB_MEMORY_FENCE_RELEASE;
1869 2134
1870 old_errno = errno; /* save errno because write will clobber it */ 2135 old_errno = errno; /* save errno because write will clobber it */
1871 2136
1872#if EV_USE_EVENTFD 2137#if EV_USE_EVENTFD
1873 if (evfd >= 0) 2138 if (evpipe [0] < 0)
1874 { 2139 {
1875 uint64_t counter = 1; 2140 uint64_t counter = 1;
1876 write (evfd, &counter, sizeof (uint64_t)); 2141 write (evpipe [1], &counter, sizeof (uint64_t));
1877 } 2142 }
1878 else 2143 else
1879#endif 2144#endif
1880 { 2145 {
1881#ifdef _WIN32 2146#ifdef _WIN32
1901 int i; 2166 int i;
1902 2167
1903 if (revents & EV_READ) 2168 if (revents & EV_READ)
1904 { 2169 {
1905#if EV_USE_EVENTFD 2170#if EV_USE_EVENTFD
1906 if (evfd >= 0) 2171 if (evpipe [0] < 0)
1907 { 2172 {
1908 uint64_t counter; 2173 uint64_t counter;
1909 read (evfd, &counter, sizeof (uint64_t)); 2174 read (evpipe [1], &counter, sizeof (uint64_t));
1910 } 2175 }
1911 else 2176 else
1912#endif 2177#endif
1913 { 2178 {
1914 char dummy[4]; 2179 char dummy[4];
1915#ifdef _WIN32 2180#ifdef _WIN32
1916 WSABUF buf; 2181 WSABUF buf;
1917 DWORD recvd; 2182 DWORD recvd;
2183 DWORD flags = 0;
1918 buf.buf = dummy; 2184 buf.buf = dummy;
1919 buf.len = sizeof (dummy); 2185 buf.len = sizeof (dummy);
1920 WSARecv (EV_FD_TO_WIN32_HANDLE (evpipe [0]), &buf, 1, &recvd, 0, 0, 0); 2186 WSARecv (EV_FD_TO_WIN32_HANDLE (evpipe [0]), &buf, 1, &recvd, &flags, 0, 0);
1921#else 2187#else
1922 read (evpipe [0], &dummy, sizeof (dummy)); 2188 read (evpipe [0], &dummy, sizeof (dummy));
1923#endif 2189#endif
1924 } 2190 }
1925 } 2191 }
1931#if EV_SIGNAL_ENABLE 2197#if EV_SIGNAL_ENABLE
1932 if (sig_pending) 2198 if (sig_pending)
1933 { 2199 {
1934 sig_pending = 0; 2200 sig_pending = 0;
1935 2201
1936 ECB_MEMORY_FENCE_RELEASE; 2202 ECB_MEMORY_FENCE;
1937 2203
1938 for (i = EV_NSIG - 1; i--; ) 2204 for (i = EV_NSIG - 1; i--; )
1939 if (expect_false (signals [i].pending)) 2205 if (expect_false (signals [i].pending))
1940 ev_feed_signal_event (EV_A_ i + 1); 2206 ev_feed_signal_event (EV_A_ i + 1);
1941 } 2207 }
1944#if EV_ASYNC_ENABLE 2210#if EV_ASYNC_ENABLE
1945 if (async_pending) 2211 if (async_pending)
1946 { 2212 {
1947 async_pending = 0; 2213 async_pending = 0;
1948 2214
1949 ECB_MEMORY_FENCE_RELEASE; 2215 ECB_MEMORY_FENCE;
1950 2216
1951 for (i = asynccnt; i--; ) 2217 for (i = asynccnt; i--; )
1952 if (asyncs [i]->sent) 2218 if (asyncs [i]->sent)
1953 { 2219 {
1954 asyncs [i]->sent = 0; 2220 asyncs [i]->sent = 0;
2221 ECB_MEMORY_FENCE_RELEASE;
1955 ev_feed_event (EV_A_ asyncs [i], EV_ASYNC); 2222 ev_feed_event (EV_A_ asyncs [i], EV_ASYNC);
1956 } 2223 }
1957 } 2224 }
1958#endif 2225#endif
1959} 2226}
1962 2229
1963void 2230void
1964ev_feed_signal (int signum) EV_THROW 2231ev_feed_signal (int signum) EV_THROW
1965{ 2232{
1966#if EV_MULTIPLICITY 2233#if EV_MULTIPLICITY
2234 ECB_MEMORY_FENCE_ACQUIRE;
1967 EV_P = signals [signum - 1].loop; 2235 EV_P = signals [signum - 1].loop;
1968 2236
1969 if (!EV_A) 2237 if (!EV_A)
1970 return; 2238 return;
1971#endif 2239#endif
1972 2240
1973 if (!ev_active (&pipe_w))
1974 return;
1975
1976 signals [signum - 1].pending = 1; 2241 signals [signum - 1].pending = 1;
1977 evpipe_write (EV_A_ &sig_pending); 2242 evpipe_write (EV_A_ &sig_pending);
1978} 2243}
1979 2244
1980static void 2245static void
1990void noinline 2255void noinline
1991ev_feed_signal_event (EV_P_ int signum) EV_THROW 2256ev_feed_signal_event (EV_P_ int signum) EV_THROW
1992{ 2257{
1993 WL w; 2258 WL w;
1994 2259
1995 if (expect_false (signum <= 0 || signum > EV_NSIG)) 2260 if (expect_false (signum <= 0 || signum >= EV_NSIG))
1996 return; 2261 return;
1997 2262
1998 --signum; 2263 --signum;
1999 2264
2000#if EV_MULTIPLICITY 2265#if EV_MULTIPLICITY
2004 if (expect_false (signals [signum].loop != EV_A)) 2269 if (expect_false (signals [signum].loop != EV_A))
2005 return; 2270 return;
2006#endif 2271#endif
2007 2272
2008 signals [signum].pending = 0; 2273 signals [signum].pending = 0;
2274 ECB_MEMORY_FENCE_RELEASE;
2009 2275
2010 for (w = signals [signum].head; w; w = w->next) 2276 for (w = signals [signum].head; w; w = w->next)
2011 ev_feed_event (EV_A_ (W)w, EV_SIGNAL); 2277 ev_feed_event (EV_A_ (W)w, EV_SIGNAL);
2012} 2278}
2013 2279
2297#if EV_ASYNC_ENABLE 2563#if EV_ASYNC_ENABLE
2298 async_pending = 0; 2564 async_pending = 0;
2299#endif 2565#endif
2300 pipe_write_skipped = 0; 2566 pipe_write_skipped = 0;
2301 pipe_write_wanted = 0; 2567 pipe_write_wanted = 0;
2568 evpipe [0] = -1;
2569 evpipe [1] = -1;
2302#if EV_USE_INOTIFY 2570#if EV_USE_INOTIFY
2303 fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2; 2571 fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2;
2304#endif 2572#endif
2305#if EV_USE_SIGNALFD 2573#if EV_USE_SIGNALFD
2306 sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1; 2574 sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1;
2357 EV_INVOKE_PENDING; 2625 EV_INVOKE_PENDING;
2358 } 2626 }
2359#endif 2627#endif
2360 2628
2361#if EV_CHILD_ENABLE 2629#if EV_CHILD_ENABLE
2362 if (ev_is_active (&childev)) 2630 if (ev_is_default_loop (EV_A) && ev_is_active (&childev))
2363 { 2631 {
2364 ev_ref (EV_A); /* child watcher */ 2632 ev_ref (EV_A); /* child watcher */
2365 ev_signal_stop (EV_A_ &childev); 2633 ev_signal_stop (EV_A_ &childev);
2366 } 2634 }
2367#endif 2635#endif
2369 if (ev_is_active (&pipe_w)) 2637 if (ev_is_active (&pipe_w))
2370 { 2638 {
2371 /*ev_ref (EV_A);*/ 2639 /*ev_ref (EV_A);*/
2372 /*ev_io_stop (EV_A_ &pipe_w);*/ 2640 /*ev_io_stop (EV_A_ &pipe_w);*/
2373 2641
2374#if EV_USE_EVENTFD
2375 if (evfd >= 0)
2376 close (evfd);
2377#endif
2378
2379 if (evpipe [0] >= 0)
2380 {
2381 EV_WIN32_CLOSE_FD (evpipe [0]); 2642 if (evpipe [0] >= 0) EV_WIN32_CLOSE_FD (evpipe [0]);
2382 EV_WIN32_CLOSE_FD (evpipe [1]); 2643 if (evpipe [1] >= 0) EV_WIN32_CLOSE_FD (evpipe [1]);
2383 }
2384 } 2644 }
2385 2645
2386#if EV_USE_SIGNALFD 2646#if EV_USE_SIGNALFD
2387 if (ev_is_active (&sigfd_w)) 2647 if (ev_is_active (&sigfd_w))
2388 close (sigfd); 2648 close (sigfd);
2474#endif 2734#endif
2475#if EV_USE_INOTIFY 2735#if EV_USE_INOTIFY
2476 infy_fork (EV_A); 2736 infy_fork (EV_A);
2477#endif 2737#endif
2478 2738
2739#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
2479 if (ev_is_active (&pipe_w)) 2740 if (ev_is_active (&pipe_w))
2480 { 2741 {
2481 /* pipe_write_wanted must be false now, so modifying fd vars should be safe */ 2742 /* pipe_write_wanted must be false now, so modifying fd vars should be safe */
2482 2743
2483 ev_ref (EV_A); 2744 ev_ref (EV_A);
2484 ev_io_stop (EV_A_ &pipe_w); 2745 ev_io_stop (EV_A_ &pipe_w);
2485 2746
2486#if EV_USE_EVENTFD
2487 if (evfd >= 0)
2488 close (evfd);
2489#endif
2490
2491 if (evpipe [0] >= 0) 2747 if (evpipe [0] >= 0)
2492 {
2493 EV_WIN32_CLOSE_FD (evpipe [0]); 2748 EV_WIN32_CLOSE_FD (evpipe [0]);
2494 EV_WIN32_CLOSE_FD (evpipe [1]);
2495 }
2496 2749
2497#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
2498 evpipe_init (EV_A); 2750 evpipe_init (EV_A);
2499 /* now iterate over everything, in case we missed something */ 2751 /* iterate over everything, in case we missed something before */
2500 pipecb (EV_A_ &pipe_w, EV_READ); 2752 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM);
2501#endif
2502 } 2753 }
2754#endif
2503 2755
2504 postfork = 0; 2756 postfork = 0;
2505} 2757}
2506 2758
2507#if EV_MULTIPLICITY 2759#if EV_MULTIPLICITY
2562#if EV_FEATURE_API 2814#if EV_FEATURE_API
2563void ecb_cold 2815void ecb_cold
2564ev_verify (EV_P) EV_THROW 2816ev_verify (EV_P) EV_THROW
2565{ 2817{
2566#if EV_VERIFY 2818#if EV_VERIFY
2567 int i, j; 2819 int i;
2568 WL w, w2; 2820 WL w, w2;
2569 2821
2570 assert (activecnt >= -1); 2822 assert (activecnt >= -1);
2571 2823
2572 assert (fdchangemax >= fdchangecnt); 2824 assert (fdchangemax >= fdchangecnt);
2573 for (i = 0; i < fdchangecnt; ++i) 2825 for (i = 0; i < fdchangecnt; ++i)
2574 assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); 2826 assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0));
2575 2827
2576 assert (anfdmax >= 0); 2828 assert (anfdmax >= 0);
2577 for (i = j = 0; i < anfdmax; ++i) 2829 for (i = 0; i < anfdmax; ++i)
2830 {
2831 int j = 0;
2832
2578 for (w = w2 = anfds [i].head; w; w = w->next) 2833 for (w = w2 = anfds [i].head; w; w = w->next)
2579 { 2834 {
2580 verify_watcher (EV_A_ (W)w); 2835 verify_watcher (EV_A_ (W)w);
2581 2836
2582 if (++j & 1) 2837 if (j++ & 1)
2583 w2 = w2->next; 2838 {
2584
2585 assert (("libev: io watcher list contains a loop", w != w2)); 2839 assert (("libev: io watcher list contains a loop", w != w2));
2840 w2 = w2->next;
2841 }
2842
2586 assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); 2843 assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1));
2587 assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); 2844 assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i));
2588 } 2845 }
2846 }
2589 2847
2590 assert (timermax >= timercnt); 2848 assert (timermax >= timercnt);
2591 verify_heap (EV_A_ timers, timercnt); 2849 verify_heap (EV_A_ timers, timercnt);
2592 2850
2593#if EV_PERIODIC_ENABLE 2851#if EV_PERIODIC_ENABLE
2674} 2932}
2675 2933
2676void 2934void
2677ev_loop_fork (EV_P) EV_THROW 2935ev_loop_fork (EV_P) EV_THROW
2678{ 2936{
2679 postfork = 1; /* must be in line with ev_default_fork */ 2937 postfork = 1;
2680} 2938}
2681 2939
2682/*****************************************************************************/ 2940/*****************************************************************************/
2683 2941
2684void 2942void
2700} 2958}
2701 2959
2702void noinline 2960void noinline
2703ev_invoke_pending (EV_P) 2961ev_invoke_pending (EV_P)
2704{ 2962{
2705 for (pendingpri = NUMPRI; pendingpri--; ) /* pendingpri is modified during the loop */ 2963 pendingpri = NUMPRI;
2964
2965 while (pendingpri) /* pendingpri possibly gets modified in the inner loop */
2966 {
2967 --pendingpri;
2968
2706 while (pendingcnt [pendingpri]) 2969 while (pendingcnt [pendingpri])
2707 { 2970 {
2708 ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; 2971 ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri];
2709 2972
2710 p->w->pending = 0; 2973 p->w->pending = 0;
2711 EV_CB_INVOKE (p->w, p->events); 2974 EV_CB_INVOKE (p->w, p->events);
2712 EV_FREQUENT_CHECK; 2975 EV_FREQUENT_CHECK;
2713 } 2976 }
2977 }
2714} 2978}
2715 2979
2716#if EV_IDLE_ENABLE 2980#if EV_IDLE_ENABLE
2717/* make idle watchers pending. this handles the "call-idle */ 2981/* make idle watchers pending. this handles the "call-idle */
2718/* only when higher priorities are idle" logic */ 2982/* only when higher priorities are idle" logic */
2808{ 3072{
2809 EV_FREQUENT_CHECK; 3073 EV_FREQUENT_CHECK;
2810 3074
2811 while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) 3075 while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now)
2812 { 3076 {
2813 int feed_count = 0;
2814
2815 do 3077 do
2816 { 3078 {
2817 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); 3079 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]);
2818 3080
2819 /*assert (("libev: inactive timer on periodic heap detected", ev_is_active (w)));*/ 3081 /*assert (("libev: inactive timer on periodic heap detected", ev_is_active (w)));*/
3078 backend_poll (EV_A_ waittime); 3340 backend_poll (EV_A_ waittime);
3079 assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ 3341 assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */
3080 3342
3081 pipe_write_wanted = 0; /* just an optimisation, no fence needed */ 3343 pipe_write_wanted = 0; /* just an optimisation, no fence needed */
3082 3344
3345 ECB_MEMORY_FENCE_ACQUIRE;
3083 if (pipe_write_skipped) 3346 if (pipe_write_skipped)
3084 { 3347 {
3085 assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); 3348 assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w)));
3086 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); 3349 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM);
3087 } 3350 }
3465#if EV_MULTIPLICITY 3728#if EV_MULTIPLICITY
3466 assert (("libev: a signal must not be attached to two different loops", 3729 assert (("libev: a signal must not be attached to two different loops",
3467 !signals [w->signum - 1].loop || signals [w->signum - 1].loop == loop)); 3730 !signals [w->signum - 1].loop || signals [w->signum - 1].loop == loop));
3468 3731
3469 signals [w->signum - 1].loop = EV_A; 3732 signals [w->signum - 1].loop = EV_A;
3733 ECB_MEMORY_FENCE_RELEASE;
3470#endif 3734#endif
3471 3735
3472 EV_FREQUENT_CHECK; 3736 EV_FREQUENT_CHECK;
3473 3737
3474#if EV_USE_SIGNALFD 3738#if EV_USE_SIGNALFD
3629# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) 3893# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX)
3630 3894
3631static void noinline 3895static void noinline
3632infy_add (EV_P_ ev_stat *w) 3896infy_add (EV_P_ ev_stat *w)
3633{ 3897{
3634 w->wd = inotify_add_watch (fs_fd, w->path, IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY | IN_DONT_FOLLOW | IN_MASK_ADD); 3898 w->wd = inotify_add_watch (fs_fd, w->path,
3899 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY
3900 | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO
3901 | IN_DONT_FOLLOW | IN_MASK_ADD);
3635 3902
3636 if (w->wd >= 0) 3903 if (w->wd >= 0)
3637 { 3904 {
3638 struct statfs sfs; 3905 struct statfs sfs;
3639 3906
3643 3910
3644 if (!fs_2625) 3911 if (!fs_2625)
3645 w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL; 3912 w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL;
3646 else if (!statfs (w->path, &sfs) 3913 else if (!statfs (w->path, &sfs)
3647 && (sfs.f_type == 0x1373 /* devfs */ 3914 && (sfs.f_type == 0x1373 /* devfs */
3915 || sfs.f_type == 0x4006 /* fat */
3916 || sfs.f_type == 0x4d44 /* msdos */
3648 || sfs.f_type == 0xEF53 /* ext2/3 */ 3917 || sfs.f_type == 0xEF53 /* ext2/3 */
3918 || sfs.f_type == 0x72b6 /* jffs2 */
3919 || sfs.f_type == 0x858458f6 /* ramfs */
3920 || sfs.f_type == 0x5346544e /* ntfs */
3649 || sfs.f_type == 0x3153464a /* jfs */ 3921 || sfs.f_type == 0x3153464a /* jfs */
3922 || sfs.f_type == 0x9123683e /* btrfs */
3650 || sfs.f_type == 0x52654973 /* reiser3 */ 3923 || sfs.f_type == 0x52654973 /* reiser3 */
3651 || sfs.f_type == 0x01021994 /* tempfs */ 3924 || sfs.f_type == 0x01021994 /* tmpfs */
3652 || sfs.f_type == 0x58465342 /* xfs */)) 3925 || sfs.f_type == 0x58465342 /* xfs */))
3653 w->timer.repeat = 0.; /* filesystem is local, kernel new enough */ 3926 w->timer.repeat = 0.; /* filesystem is local, kernel new enough */
3654 else 3927 else
3655 w->timer.repeat = w->interval ? w->interval : NFS_STAT_INTERVAL; /* remote, use reduced frequency */ 3928 w->timer.repeat = w->interval ? w->interval : NFS_STAT_INTERVAL; /* remote, use reduced frequency */
3656 } 3929 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines