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

Comparing libev/ev.c (file contents):
Revision 1.392 by root, Thu Aug 4 14:37:49 2011 UTC vs.
Revision 1.398 by root, Sun Sep 25 21:27:35 2011 UTC

537 537
538/* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ 538/* 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 */ 539/* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */
540 540
541#if ECB_NO_THREADS || ECB_NO_SMP 541#if ECB_NO_THREADS || ECB_NO_SMP
542 #define ECB_MEMORY_FENCE do { } while (0) 542 #define ECB_MEMORY_FENCE do { } while (0)
543 #define ECB_MEMORY_FENCE_ACQUIRE do { } while (0)
544 #define ECB_MEMORY_FENCE_RELEASE do { } while (0)
545#endif 543#endif
546 544
547#ifndef ECB_MEMORY_FENCE 545#ifndef ECB_MEMORY_FENCE
548 #if ECB_GCC_VERSION(2,5) 546 #if ECB_GCC_VERSION(2,5) || defined(__INTEL_COMPILER) || defined(__clang__)
549 #if __x86 547 #if __i386__
550 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") 548 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
551 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */ 549 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */
552 #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ 550 #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */
553 #elif __amd64 551 #elif __amd64
554 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") 552 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
555 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") 553 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory")
556 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */ 554 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */
557 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ 555 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__
558 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 556 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
559 #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \ 557 #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \
560 || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) \ 558 || 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")
561 || defined(__ARM_ARCH_7__ ) || defined(__ARM_ARCH_7A__ ) \ 560 #elif defined(__ARM_ARCH_7__ ) || defined(__ARM_ARCH_7A__ ) \
562 || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ ) 561 || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ )
563 #define ECB_MEMORY_FENCE \ 562 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory")
564 do { \
565 int null = 0; \
566 __asm__ __volatile__ ("mcr p15,0,%0,c6,c10,5", : "=&r" (null) : : "memory"); \
567 while (0)
568 #endif 563 #endif
569 #endif 564 #endif
570#endif 565#endif
571 566
572#ifndef ECB_MEMORY_FENCE 567#ifndef ECB_MEMORY_FENCE
573 #if ECB_GCC_VERSION(4,4) || defined(__INTEL_COMPILER) 568 #if ECB_GCC_VERSION(4,4) || defined(__INTEL_COMPILER) || defined(__clang__)
574 #define ECB_MEMORY_FENCE __sync_synchronize () 569 #define ECB_MEMORY_FENCE __sync_synchronize ()
575 /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */ 570 /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */
576 /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */ 571 /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */
577 #elif _MSC_VER >= 1400 /* VC++ 2005 */ 572 #elif _MSC_VER >= 1400 /* VC++ 2005 */
578 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) 573 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier)
848 #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) 843 #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0))
849#else 844#else
850 #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) 845 #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n)))
851#endif 846#endif
852 847
848#if __cplusplus
849 template<typename T>
850 static inline T ecb_div_rd (T val, T div)
851 {
852 return val < 0 ? - ((-val + div - 1) / div) : (val ) / div;
853 }
854 template<typename T>
855 static inline T ecb_div_ru (T val, T div)
856 {
857 return val < 0 ? - ((-val ) / div) : (val + div - 1) / div;
858 }
859#else
860 #define ecb_div_rd(val,div) ((val) < 0 ? - ((-(val) + (div) - 1) / (div)) : ((val) ) / (div))
861 #define ecb_div_ru(val,div) ((val) < 0 ? - ((-(val) ) / (div)) : ((val) + (div) - 1) / (div))
862#endif
863
853#if ecb_cplusplus_does_not_suck 864#if ecb_cplusplus_does_not_suck
854 /* does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm) */ 865 /* does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm) */
855 template<typename T, int N> 866 template<typename T, int N>
856 static inline int ecb_array_length (const T (&arr)[N]) 867 static inline int ecb_array_length (const T (&arr)[N])
857 { 868 {
864#endif 875#endif
865 876
866/* ECB.H END */ 877/* ECB.H END */
867 878
868#if ECB_MEMORY_FENCE_NEEDS_PTHREADS 879#if ECB_MEMORY_FENCE_NEEDS_PTHREADS
880/* if your architecture doesn't need memory fences, e.g. because it is
881 * single-cpu/core, or if you use libev in a project that doesn't use libev
882 * from multiple threads, then you can define ECB_AVOID_PTHREADS when compiling
883 * libev, in which casess the memory fences become nops.
884 * alternatively, you can remove this #error and link against libpthread,
885 * which will then provide the memory fences.
886 */
887# error "memory fences not defined for your architecture, please report"
888#endif
889
869# undef ECB_MEMORY_FENCE 890#ifndef ECB_MEMORY_FENCE
870# undef ECB_MEMORY_FENCE_ACQUIRE 891# define ECB_MEMORY_FENCE do { } while (0)
871# undef ECB_MEMORY_FENCE_RELEASE 892# define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
893# define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
872#endif 894#endif
873 895
874#define expect_false(cond) ecb_expect_false (cond) 896#define expect_false(cond) ecb_expect_false (cond)
875#define expect_true(cond) ecb_expect_true (cond) 897#define expect_true(cond) ecb_expect_true (cond)
876#define noinline ecb_noinline 898#define noinline ecb_noinline

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines