14#ifndef ALPAKA_DISABLE_ATOMIC_ATOMICREF
15# ifndef ALPAKA_HAS_STD_ATOMIC_REF
16# include <boost/atomic.hpp>
23# if defined(ALPAKA_HAS_STD_ATOMIC_REF)
46 "Type not supported by AtomicAtomicRef, please recompile defining "
47 "ALPAKA_DISABLE_ATOMIC_ATOMICREF.");
53 template<
typename T,
typename THierarchy>
54 struct AtomicOp<AtomicAdd, AtomicAtomicRef, T, THierarchy>
58 isSupportedByAtomicAtomicRef<T>();
60 return ref.fetch_add(value);
65 template<
typename T,
typename THierarchy>
66 struct AtomicOp<AtomicSub, AtomicAtomicRef, T, THierarchy>
70 isSupportedByAtomicAtomicRef<T>();
72 return ref.fetch_sub(value);
77 template<
typename T,
typename THierarchy>
78 struct AtomicOp<AtomicMin, AtomicAtomicRef, T, THierarchy>
82 isSupportedByAtomicAtomicRef<T>();
86 result = std::min(result, value);
87 while(!ref.compare_exchange_weak(old, result))
90 result = std::min(result, value);
97 template<
typename T,
typename THierarchy>
98 struct AtomicOp<AtomicMax, AtomicAtomicRef, T, THierarchy>
102 isSupportedByAtomicAtomicRef<T>();
106 result = std::max(result, value);
107 while(!ref.compare_exchange_weak(old, result))
110 result = std::max(result, value);
117 template<
typename T,
typename THierarchy>
118 struct AtomicOp<AtomicExch, AtomicAtomicRef, T, THierarchy>
122 isSupportedByAtomicAtomicRef<T>();
126 while(!ref.compare_exchange_weak(old, result))
135 template<
typename T,
typename THierarchy>
136 struct AtomicOp<AtomicInc, AtomicAtomicRef, T, THierarchy>
140 isSupportedByAtomicAtomicRef<T>();
143 T result = ((old >= value) ? 0 : static_cast<T>(old + 1));
144 while(!ref.compare_exchange_weak(old, result))
146 result = ((old >= value) ? 0 : static_cast<T>(old + 1));
153 template<
typename T,
typename THierarchy>
154 struct AtomicOp<AtomicDec, AtomicAtomicRef, T, THierarchy>
158 isSupportedByAtomicAtomicRef<T>();
161 T result = ((old >= value) ? 0 : static_cast<T>(old - 1));
162 while(!ref.compare_exchange_weak(old, result))
164 result = ((old >= value) ? 0 : static_cast<T>(old - 1));
171 template<
typename T,
typename THierarchy>
172 struct AtomicOp<AtomicAnd, AtomicAtomicRef, T, THierarchy>
176 isSupportedByAtomicAtomicRef<T>();
178 return ref.fetch_and(value);
183 template<
typename T,
typename THierarchy>
184 struct AtomicOp<AtomicOr, AtomicAtomicRef, T, THierarchy>
188 isSupportedByAtomicAtomicRef<T>();
190 return ref.fetch_or(value);
195 template<
typename T,
typename THierarchy>
196 struct AtomicOp<AtomicXor, AtomicAtomicRef, T, THierarchy>
200 isSupportedByAtomicAtomicRef<T>();
202 return ref.fetch_xor(value);
207 template<
typename T,
typename THierarchy>
208 struct AtomicOp<AtomicCas, AtomicAtomicRef, T, THierarchy>
211 AtomicAtomicRef
const&,
216 isSupportedByAtomicAtomicRef<T>();
222# if BOOST_COMP_GNUC || BOOST_COMP_CLANG
223# pragma GCC diagnostic push
224# pragma GCC diagnostic ignored "-Wfloat-equal"
226 result = ((old == compare) ? value : old);
227# if BOOST_COMP_GNUC || BOOST_COMP_CLANG
228# pragma GCC diagnostic pop
230 }
while(!ref.compare_exchange_weak(old, result));
The atomic ops based on atomic_ref for CPU accelerators.
boost::atomic_ref< T > atomic_ref
The alpaka accelerator library.
void isSupportedByAtomicAtomicRef()
ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_HOST_ACC auto atomicOp(TAtomic const &atomic, T *const addr, T const &value, THierarchy const &=THierarchy()) -> T
Executes the given operation atomically.