3 * Memory barrier inline functions
6 * Mark Probst (mark.probst@gmail.com)
11 #ifndef _MONO_UTILS_MONO_MEMBAR_H_
12 #define _MONO_UTILS_MONO_MEMBAR_H_
19 #ifndef WIN32_LEAN_AND_MEAN
20 #define WIN32_LEAN_AND_MEAN
25 static inline void mono_memory_barrier (void)
27 /* NOTE: _ReadWriteBarrier and friends only prevent the
28 compiler from reordering loads and stores. To prevent
29 the CPU from doing the same, we have to use the
30 MemoryBarrier macro which expands to e.g. a serializing
31 XCHG instruction on x86. Also note that the MemoryBarrier
32 macro does *not* imply _ReadWriteBarrier, so that call
33 cannot be eliminated. */
38 static inline void mono_memory_read_barrier (void)
44 static inline void mono_memory_write_barrier (void)
49 #elif defined(USE_GCC_ATOMIC_OPS)
50 static inline void mono_memory_barrier (void)
52 __sync_synchronize ();
55 static inline void mono_memory_read_barrier (void)
57 mono_memory_barrier ();
60 static inline void mono_memory_write_barrier (void)
62 mono_memory_barrier ();
65 #error "Don't know how to do memory barriers!"
68 #endif /* _MONO_UTILS_MONO_MEMBAR_H_ */