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_
21 static inline void mono_memory_barrier (void)
25 static inline void mono_memory_read_barrier (void)
29 static inline void mono_memory_write_barrier (void)
34 #ifndef WIN32_LEAN_AND_MEAN
35 #define WIN32_LEAN_AND_MEAN
40 static inline void mono_memory_barrier (void)
42 /* NOTE: _ReadWriteBarrier and friends only prevent the
43 compiler from reordering loads and stores. To prevent
44 the CPU from doing the same, we have to use the
45 MemoryBarrier macro which expands to e.g. a serializing
46 XCHG instruction on x86. Also note that the MemoryBarrier
47 macro does *not* imply _ReadWriteBarrier, so that call
48 cannot be eliminated. */
53 static inline void mono_memory_read_barrier (void)
59 static inline void mono_memory_write_barrier (void)
64 #elif defined(USE_GCC_ATOMIC_OPS)
65 static inline void mono_memory_barrier (void)
67 __sync_synchronize ();
70 static inline void mono_memory_read_barrier (void)
72 mono_memory_barrier ();
75 static inline void mono_memory_write_barrier (void)
77 mono_memory_barrier ();
80 #error "Don't know how to do memory barriers!"
83 #endif /* _MONO_UTILS_MONO_MEMBAR_H_ */