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

Comparing libev/ev.c (file contents):
Revision 1.391 by root, Thu Aug 4 13:57:16 2011 UTC vs.
Revision 1.392 by root, Thu Aug 4 14:37:49 2011 UTC

552 #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ 552 #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */
553 #elif __amd64 553 #elif __amd64
554 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") 554 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
555 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") 555 #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 */ 556 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */
557 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__
558 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
559 #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \
560 || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) \
561 || defined(__ARM_ARCH_7__ ) || defined(__ARM_ARCH_7A__ ) \
562 || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ )
563 #define ECB_MEMORY_FENCE \
564 do { \
565 int null = 0; \
566 __asm__ __volatile__ ("mcr p15,0,%0,c6,c10,5", : "=&r" (null) : : "memory"); \
567 while (0)
557 #endif 568 #endif
558 #endif 569 #endif
559#endif 570#endif
560 571
561#ifndef ECB_MEMORY_FENCE 572#ifndef ECB_MEMORY_FENCE
562 #if ECB_GCC_VERSION(4,4) 573 #if ECB_GCC_VERSION(4,4) || defined(__INTEL_COMPILER)
563 #define ECB_MEMORY_FENCE __sync_synchronize () 574 #define ECB_MEMORY_FENCE __sync_synchronize ()
564 #define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) 575 /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */
565 #define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) 576 /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */
566 #elif _MSC_VER >= 1400 /* VC++ 2005 */ 577 #elif _MSC_VER >= 1400 /* VC++ 2005 */
567 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) 578 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier)
568 #define ECB_MEMORY_FENCE _ReadWriteBarrier () 579 #define ECB_MEMORY_FENCE _ReadWriteBarrier ()
569 #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ 580 #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */
570 #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () 581 #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier ()
571 #elif defined(_WIN32) 582 #elif defined(_WIN32)
572 #include <WinNT.h> 583 #include <WinNT.h>
573 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ 584 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */
574 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
575 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
576 #endif 585 #endif
577#endif 586#endif
578 587
579#ifndef ECB_MEMORY_FENCE 588#ifndef ECB_MEMORY_FENCE
589 #if !ECB_AVOID_PTHREADS
580 /* 590 /*
581 * if you get undefined symbol references to pthread_mutex_lock, 591 * if you get undefined symbol references to pthread_mutex_lock,
582 * or failure to find pthread.h, then you should implement 592 * or failure to find pthread.h, then you should implement
583 * the ECB_MEMORY_FENCE operations for your cpu/compiler 593 * the ECB_MEMORY_FENCE operations for your cpu/compiler
584 * OR provide pthread.h and link against the posix thread library 594 * OR provide pthread.h and link against the posix thread library
585 * of your system. 595 * of your system.
586 */ 596 */
587 #include <pthread.h> 597 #include <pthread.h>
588 #define ECB_NEEDS_PTHREADS 1 598 #define ECB_NEEDS_PTHREADS 1
589 #define ECB_MEMORY_FENCE_NEEDS_PTHREADS 1 599 #define ECB_MEMORY_FENCE_NEEDS_PTHREADS 1
590 600
591 static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; 601 static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER;
592 #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0) 602 #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0)
603 #endif
604#endif
605
606#if !defined(ECB_MEMORY_FENCE_ACQUIRE) && defined(ECB_MEMORY_FENCE)
593 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE 607 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
608#endif
609
610#if !defined(ECB_MEMORY_FENCE_RELEASE) && defined(ECB_MEMORY_FENCE)
594 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE 611 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
595#endif 612#endif
596 613
597/*****************************************************************************/ 614/*****************************************************************************/
598 615
845#endif 862#endif
846 863
847#endif 864#endif
848 865
849/* ECB.H END */ 866/* ECB.H END */
867
868#if ECB_MEMORY_FENCE_NEEDS_PTHREADS
869# undef ECB_MEMORY_FENCE
870# undef ECB_MEMORY_FENCE_ACQUIRE
871# undef ECB_MEMORY_FENCE_RELEASE
872#endif
850 873
851#define expect_false(cond) ecb_expect_false (cond) 874#define expect_false(cond) ecb_expect_false (cond)
852#define expect_true(cond) ecb_expect_true (cond) 875#define expect_true(cond) ecb_expect_true (cond)
853#define noinline ecb_noinline 876#define noinline ecb_noinline
854 877
1754 1777
1755 if (pipe_write_wanted) 1778 if (pipe_write_wanted)
1756 { 1779 {
1757 int old_errno; 1780 int old_errno;
1758 1781
1759 pipe_write_skipped = 0; /* just an optimsiation, no fence needed */ 1782 pipe_write_skipped = 0; /* just an optimisation, no fence needed */
1760 1783
1761 old_errno = errno; /* save errno because write will clobber it */ 1784 old_errno = errno; /* save errno because write will clobber it */
1762 1785
1763#if EV_USE_EVENTFD 1786#if EV_USE_EVENTFD
1764 if (evfd >= 0) 1787 if (evfd >= 0)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines