27 namespace AtomicHelpers
29 template <
typename T>
struct DiffTypeHelper {
using Type = T; };
30 template <
typename T>
struct DiffTypeHelper<T*> {
using Type = std::ptrdiff_t; };
40 template <
typename Type>
43 using DiffType =
typename AtomicHelpers::DiffTypeHelper<Type>::Type;
57 #if __cpp_lib_atomic_is_always_lock_free
58 static_assert (std::atomic<Type>::is_always_lock_free,
59 "This class can only be used for lock-free types");
64 Type
get() const noexcept {
return value.load(); }
67 void set (Type newValue) noexcept {
value = newValue; }
70 Type
exchange (Type newValue) noexcept {
return value.exchange (newValue); }
98 return value.compare_exchange_strong (valueToCompare, newValue);
104 value = other.value.load();
119 Type
operator-= (DiffType amountToSubtract) noexcept {
return value -= amountToSubtract; }
132 void memoryBarrier() noexcept { atomic_thread_fence (std::memory_order_seq_cst); }
142 JUCE_DEPRECATED (Type compareAndSetValue (Type, Type) noexcept);
Type get() const noexcept
Type exchange(Type newValue) noexcept
Atomic(Type initialValue) noexcept
void set(Type newValue) noexcept
Atomic< Type > & operator=(const Atomic &other) noexcept
std::atomic< Type > value
bool compareAndSetBool(Type newValue, Type valueToCompare) noexcept
Type operator--() noexcept
Type operator-=(DiffType amountToSubtract) noexcept
Type operator+=(DiffType amountToAdd) noexcept
void memoryBarrier() noexcept
Type operator++() noexcept
Atomic(const Atomic &other) noexcept