40template <
typename Type>
43 using DiffType =
typename AtomicHelpers::DiffTypeHelper<Type>::Type;
57 #if __cpp_lib_atomic_is_always_lock_free
59 "This class can only be used for lock-free types");
67 void set (Type newValue)
noexcept {
value = newValue; }
132 void memoryBarrier() noexcept { atomic_thread_fence (std::memory_order_seq_cst); }
139 [[
deprecated (
"This method has been deprecated as there is no equivalent method in "
140 "std::atomic. Use compareAndSetBool instead.")]]
T compare_exchange_strong(T... args)
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
A simple wrapper around std::atomic.
Type get() const noexcept
Atomically reads and returns the current value.
Type exchange(Type newValue) noexcept
Atomically sets the current value, returning the value that was replaced.
Atomic(Type initialValue) noexcept
Creates a new value, with a given initial value.
void set(Type newValue) noexcept
Atomically sets the current value.
Atomic() noexcept
Creates a new value, initialised to zero.
std::atomic< Type > value
The std::atomic object that this class operates on.
bool compareAndSetBool(Type newValue, Type valueToCompare) noexcept
Atomically compares this value with a target value, and if it is equal, sets this to be equal to a ne...
Atomic< Type > & operator=(const Atomic &other) noexcept
Copies another value into this one (atomically).
Type operator--() noexcept
Atomically decrements this value, returning the new value.
Type operator-=(DiffType amountToSubtract) noexcept
Atomically subtracts a number from this value, returning the new value.
Type operator+=(DiffType amountToAdd) noexcept
Atomically adds a number to this value, returning the new value.
~Atomic() noexcept
Destructor.
void memoryBarrier() noexcept
Implements a memory read/write barrier.
Type operator++() noexcept
Atomically increments this value, returning the new value.
Atomic(const Atomic &other) noexcept
Copies another value (atomically).