OpenShot Library | libopenshot-audio
0.2.0
|
31 namespace AtomicHelpers
33 template <
typename T>
struct DiffTypeHelper {
using Type = T; };
34 template <
typename T>
struct DiffTypeHelper<T*> {
using Type = std::ptrdiff_t; };
44 template <
typename Type>
47 using DiffType =
typename AtomicHelpers::DiffTypeHelper<Type>::Type;
61 #if __cpp_lib_atomic_is_always_lock_free
62 static_assert (std::atomic<Type>::is_always_lock_free,
63 "This class can only be used for lock-free types");
68 Type
get() const noexcept {
return value.load(); }
71 void set (Type newValue) noexcept {
value = newValue; }
74 Type
exchange (Type newValue) noexcept {
return value.exchange (newValue); }
102 return value.compare_exchange_strong (valueToCompare, newValue);
108 value = other.value.load();
123 Type
operator-= (DiffType amountToSubtract) noexcept {
return value -= amountToSubtract; }
136 void memoryBarrier() noexcept { atomic_thread_fence (std::memory_order_seq_cst); }
146 JUCE_DEPRECATED (Type compareAndSetValue (Type, Type) noexcept);
A simple wrapper around std::atomic.
Atomic(const Atomic &other) noexcept
Copies another value (atomically).
Type operator-=(DiffType amountToSubtract) noexcept
Atomically subtracts a number from this value, returning the new value.
Atomic< Type > & operator=(const Atomic &other) noexcept
Copies another value into this one (atomically).
Type get() const noexcept
Atomically reads and returns the current value.
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...
void set(Type newValue) noexcept
Atomically sets the current value.
~Atomic() noexcept
Destructor.
Type exchange(Type newValue) noexcept
Atomically sets the current value, returning the value that was replaced.
Type operator+=(DiffType amountToAdd) noexcept
Atomically adds a number to this value, returning the new value.
void memoryBarrier() noexcept
Implements a memory read/write barrier.
Type operator--() noexcept
Atomically decrements this value, returning the new value.
Atomic() noexcept
Creates a new value, initialised to zero.
Atomic(Type initialValue) noexcept
Creates a new value, with a given initial value.
std::atomic< Type > value
The std::atomic object that this class operates on.
Type operator++() noexcept
Atomically increments this value, returning the new value.