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

Comparing libecb/ecb.h (file contents):
Revision 1.177 by root, Mon Nov 19 00:27:38 2018 UTC vs.
Revision 1.178 by root, Mon Jun 24 22:22:59 2019 UTC

40 40
41#ifndef ECB_H 41#ifndef ECB_H
42#define ECB_H 42#define ECB_H
43 43
44/* 16 bits major, 16 bits minor */ 44/* 16 bits major, 16 bits minor */
45#define ECB_VERSION 0x00010005 45#define ECB_VERSION 0x00010006
46 46
47#ifdef _WIN32 47#ifdef _WIN32
48 typedef signed char int8_t; 48 typedef signed char int8_t;
49 typedef unsigned char uint8_t; 49 typedef unsigned char uint8_t;
50 typedef signed short int16_t; 50 typedef signed short int16_t;
164 #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */ 164 #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */
165#endif 165#endif
166 166
167#ifndef ECB_MEMORY_FENCE 167#ifndef ECB_MEMORY_FENCE
168 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 168 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
169 #define ECB_MEMORY_FENCE_RELAXED __asm__ __volatile__ ("" : : : "memory")
169 #if __i386 || __i386__ 170 #if __i386 || __i386__
170 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") 171 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
171 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") 172 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
172 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") 173 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory")
173 #elif ECB_GCC_AMD64 174 #elif ECB_GCC_AMD64
223 #if ECB_GCC_VERSION(4,7) 224 #if ECB_GCC_VERSION(4,7)
224 /* see comment below (stdatomic.h) about the C11 memory model. */ 225 /* see comment below (stdatomic.h) about the C11 memory model. */
225 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) 226 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST)
226 #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE) 227 #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE)
227 #define ECB_MEMORY_FENCE_RELEASE __atomic_thread_fence (__ATOMIC_RELEASE) 228 #define ECB_MEMORY_FENCE_RELEASE __atomic_thread_fence (__ATOMIC_RELEASE)
229 #define ECB_MEMORY_FENCE_RELAXED __atomic_thread_fence (__ATOMIC_RELAXED)
228 230
229 #elif ECB_CLANG_EXTENSION(c_atomic) 231 #elif ECB_CLANG_EXTENSION(c_atomic)
230 /* see comment below (stdatomic.h) about the C11 memory model. */ 232 /* see comment below (stdatomic.h) about the C11 memory model. */
231 #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) 233 #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST)
232 #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE) 234 #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE)
233 #define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE) 235 #define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE)
236 #define ECB_MEMORY_FENCE_RELAXED __c11_atomic_thread_fence (__ATOMIC_RELAXED)
234 237
235 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ 238 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__
236 #define ECB_MEMORY_FENCE __sync_synchronize () 239 #define ECB_MEMORY_FENCE __sync_synchronize ()
237 #elif _MSC_VER >= 1500 /* VC++ 2008 */ 240 #elif _MSC_VER >= 1500 /* VC++ 2008 */
238 /* apparently, microsoft broke all the memory barrier stuff in Visual Studio 2008... */ 241 /* apparently, microsoft broke all the memory barrier stuff in Visual Studio 2008... */
248 #elif defined _WIN32 251 #elif defined _WIN32
249 #include <WinNT.h> 252 #include <WinNT.h>
250 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ 253 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */
251 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 254 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
252 #include <mbarrier.h> 255 #include <mbarrier.h>
253 #define ECB_MEMORY_FENCE __machine_rw_barrier () 256 #define ECB_MEMORY_FENCE __machine_rw_barrier ()
254 #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () 257 #define ECB_MEMORY_FENCE_ACQUIRE __machine_acq_barrier ()
255 #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () 258 #define ECB_MEMORY_FENCE_RELEASE __machine_rel_barrier ()
259 #define ECB_MEMORY_FENCE_RELAXED __compiler_barrier ()
256 #elif __xlC__ 260 #elif __xlC__
257 #define ECB_MEMORY_FENCE __sync () 261 #define ECB_MEMORY_FENCE __sync ()
258 #endif 262 #endif
259#endif 263#endif
260 264
261#ifndef ECB_MEMORY_FENCE 265#ifndef ECB_MEMORY_FENCE
262 #if ECB_C11 && !defined __STDC_NO_ATOMICS__ 266 #if ECB_C11 && !defined __STDC_NO_ATOMICS__
263 /* we assume that these memory fences work on all variables/all memory accesses, */ 267 /* we assume that these memory fences work on all variables/all memory accesses, */
264 /* not just C11 atomics and atomic accesses */ 268 /* not just C11 atomics and atomic accesses */
265 #include <stdatomic.h> 269 #include <stdatomic.h>
266 /* Unfortunately, neither gcc 4.7 nor clang 3.1 generate any instructions for */
267 /* any fence other than seq_cst, which isn't very efficient for us. */
268 /* Why that is, we don't know - either the C11 memory model is quite useless */
269 /* for most usages, or gcc and clang have a bug */
270 /* I *currently* lean towards the latter, and inefficiently implement */
271 /* all three of ecb's fences as a seq_cst fence */
272 /* Update, gcc-4.8 generates mfence for all c++ fences, but nothing */
273 /* for all __atomic_thread_fence's except seq_cst */
274 #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst) 270 #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst)
271 #define ECB_MEMORY_FENCE_ACQUIRE atomic_thread_fence (memory_order_acquire)
272 #define ECB_MEMORY_FENCE_RELEASE atomic_thread_fence (memory_order_release)
275 #endif 273 #endif
276#endif 274#endif
277 275
278#ifndef ECB_MEMORY_FENCE 276#ifndef ECB_MEMORY_FENCE
279 #if !ECB_AVOID_PTHREADS 277 #if !ECB_AVOID_PTHREADS
297 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE 295 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
298#endif 296#endif
299 297
300#if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE 298#if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE
301 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE 299 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
300#endif
301
302#if !defined ECB_MEMORY_FENCE_RELAXED && defined ECB_MEMORY_FENCE
303 #define ECB_MEMORY_FENCE_RELAXED ECB_MEMORY_FENCE /* very heavy-handed */
302#endif 304#endif
303 305
304/*****************************************************************************/ 306/*****************************************************************************/
305 307
306#if ECB_CPP 308#if ECB_CPP

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines