14 #ifndef ATOMIC_PRV_BASIC_H_
15 #define ATOMIC_PRV_BASIC_H_
17 #ifndef USE_STD_ATOMIC
19 #define USE_STD_ATOMIC
22 #define USE_STD_ATOMIC
24 #if defined __GNUC__ && !defined __clang__
25 #if __GNUC__ >= 5 && __GNUC_MINOR__ >= 1
26 #define USE_STD_ATOMIC
33 template <
typename T,
class Enable =
void >
class atomic;
36 #include "atomic_prv_std.h"
39 #if defined __i386__ || defined __i486__ || defined __i586__ || defined __i686__\
40 || defined __x86_64__ || defined _M_IX86 || defined _M_X64
41 #include "atomic_prv_x86.h"
43 #if defined __ppc__ || defined __POWERPC__ || defined __powerpc__
44 #include "atomic_prv_ppc.h"
46 #error Unsupported processor
50 #include <type_traits>
59 operator T()
const noexcept { T x = m_var; readBarrier();
return x;}
61 writeBarrier(); m_var = t;
return *
this;
64 writeBarrier(); m_var = x.m_var;
return *
this;
66 T exchange(T newv) noexcept {
67 T old = atomicSwap(newv, &m_var);
70 bool compare_set_strong(T oldv, T newv) noexcept {
71 bool ret = atomicCompareAndSet(oldv, newv, &m_var);
85 operator T()
const noexcept {
88 if(atomicCompareAndSet(oldv, oldv, &m_var)) {
97 if(atomicCompareAndSet(oldv, t, &m_var))
106 T exchange(T newv) noexcept {
109 if(atomicCompareAndSet(oldv, newv, &m_var)) {
114 bool compare_set_strong(T oldv, T newv) noexcept {
115 bool ret = atomicCompareAndSet(oldv, newv, &m_var);
121 __declspec(align(8));
123 __attribute__((aligned(8)));
128 template <
typename T>
130 (sizeof(int_cas2) * 2 == sizeof(T)) && std::is_pod<T>::value>::type>
133 atomic() noexcept =
default;
139 template <
typename T>
141 (sizeof(int_cas_max) >= sizeof(T)) && std::is_pod<T>::value &&
142 !std::is_integral<T>::value>
::type>
145 atomic() noexcept =
default;
151 template <
typename T>
152 class atomic<T, typename std::enable_if<
153 (sizeof(int_cas_max) >= sizeof(T)) && std::is_integral<T>::value>
::type >
162 atomic &
operator--() noexcept {writeBarrier(); atomicDecAndTest( &this->m_var);
return *
this;}
164 atomic &
operator+=(T t) noexcept {writeBarrier(); atomicAdd( &this->m_var, t);
return *
this;}
166 atomic &
operator-=(T t) noexcept {writeBarrier(); atomicAdd( &this->m_var, -t);
return *
this;}
167 bool decAndTest() noexcept {
168 bool ret = atomicDecAndTest( &this->m_var);
171 bool addAndTest(T t) noexcept {
172 bool ret = atomicAddAndTest( &this->m_var, t);