27 #if defined(__x86_64__) || defined (__i386__)
32 #define NDB_HAVE_READ_BARRIER_DEPENDS
34 #define NDB_HAVE_CPU_PAUSE
37 #define mb() asm volatile("mfence":::"memory")
40 #define rmb() asm volatile("" ::: "memory")
41 #define wmb() asm volatile("" ::: "memory")
42 #define read_barrier_depends() do {} while(0)
47 xcng(
volatile unsigned * addr,
int val)
49 asm volatile (
"xchg %0, %1;" :
"+r" (val) ,
"+m" (*addr));
58 asm volatile (
"rep;nop");
61 #elif defined(__sparc__)
66 #define NDB_HAVE_READ_BARRIER_DEPENDS
68 #define mb() asm volatile("membar #LoadLoad | #LoadStore | #StoreLoad | #StoreStore":::"memory")
69 #define rmb() asm volatile("membar #LoadLoad" ::: "memory")
70 #define wmb() asm volatile("membar #StoreStore" ::: "memory")
71 #define read_barrier_depends() do {} while(0)
77 #ifdef HAVE_ATOMIC_SWAP_32
80 xcng(
volatile unsigned * addr,
int val)
82 asm volatile(
"membar #StoreLoad | #LoadLoad");
83 int ret = atomic_swap_32(addr, val);
84 asm volatile(
"membar #StoreLoad | #StoreStore");
89 #define NDB_HAVE_CPU_PAUSE
92 extern int xcng(
volatile unsigned * addr,
int val);
93 extern void cpu_pause();
97 #define NDB_NO_ASM "Unsupported architecture (gcc)"
109 #if defined(__x86_64__)
113 #define NDB_HAVE_READ_BARRIER_DEPENDS
115 #define mb() asm ("mfence")
118 #define rmb() asm ("")
119 #define wmb() asm ("")
120 #define read_barrier_depends() do {} while(0)
122 #elif defined(__sparc)
126 #define NDB_HAVE_READ_BARRIER_DEPENDS
128 #define mb() asm ("membar #LoadLoad | #LoadStore | #StoreLoad | #StoreStore")
129 #define rmb() asm ("membar #LoadLoad")
130 #define wmb() asm ("membar #StoreStore")
131 #define read_barrier_depends() do {} while(0)
133 #define NDB_NO_ASM "Unsupported architecture (sun studio)"
136 #if defined(__x86_64__) || defined(__sparc)
145 #ifdef HAVE_ATOMIC_SWAP_32
146 #define NDB_HAVE_XCNG
147 #define NDB_HAVE_CPU_PAUSE
151 xcng(
volatile unsigned * addr,
int val)
153 asm (
"membar #StoreLoad | #LoadLoad");
154 int ret = atomic_swap_32(addr, val);
155 asm (
"membar #StoreLoad | #StoreStore");
159 #elif defined(__x86_64__)
162 xcng(
volatile unsigned * addr,
int val)
168 int ret = atomic_swap_32(addr, val);
176 asm volatile (
"rep;nop");
181 extern int xcng(
volatile unsigned * addr,
int val);
182 extern void cpu_pause();
185 #elif defined (_MSC_VER)
190 #define NDB_HAVE_READ_BARRIER_DEPENDS
193 #define mb() MemoryBarrier()
194 #define read_barrier_depends() do {} while(0)
196 #define rmb() do {} while(0)
197 #define wmb() do {} while(0)
204 #define rmb() _ReadBarrier()
205 #define wmb() _WriteBarrier()
208 #define NDB_HAVE_XCNG
209 #define NDB_HAVE_CPU_PAUSE
213 xcng(
volatile unsigned * addr,
int val)
215 return InterlockedExchange((
volatile LONG*)addr, val);
226 #define NDB_NO_ASM "Unsupported compiler"