JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | List of all members
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.
 
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.
 

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.

@tags{Core}

Definition at line 41 of file juce_Atomic.h.

Member Typedef Documentation

◆ DiffType

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

Definition at line 43 of file juce_Atomic.h.

Constructor & Destructor Documentation

◆ Atomic() [1/3]

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

Creates a new value, initialised to zero.

Definition at line 46 of file juce_Atomic.h.

◆ Atomic() [2/3]

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

Creates a new value, with a given initial value.

Definition at line 49 of file juce_Atomic.h.

◆ Atomic() [3/3]

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

Copies another value (atomically).

Definition at line 52 of file juce_Atomic.h.

◆ ~Atomic()

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

Destructor.

Definition at line 55 of file juce_Atomic.h.

Member Function Documentation

◆ compareAndSetBool()

template<typename Type >
bool juce::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;
}
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88
Type get() const noexcept
Atomically reads and returns the current value.
Definition juce_Atomic.h:64
void set(Type newValue) noexcept
Atomically sets the current value.
Definition juce_Atomic.h:67
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:96

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 96 of file juce_Atomic.h.

◆ exchange()

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

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

Definition at line 70 of file juce_Atomic.h.

◆ get()

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

Atomically reads and returns the current value.

Definition at line 64 of file juce_Atomic.h.

◆ memoryBarrier()

template<typename Type >
void juce::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).

Definition at line 132 of file juce_Atomic.h.

◆ operator++()

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

Atomically increments this value, returning the new value.

Definition at line 122 of file juce_Atomic.h.

◆ operator+=()

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

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

Definition at line 116 of file juce_Atomic.h.

◆ operator--()

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

Atomically decrements this value, returning the new value.

Definition at line 125 of file juce_Atomic.h.

◆ operator-=()

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

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

Definition at line 119 of file juce_Atomic.h.

◆ operator=() [1/2]

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

Copies another value into this one (atomically).

Definition at line 102 of file juce_Atomic.h.

◆ operator=() [2/2]

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

Copies another value into this one (atomically).

Definition at line 109 of file juce_Atomic.h.

◆ set()

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

Atomically sets the current value.

Definition at line 67 of file juce_Atomic.h.

Member Data Documentation

◆ value

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

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

Definition at line 135 of file juce_Atomic.h.


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