10 #ifndef MI_BASE_ATOM_H
11 #define MI_BASE_ATOM_H
20 #if defined(MI_ARCH_X86) && defined(MI_COMPILER_MSC)
21 # define MI_ATOM32_X86MSC
23 # pragma intrinsic (_InterlockedExchangeAdd)
24 # pragma intrinsic (_InterlockedCompareExchange)
25 #elif defined(MI_ARCH_X86) && (defined(MI_COMPILER_GCC) || defined(MI_COMPILER_ICC))
26 # define MI_ATOM32_X86GCC
28 # define MI_ATOM32_GENERIC
85 #if defined(MI_ATOM32_GENERIC)
90 #if defined(MI_ATOM32_X86MSC)
96 return _InterlockedExchangeAdd(reinterpret_cast<volatile long *>(&m_atom),rhs) + rhs;
103 return _InterlockedExchangeAdd(
104 reinterpret_cast<volatile long *>(&m_atom), -static_cast<const Sint32>(rhs)) - rhs;
111 return _InterlockedExchangeAdd(reinterpret_cast<volatile long *>(&m_atom),1L) + 1L;
118 return _InterlockedExchangeAdd(reinterpret_cast<volatile long *>(&m_atom),-1L) - 1L;
125 return _InterlockedExchangeAdd(reinterpret_cast<volatile long *>(&m_atom),1L);
132 return _InterlockedExchangeAdd(reinterpret_cast<volatile long *>(&m_atom),-1L);
139 return _InterlockedExchange(reinterpret_cast<volatile long *>(&m_atom),rhs);
142 #elif defined(MI_ATOM32_X86GCC) // defined(MI_ATOM32_X86MSC)
151 "lock; xaddl %0,%1\n"
153 :
"=&r" (retval),
"+m" (m_atom)
168 "lock; xaddl %0,%1\n"
170 :
"=&r" (retval),
"+m" (m_atom)
184 "lock; xaddl %0,%1\n"
186 :
"=&r" (retval),
"+m" (m_atom)
200 "lock; xaddl %0,%1\n"
202 :
"=&r" (retval),
"+m" (m_atom)
216 "lock; xaddl %0,%1\n"
217 :
"=&r" (retval),
"+m" (m_atom)
231 "lock; xaddl %0,%1\n"
232 :
"=&r" (retval),
"+m" (m_atom)
247 "lock; cmpxchg %2,%1\n"
249 :
"=&a" (retval),
"+m" (m_atom)
256 #elif defined(MI_ATOM32_GENERIC) // defined(MI_ATOM32_X86GCC)
263 return m_atom += rhs;
271 return m_atom -= rhs;
316 #else // MI_ATOM32_GENERIC
317 #error One of MI_ATOM32_X86MSC, MI_ATOM32_X86GCC, or MI_ATOM32_GENERIC must be defined.
320 #undef MI_ATOM32_X86MSC
321 #undef MI_ATOM32_X86GCC
322 #undef MI_ATOM32_GENERIC
329 #endif // MI_BASE_ATOM_H