JUCE
Public Types | Public Member Functions | Public Attributes | List of all members
Atomic< Type > Struct Template Referencefinal

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

Public Types

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

Public Member Functions

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

Detailed Description

template<typename Type>
struct Atomic< Type >

A simple wrapper around std::atomic.

Member Typedef Documentation

◆ DiffType

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

Constructor & Destructor Documentation

◆ Atomic() [1/3]

template<typename Type>
Atomic< Type >::Atomic ( )
noexcept

Creates a new value, initialised to zero.

◆ Atomic() [2/3]

template<typename Type>
Atomic< Type >::Atomic ( Type  initialValue)
noexcept

Creates a new value, with a given initial value.

◆ Atomic() [3/3]

template<typename Type>
Atomic< Type >::Atomic ( const Atomic< Type > &  other)
noexcept

Copies another value (atomically).

◆ ~Atomic()

template<typename Type>
Atomic< Type >::~Atomic ( )
noexcept

Destructor.

Member Function Documentation

◆ get()

template<typename Type>
Type Atomic< Type >::get ( ) const
noexcept

◆ set()

template<typename Type>
void Atomic< Type >::set ( Type  newValue)
noexcept

Atomically sets the current value.

◆ exchange()

template<typename Type>
Type Atomic< Type >::exchange ( Type  newValue)
noexcept

Atomically sets the current value, returning the value that was replaced.

◆ compareAndSetBool()

template<typename Type>
bool Atomic< Type >::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.

This operation is the atomic equivalent of doing this:

bool compareAndSetBool (Type newValue, Type valueToCompare)
{
if (get() == valueToCompare)
{
set (newValue);
return true;
}
return false;
}

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

Referenced by ThreadLocalValue< Type >::get().

◆ operator=() [1/2]

template<typename Type>
Atomic<Type>& Atomic< Type >::operator= ( const Atomic< Type > &  other)
noexcept

Copies another value into this one (atomically).

◆ operator=() [2/2]

template<typename Type>
Atomic<Type>& Atomic< Type >::operator= ( Type  newValue)
noexcept

Copies another value into this one (atomically).

◆ operator+=()

template<typename Type>
Type Atomic< Type >::operator+= ( DiffType  amountToAdd)
noexcept

Atomically adds a number to this value, returning the new value.

◆ operator-=()

template<typename Type>
Type Atomic< Type >::operator-= ( DiffType  amountToSubtract)
noexcept

Atomically subtracts a number from this value, returning the new value.

◆ operator++()

template<typename Type>
Type Atomic< Type >::operator++ ( )
noexcept

Atomically increments this value, returning the new value.

◆ operator--()

template<typename Type>
Type Atomic< Type >::operator-- ( )
noexcept

Atomically decrements this value, returning the new value.

◆ memoryBarrier()

template<typename Type>
void Atomic< Type >::memoryBarrier ( )
noexcept

Implements a memory read/write barrier.

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

Member Data Documentation

◆ value

template<typename Type>
std::atomic<Type> Atomic< Type >::value

The std::atomic object that this class operates on.

Referenced by Atomic< Thread::ThreadID >::operator=().


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