ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libecb/ecb.h
(Generate patch)

Comparing libecb/ecb.h (file contents):
Revision 1.90 by root, Tue May 29 14:09:49 2012 UTC vs.
Revision 1.95 by root, Tue May 29 21:06:01 2012 UTC

79 #else 79 #else
80 #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) 80 #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
81 #endif 81 #endif
82#endif 82#endif
83 83
84#define ECB_C (__STDC__+0) /* this assumes that __STDC__ is either empty or a number */
84#define ECB_C99 (__STDC_VERSION__ >= 199901L) 85#define ECB_C99 (__STDC_VERSION__ >= 199901L)
85#define ECB_C11 (__STDC_VERSION__ >= 201112L) 86#define ECB_C11 (__STDC_VERSION__ >= 201112L)
87#define ECB_CPP (__cplusplus+0)
88#define ECB_CPP98 (__cplusplus >= 199711L)
89#define ECB_CPP11 (__cplusplus >= 201103L)
86 90
87/*****************************************************************************/ 91/*****************************************************************************/
88 92
89/* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ 93/* ECB_NO_THREADS - ecb is not used by multiple threads, ever */
90/* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ 94/* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */
91 95
92#if ECB_NO_THREADS 96#if ECB_NO_THREADS
93# define ECB_NO_SMP 1 97 #define ECB_NO_SMP 1
94#endif 98#endif
95 99
96#if ECB_NO_THREADS || ECB_NO_SMP 100#if ECB_NO_SMP
97 #define ECB_MEMORY_FENCE do { } while (0) 101 #define ECB_MEMORY_FENCE do { } while (0)
98#endif
99
100#ifndef ECB_MEMORY_FENCE
101 #if ECB_C11 && !defined __STDC_NO_ATOMICS__
102 /* we assume that these memory fences work on all variables/all memory accesses, */
103 /* not just C11 atomics and atomic accesses */
104 #include <stdatomic.h>
105 #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_acq_rel)
106 #define ECB_MEMORY_FENCE_ACQUIRE atomic_thread_fence (memory_order_acquire)
107 #define ECB_MEMORY_FENCE_RELEASE atomic_thread_fence (memory_order_release)
108 #endif
109#endif 102#endif
110 103
111#ifndef ECB_MEMORY_FENCE 104#ifndef ECB_MEMORY_FENCE
112 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 105 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
113 #if __i386 || __i386__ 106 #if __i386 || __i386__
114 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") 107 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
115 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */ 108 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
116 #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ 109 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("")
117 #elif __amd64 || __amd64__ || __x86_64 || __x86_64__ 110 #elif __amd64 || __amd64__ || __x86_64 || __x86_64__
118 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") 111 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
119 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") 112 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
120 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */ 113 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("")
121 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ 114 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__
122 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 115 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
123 #elif defined __ARM_ARCH_6__ || defined __ARM_ARCH_6J__ \ 116 #elif defined __ARM_ARCH_6__ || defined __ARM_ARCH_6J__ \
124 || defined __ARM_ARCH_6K__ || defined __ARM_ARCH_6ZK__ 117 || defined __ARM_ARCH_6K__ || defined __ARM_ARCH_6ZK__
125 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory") 118 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory")
126 #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \ 119 #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \
127 || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__ 120 || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__
128 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") 121 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory")
129 #elif __sparc || __sparc__ 122 #elif __sparc || __sparc__
130 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad | " : : : "memory") 123 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad" : : : "memory")
131 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") 124 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory")
132 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") 125 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore")
133 #elif defined __s390__ || defined __s390x__ 126 #elif defined __s390__ || defined __s390x__
134 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") 127 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory")
135 #elif defined __mips__ 128 #elif defined __mips__
136 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 129 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
137 #elif defined __alpha__ 130 #elif defined __alpha__
138 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mb" : : : "memory") 131 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mb" : : : "memory")
132 #elif defined __hppa__
133 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("" : : : "memory")
134 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("")
135 #elif defined __ia64__
136 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mf" : : : "memory")
139 #endif 137 #endif
140 #endif 138 #endif
141#endif 139#endif
142 140
143#ifndef ECB_MEMORY_FENCE 141#ifndef ECB_MEMORY_FENCE
142 #if ECB_GCC_VERSION(4,7)
143 /* see comment below about the C11 memory model. in short - avoid */
144 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST)
145 #elif defined __clang && __has_feature (cxx_atomic)
146 /* see above */
147 #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST)
144 #if ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ 148 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__
145 #define ECB_MEMORY_FENCE __sync_synchronize () 149 #define ECB_MEMORY_FENCE __sync_synchronize ()
146 /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */
147 /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */
148 #elif _MSC_VER >= 1400 /* VC++ 2005 */ 150 #elif _MSC_VER >= 1400 /* VC++ 2005 */
149 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) 151 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier)
150 #define ECB_MEMORY_FENCE _ReadWriteBarrier () 152 #define ECB_MEMORY_FENCE _ReadWriteBarrier ()
151 #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ 153 #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */
152 #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () 154 #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier ()
162 #define ECB_MEMORY_FENCE __sync () 164 #define ECB_MEMORY_FENCE __sync ()
163 #endif 165 #endif
164#endif 166#endif
165 167
166#ifndef ECB_MEMORY_FENCE 168#ifndef ECB_MEMORY_FENCE
169 #if ECB_C11 && !defined __STDC_NO_ATOMICS__
170 /* we assume that these memory fences work on all variables/all memory accesses, */
171 /* not just C11 atomics and atomic accesses */
172 #include <stdatomic.h>
173 /* unfortunately, the C11 memory model seems to be very limited, and unable to express */
174 /* simple barrier semantics. That means we need to take out thor's hammer. */
175 #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst)
176 #endif
177#endif
178
179#ifndef ECB_MEMORY_FENCE
167 #if !ECB_AVOID_PTHREADS 180 #if !ECB_AVOID_PTHREADS
168 /* 181 /*
169 * if you get undefined symbol references to pthread_mutex_lock, 182 * if you get undefined symbol references to pthread_mutex_lock,
170 * or failure to find pthread.h, then you should implement 183 * or failure to find pthread.h, then you should implement
171 * the ECB_MEMORY_FENCE operations for your cpu/compiler 184 * the ECB_MEMORY_FENCE operations for your cpu/compiler

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines