Go to the documentation of this file.
63 #if defined(__APPLE__)
66 # if (__STDC_VERSION__ < 201112L) || defined(__STDC_NO_ATOMICS__)
67 # include <libkern/OSAtomic.h>
72 # define PaUtil_FullMemoryBarrier() OSMemoryBarrier()
73 # define PaUtil_ReadMemoryBarrier() OSMemoryBarrier()
74 # define PaUtil_WriteMemoryBarrier() OSMemoryBarrier()
76 # include <stdatomic.h>
77 # define PaUtil_FullMemoryBarrier() atomic_thread_fence(memory_order_seq_cst)
78 # define PaUtil_ReadMemoryBarrier() atomic_thread_fence(memory_order_acquire)
79 # define PaUtil_WriteMemoryBarrier() atomic_thread_fence(memory_order_release)
81 #elif defined(__GNUC__)
83 # if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
84 # define PaUtil_FullMemoryBarrier() __sync_synchronize()
85 # define PaUtil_ReadMemoryBarrier() __sync_synchronize()
86 # define PaUtil_WriteMemoryBarrier() __sync_synchronize()
91 # elif defined( __ppc__ ) || defined( __powerpc__) || defined( __PPC__ )
92 # define PaUtil_FullMemoryBarrier() asm volatile("sync":::"memory")
93 # define PaUtil_ReadMemoryBarrier() asm volatile("sync":::"memory")
94 # define PaUtil_WriteMemoryBarrier() asm volatile("sync":::"memory")
95 # elif defined( __i386__ ) || defined( __i486__ ) || defined( __i586__ ) || \
96 defined( __i686__ ) || defined( __x86_64__ )
97 # define PaUtil_FullMemoryBarrier() asm volatile("mfence":::"memory")
98 # define PaUtil_ReadMemoryBarrier() asm volatile("lfence":::"memory")
99 # define PaUtil_WriteMemoryBarrier() asm volatile("sfence":::"memory")
101 # ifdef ALLOW_SMP_DANGERS
102 # warning Memory barriers not defined on this system or system unknown
103 # warning For SMP safety, you should fix this.
104 # define PaUtil_FullMemoryBarrier()
105 # define PaUtil_ReadMemoryBarrier()
106 # define PaUtil_WriteMemoryBarrier()
108 # error Memory barriers are not defined on this system. You can still compile by defining ALLOW_SMP_DANGERS, but SMP safety will not be guaranteed.
111 #elif (_MSC_VER >= 1400) && !defined(_WIN32_WCE)
113 # pragma intrinsic(_ReadWriteBarrier)
114 # pragma intrinsic(_ReadBarrier)
115 # pragma intrinsic(_WriteBarrier)
117 # define PaUtil_FullMemoryBarrier() _ReadWriteBarrier()
118 # define PaUtil_ReadMemoryBarrier() _ReadBarrier()
119 # define PaUtil_WriteMemoryBarrier() _WriteBarrier()
120 #elif defined(_WIN32_WCE)
121 # define PaUtil_FullMemoryBarrier()
122 # define PaUtil_ReadMemoryBarrier()
123 # define PaUtil_WriteMemoryBarrier()
124 #elif defined(_MSC_VER) || defined(__BORLANDC__)
125 # define PaUtil_FullMemoryBarrier() _asm { lock add [esp], 0 }
126 # define PaUtil_ReadMemoryBarrier() _asm { lock add [esp], 0 }
127 # define PaUtil_WriteMemoryBarrier() _asm { lock add [esp], 0 }
129 # ifdef ALLOW_SMP_DANGERS
130 # warning Memory barriers not defined on this system or system unknown
131 # warning For SMP safety, you should fix this.
132 # define PaUtil_FullMemoryBarrier()
133 # define PaUtil_ReadMemoryBarrier()
134 # define PaUtil_WriteMemoryBarrier()
136 # error Memory barriers are not defined on this system. You can still compile by defining ALLOW_SMP_DANGERS, but SMP safety will not be guaranteed.