2 * mono-membar.h: Memory barrier inline functions
5 * Mark Probst (mark.probst@gmail.com)
10 #ifndef _MONO_UTILS_MONO_MEMBAR_H_
11 #define _MONO_UTILS_MONO_MEMBAR_H_
18 #ifndef WIN32_LEAN_AND_MEAN
19 #define WIN32_LEAN_AND_MEAN
24 static inline void mono_memory_barrier (void)
26 /* NOTE: _ReadWriteBarrier and friends only prevent the
27 compiler from reordering loads and stores. To prevent
28 the CPU from doing the same, we have to use the
29 MemoryBarrier macro which expands to e.g. a serializing
30 XCHG instruction on x86. Also note that the MemoryBarrier
31 macro does *not* imply _ReadWriteBarrier, so that call
32 cannot be eliminated. */
37 static inline void mono_memory_read_barrier (void)
43 static inline void mono_memory_write_barrier (void)
48 #elif defined(USE_GCC_ATOMIC_OPS)
49 static inline void mono_memory_barrier (void)
51 __sync_synchronize ();
54 static inline void mono_memory_read_barrier (void)
56 mono_memory_barrier ();
59 static inline void mono_memory_write_barrier (void)
61 mono_memory_barrier ();
64 #error "Don't know how to do memory barriers!"
67 #endif /* _MONO_UTILS_MONO_MEMBAR_H_ */