[cert-sync]: Make the new store the default and add '--legacy' for the old one.
[mono-project.git] / mono / utils / mono-membar.h
blobb59ffff85f93b28573c3089420381f8eeef6b484
1 /*
2 * mono-membar.h: Memory barrier inline functions
4 * Author:
5 * Mark Probst (mark.probst@gmail.com)
7 * (C) 2007 Novell, Inc
8 */
10 #ifndef _MONO_UTILS_MONO_MEMBAR_H_
11 #define _MONO_UTILS_MONO_MEMBAR_H_
13 #include <config.h>
15 #include <glib.h>
17 #ifdef _MSC_VER
18 #ifndef WIN32_LEAN_AND_MEAN
19 #define WIN32_LEAN_AND_MEAN
20 #endif
21 #include <windows.h>
22 #include <intrin.h>
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. */
33 _ReadWriteBarrier ();
34 MemoryBarrier ();
37 static inline void mono_memory_read_barrier (void)
39 _ReadBarrier ();
40 MemoryBarrier ();
43 static inline void mono_memory_write_barrier (void)
45 _WriteBarrier ();
46 MemoryBarrier ();
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 ();
63 #else
64 #error "Don't know how to do memory barriers!"
65 #endif
67 #endif /* _MONO_UTILS_MONO_MEMBAR_H_ */