OpenShot Library | OpenShotAudio  0.2.2
juce::Atomic< Type > Struct Template Referencefinal

A simple wrapper around std::atomic. More...

#include <juce_Atomic.h>

Public Types

using DiffType = typename AtomicHelpers::DiffTypeHelper< Type >::Type
 

Public Member Functions

 Atomic () noexcept
 Creates a new value, initialised to zero.
 
 Atomic (Type initialValue) noexcept
 Creates a new value, with a given initial value.
 
 Atomic (const Atomic &other) noexcept
 Copies another value (atomically).
 
 ~Atomic () noexcept
 Destructor.
 
Type get () const noexcept
 Atomically reads and returns the current value.
 
void set (Type newValue) noexcept
 Atomically sets the current value.
 
Type exchange (Type newValue) noexcept
 Atomically sets the current value, returning the value that was replaced.
 
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 new value. More...
 
Atomic< Type > & operator= (const Atomic &other) noexcept
 Copies another value into this one (atomically).
 
Atomic< Type > & operator= (Type newValue) noexcept
 Copies another value into this one (atomically).
 
Type operator+= (DiffType amountToAdd) noexcept
 Atomically adds a number to this value, returning the new value.
 
Type operator-= (DiffType amountToSubtract) noexcept
 Atomically subtracts a number from this value, returning the new value.
 
Type operator++ () noexcept
 Atomically increments this value, returning the new value.
 
Type operator-- () noexcept
 Atomically decrements this value, returning the new value.
 
void memoryBarrier () noexcept
 Implements a memory read/write barrier. More...
 

Public Attributes

std::atomic< Type > value
 The std::atomic object that this class operates on.
 

Detailed Description

template<typename Type>
struct juce::Atomic< Type >

A simple wrapper around std::atomic.

Definition at line 45 of file juce_Atomic.h.

Member Function Documentation

◆ compareAndSetBool()

template<typename Type >
bool juce::Atomic< Type >::compareAndSetBool ( Type  newValue,
Type  valueToCompare 
)
inlinenoexcept

Atomically compares this value with a target value, and if it is equal, sets this to be equal to a new value.

This operation is the atomic equivalent of doing this:

bool compareAndSetBool (Type newValue, Type valueToCompare)
{
if (get() == valueToCompare)
{
set (newValue);
return true;
}
return false;
}
Type get() const noexcept
Atomically reads and returns the current value.
Definition: juce_Atomic.h:68
void set(Type newValue) noexcept
Atomically sets the current value.
Definition: juce_Atomic.h:71
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...
Definition: juce_Atomic.h:100

Internally, this method calls std::atomic::compare_exchange_strong with memory_order_seq_cst (the strictest std::memory_order).

Returns
true if the comparison was true and the value was replaced; false if the comparison failed and the value was left unchanged.
See also
compareAndSetValue

Definition at line 100 of file juce_Atomic.h.

References juce::Atomic< Type >::value.

Referenced by juce::ThreadLocalValue< Type >::get(), and juce::AsyncUpdater::AsyncUpdaterMessage::messageCallback().

◆ memoryBarrier()

template<typename Type >
void juce::Atomic< Type >::memoryBarrier ( )
inlinenoexcept

Implements a memory read/write barrier.

Internally this calls std::atomic_thread_fence with memory_order_seq_cst (the strictest std::memory_order).

Definition at line 136 of file juce_Atomic.h.


The documentation for this struct was generated from the following file: