xentara-utils v2.1
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::lockFree::WaitableState< State > Class Template Reference

A simple state that can be waited for without locking. More...

#include <xentara/utils/lockFree/WaitableState.hpp>

+ Inheritance diagram for xentara::utils::lockFree::WaitableState< State >:

Public Types

using value_type = State
 The type used for the state.
 

Public Member Functions

Constructors
constexpr WaitableState () noexcept(std::is_nothrow_default_constructible_v< State >)=default
 Default constructor.
 
constexpr WaitableState (State initialState) noexcept
 Constructor that initializes the state to a specific value.
 
Wait operations
auto wait (State oldState, std::memory_order memoryOrder=std::memory_order::seq_cst) const noexcept -> State
 Waits until the state differs from a given state.
 
template<typename Rep , typename Period >
auto waitFor (State oldState, const std::chrono::duration< Rep, Period > &timeout, std::memory_order memoryOrder=std::memory_order::seq_cst) const noexcept -> State
 Waits until the state differs from a given state using a relative timeout.
 
template<typename Clock , typename Duration >
auto waitUntil (State oldState, const std::chrono::time_point< Clock, Duration > &timeoutTime, std::memory_order memoryOrder=std::memory_order::seq_cst) const noexcept -> State
 Waits until the state differs from a given state using an absolute timeout.
 
Value access
 operator State () const noexcept
 Conversion to a non-atomic state.
 
auto operator= (State desired) noexcept -> State
 
auto load (std::memory_order memoryOrder=std::memory_order::seq_cst) const noexcept -> State
 Gets the current state.
 
auto store (State desired, std::memory_order memoryOrder=std::memory_order::seq_cst) noexcept -> void
 Sets the current state.
 
auto store (State desired, NotifyOneTag tag, std::memory_order memoryOrder=std::memory_order::seq_cst) noexcept -> void
 Sets the current state.
 
auto exchange (State desired, std::memory_order memoryOrder=std::memory_order::seq_cst) noexcept -> State
 Exchanges the state with a new state.
 
auto exchange (State desired, NotifyOneTag tag, std::memory_order memoryOrder=std::memory_order::seq_cst) noexcept -> State
 Exchanges the state with a new state.
 
auto compareExchangeWeak (State &expected, State desired, std::memory_order memoryOrder=std::memory_order::seq_cst) noexcept -> bool
 Exchanges the current state with a new state if and only if it matches an expected value.
 
auto compareExchangeWeak (State &expected, State desired, NotifyOneTag tag, std::memory_order memoryOrder=std::memory_order::seq_cst) noexcept -> bool
 Exchanges the current state with a new state if and only if it matches an expected value.
 
auto compareExchangeWeak (State &expected, State desired, std::memory_order memoryOrderSuccess, std::memory_order memoryOrderFailure) noexcept -> bool
 Exchanges the current state with a new state if and only if it matches an expected value.
 
auto compareExchangeWeak (State &expected, State desired, NotifyOneTag tag, std::memory_order memoryOrderSuccess, std::memory_order memoryOrderFailure) noexcept -> bool
 Exchanges the current state with a new state if and only if it matches an expected value.
 
auto compareExchangeStrong (State &expected, State desired, std::memory_order memoryOrder=std::memory_order::seq_cst) noexcept -> bool
 Exchanges the current state with a new state if and only if it matches an expected value.
 
auto compareExchangeStrong (State &expected, State desired, NotifyOneTag tag, std::memory_order memoryOrder=std::memory_order::seq_cst) noexcept -> bool
 Exchanges the current state with a new state if and only if it matches an expected value.
 
auto compareExchangeStrong (State &expected, State desired, std::memory_order memoryOrderSuccess, std::memory_order memoryOrderFailure) noexcept -> bool
 Exchanges the current state with a new state if and only if it matches an expected value.
 
auto compareExchangeStrong (State &expected, State desired, NotifyOneTag tag, std::memory_order memoryOrderSuccess, std::memory_order memoryOrderFailure) noexcept -> bool
 Exchanges the current state with a new state if and only if it matches an expected value.
 
Special members for integral types
auto fetchAdd (State value, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Fetches the current state, and then adds a value to the state.
 
auto fetchAdd (State value, NotifyOneTag tag, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Fetches the current state, and then adds a value to the state.
 
auto fetchSubtract (State value, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Fetches the current state, and then subtracts a value from the state.
 
auto fetchSubtract (State value, NotifyOneTag tag, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Fetches the current state, and then subtracts a value from the state.
 
auto fetchAnd (State value, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Fetches the current state, and then performs a bitwise AND operation.
 
auto fetchAnd (State value, NotifyOneTag tag, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Fetches the current state, and then performs a bitwise AND operation.
 
auto fetchOr (State value, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Fetches the current state, and then performs a bitwise OR operation.
 
auto fetchOr (State value, NotifyOneTag tag, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Fetches the current state, and then performs a bitwise OR operation.
 
auto fetchXor (State value, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Fetches the current state, and then performs a bitwise XOR operation.
 
auto fetchXor (State value, NotifyOneTag tag, std::memory_order memoryOrder=std::memory_order_seq_cst) noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Fetches the current state, and then performs a bitwise XOR operation.
 
auto operator++ () noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Pre-Increment operator.
 
auto operator++ (int) noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Post-Increment operator.
 
auto operator-- () noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Pre-Increment operator.
 
auto operator-- (int) noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Post-Increment operator.
 
auto operator+= (State desired) noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Addition assignment operator.
 
auto operator-= (State desired) noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Subtraction assignment operator.
 
auto operator&= (State desired) noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Bitwise AND assignment operator.
 
auto operator|= (State desired) noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Bitwise OR assignment operator.
 
auto operator^= (State desired) noexcept -> State requires(std::is_integral_v< State > &&!std::is_same_v< State, bool >)
 Bitwise XOR assignment operator.
 

Detailed Description

template<typename State>
class xentara::utils::lockFree::WaitableState< State >

A simple state that can be waited for without locking.

This class can neither be moved nor copied.

Template Parameters
StateThe type of the state. Must be int, unsigned int, bool, or an enum with one of these types as underlying type. Enums use int as underlying type be default, so unless you explicitly specify a different type in your enum declaration, enums are suitable as State parameters.

Member Typedef Documentation

◆ value_type

template<typename State >
using xentara::utils::lockFree::WaitableState< State >::value_type = State

The type used for the state.

Constructor & Destructor Documentation

◆ WaitableState() [1/2]

template<typename State >
constexpr xentara::utils::lockFree::WaitableState< State >::WaitableState ( ) const
constexprdefaultnoexcept

Default constructor.

This constructor value-initializes the state. This is the same as initializing the atomit with the value State().

◆ WaitableState() [2/2]

template<typename State >
constexpr xentara::utils::lockFree::WaitableState< State >::WaitableState ( State  initialState)
constexprnoexcept

Constructor that initializes the state to a specific value.

Member Function Documentation

◆ compareExchangeStrong() [1/4]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::compareExchangeStrong ( State &  expected,
State  desired,
NotifyOneTag  tag,
std::memory_order  memoryOrder = std::memory_order::seq_cst 
) -> bool
noexcept

Exchanges the current state with a new state if and only if it matches an expected value.

If the state was stored and any threads are waiting, this function wakes up at least one of the threads.

Parameters
expectedThe expected state. If the current state does not match the expected state, then this variable is set to the current state.
desiredThe new state
tagAlways pass kNotifyOne as this parameter
memoryOrderThe memory order. See std::atomic::compare_exchange_weak for notes on the memory order.
Returns
Returns true if the state was stored, or false if the comparison with expected failed.

◆ compareExchangeStrong() [2/4]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::compareExchangeStrong ( State &  expected,
State  desired,
NotifyOneTag  tag,
std::memory_order  memoryOrderSuccess,
std::memory_order  memoryOrderFailure 
) -> bool
noexcept

Exchanges the current state with a new state if and only if it matches an expected value.

If the state was stored and any threads are waiting, this function wakes up at least one of the threads.

Parameters
expectedThe expected state. If the current state does not match the expected state, then this variable is set to the current state.
desiredThe new state
tagAlways pass kNotifyOne as this parameter
memoryOrderSuccessThe memory order to use on success to store the value. See std::atomic::compare_exchange_weak for notes on the memory order.
memoryOrderFailureThe memory order to use on failure to read the current value. See std::atomic::compare_exchange_weak for notes on the memory order.
Returns
Returns true if the state was stored, or false if the comparison with expected failed.

◆ compareExchangeStrong() [3/4]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::compareExchangeStrong ( State &  expected,
State  desired,
std::memory_order  memoryOrder = std::memory_order::seq_cst 
) -> bool
noexcept

Exchanges the current state with a new state if and only if it matches an expected value.

This function wakes up all waiting threads if the state was stored.

Parameters
expectedThe expected state. If the current state does not match the expected state, then this variable is set to the current state.
desiredThe new state
memoryOrderThe memory order. See std::atomic::compare_exchange_weak for notes on the memory order.
Returns
Returns true if the state was stored, or false if the comparison with expected failed.

◆ compareExchangeStrong() [4/4]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::compareExchangeStrong ( State &  expected,
State  desired,
std::memory_order  memoryOrderSuccess,
std::memory_order  memoryOrderFailure 
) -> bool
noexcept

Exchanges the current state with a new state if and only if it matches an expected value.

This function wakes up all waiting threads if the state was stored.

Parameters
expectedThe expected state. If the current state does not match the expected state, then this variable is set to the current state.
desiredThe new state
memoryOrderSuccessThe memory order to use on success to store the value. See std::atomic::compare_exchange_weak for notes on the memory order.
memoryOrderFailureThe memory order to use on failure to read the current value. See std::atomic::compare_exchange_weak for notes on the memory order.
Returns
Returns true if the state was stored, or false if the comparison with expected failed.

◆ compareExchangeWeak() [1/4]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::compareExchangeWeak ( State &  expected,
State  desired,
NotifyOneTag  tag,
std::memory_order  memoryOrder = std::memory_order::seq_cst 
) -> bool
noexcept

Exchanges the current state with a new state if and only if it matches an expected value.

If the state was stored and any threads are waiting, this function wakes up at least one of the threads.

Parameters
expectedThe expected state. If the current state does not match the expected state, then this variable is set to the current state.
desiredThe new state
tagAlways pass kNotifyOne as this parameter
memoryOrderThe memory order. See std::atomic::compare_exchange_weak for notes on the memory order.
Returns
Returns true if the state was stored, or false if the comparison with expected failed.

◆ compareExchangeWeak() [2/4]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::compareExchangeWeak ( State &  expected,
State  desired,
NotifyOneTag  tag,
std::memory_order  memoryOrderSuccess,
std::memory_order  memoryOrderFailure 
) -> bool
noexcept

Exchanges the current state with a new state if and only if it matches an expected value.

If the state was stored and any threads are waiting, this function wakes up at least one of the threads.

Parameters
expectedThe expected state. If the current state does not match the expected state, then this variable is set to the current state.
desiredThe new state
tagAlways pass kNotifyOne as this parameter
memoryOrderSuccessThe memory order to use on success to store the value. See std::atomic::compare_exchange_weak for notes on the memory order.
memoryOrderFailureThe memory order to use on failure to read the current value. See std::atomic::compare_exchange_weak for notes on the memory order.
Returns
Returns true if the state was stored, or false if the comparison with expected failed.

◆ compareExchangeWeak() [3/4]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::compareExchangeWeak ( State &  expected,
State  desired,
std::memory_order  memoryOrder = std::memory_order::seq_cst 
) -> bool
noexcept

Exchanges the current state with a new state if and only if it matches an expected value.

This function wakes up all waiting threads if the state was stored.

Parameters
expectedThe expected state. If the current state does not match the expected state, then this variable is set to the current state.
desiredThe new state
memoryOrderThe memory order. See std::atomic::compare_exchange_weak for notes on the memory order.
Returns
Returns true if the state was stored, or false if the comparison with expected failed.

◆ compareExchangeWeak() [4/4]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::compareExchangeWeak ( State &  expected,
State  desired,
std::memory_order  memoryOrderSuccess,
std::memory_order  memoryOrderFailure 
) -> bool
noexcept

Exchanges the current state with a new state if and only if it matches an expected value.

This function wakes up all waiting threads if the state was stored.

Parameters
expectedThe expected state. If the current state does not match the expected state, then this variable is set to the current state.
desiredThe new state
memoryOrderSuccessThe memory order to use on success to store the value. See std::atomic::compare_exchange_weak for notes on the memory order.
memoryOrderFailureThe memory order to use on failure to read the current value. See std::atomic::compare_exchange_weak for notes on the memory order.
Returns
Returns true if the state was stored, or false if the comparison with expected failed.

◆ exchange() [1/2]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::exchange ( State  desired,
NotifyOneTag  tag,
std::memory_order  memoryOrder = std::memory_order::seq_cst 
) -> State
noexcept

Exchanges the state with a new state.

If any threads are waiting, this function wakes up at least one of the threads.

Parameters
desiredThe new state
tagAlways pass kNotifyOne as this parameter
memoryOrderThe memory order
Returns
The old state.

◆ exchange() [2/2]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::exchange ( State  desired,
std::memory_order  memoryOrder = std::memory_order::seq_cst 
) -> State
noexcept

Exchanges the state with a new state.

This function wakes up all waiting threads.

Parameters
desiredThe new state
memoryOrderThe memory order
Returns
The old state.

◆ fetchAdd() [1/2]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::fetchAdd ( State  value,
NotifyOneTag  tag,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Fetches the current state, and then adds a value to the state.

Note
This member function is only available for int and unsigned int.
Parameters
valueThe value to add.
tagAlways pass kNotifyOne as this parameter
memoryOrderThe memory order
Returns
The old state, before the value has been added.

◆ fetchAdd() [2/2]

template<typename State >
requires (std::is_integral_v<State> && !std::is_same_v<State, bool>)
auto xentara::utils::lockFree::WaitableState< State >::fetchAdd ( State  value,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Fetches the current state, and then adds a value to the state.

Note
This member function is only available for int and unsigned int.
Parameters
valueThe value to add.
memoryOrderThe memory order
Returns
The old state, before the value has been added.

◆ fetchAnd() [1/2]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::fetchAnd ( State  value,
NotifyOneTag  tag,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Fetches the current state, and then performs a bitwise AND operation.

Note
This member function is only available for int and unsigned int.
Parameters
valueThe value to AND into the state.
tagAlways pass kNotifyOne as this parameter
memoryOrderThe memory order
Returns
The old state, before the bit operation has been performed.

◆ fetchAnd() [2/2]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::fetchAnd ( State  value,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Fetches the current state, and then performs a bitwise AND operation.

Note
This member function is only available for int and unsigned int.
Parameters
valueThe value to AND into the state.
memoryOrderThe memory order
Returns
The old state, before the bit operation has been performed.

◆ fetchOr() [1/2]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::fetchOr ( State  value,
NotifyOneTag  tag,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Fetches the current state, and then performs a bitwise OR operation.

Note
This member function is only available for int and unsigned int.
Parameters
valueThe value to OR into the state.
tagAlways pass kNotifyOne as this parameter
memoryOrderThe memory order
Returns
The old state, before the bit operation has been performed.

◆ fetchOr() [2/2]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::fetchOr ( State  value,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Fetches the current state, and then performs a bitwise OR operation.

Note
This member function is only available for int and unsigned int.
Parameters
valueThe value to OR into the state.
memoryOrderThe memory order
Returns
The old state, before the bit operation has been performed.

◆ fetchSubtract() [1/2]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::fetchSubtract ( State  value,
NotifyOneTag  tag,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Fetches the current state, and then subtracts a value from the state.

Note
This member function is only available for int and unsigned int.
Parameters
valueThe value to substract.
tagAlways pass kNotifyOne as this parameter
memoryOrderThe memory order
Returns
The old state, before the value has been substracted.

◆ fetchSubtract() [2/2]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::fetchSubtract ( State  value,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Fetches the current state, and then subtracts a value from the state.

Note
This member function is only available for int and unsigned int.
Parameters
valueThe value to substract.
memoryOrderThe memory order
Returns
The old state, before the value has been substracted.

◆ fetchXor() [1/2]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::fetchXor ( State  value,
NotifyOneTag  tag,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Fetches the current state, and then performs a bitwise XOR operation.

Note
This member function is only available for int and unsigned int.
Parameters
valueThe value to XOR into the state.
tagAlways pass kNotifyOne as this parameter
memoryOrderThe memory order
Returns
The old state, before the bit operation has been performed.

◆ fetchXor() [2/2]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::fetchXor ( State  value,
std::memory_order  memoryOrder = std::memory_order_seq_cst 
) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Fetches the current state, and then performs a bitwise XOR operation.

Note
This member function is only available for int and unsigned int.
Parameters
valueThe value to XOR into the state.
memoryOrderThe memory order
Returns
The old state, before the bit operation has been performed.

◆ load()

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::load ( std::memory_order  memoryOrder = std::memory_order::seq_cst) const -> State
noexcept

Gets the current state.

Parameters
memoryOrderThe memory order
Returns
The current state.

◆ operator State()

template<typename State >
xentara::utils::lockFree::WaitableState< State >::operator State ( ) const
noexcept

Conversion to a non-atomic state.

This operator get the current state using std::memory_order::seq_cst. It is equivalent to calling load().

Returns
The current state.

◆ operator&=()

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::operator&= ( State  desired) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Bitwise AND assignment operator.

This operator performs a bitwise AND operation on the current state using std::memory_order::seq_cst. It is equivalient to calling fetchAnd(), except that fetchAnd() returns the old value, and this operator returns the new value.

Note
This operator is only available for int and unsigned int.
Returns
The new value, after it has been modified.

◆ operator++() [1/2]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::operator++ ( ) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Pre-Increment operator.

This operator adds 1 to the current state using std::memory_order::seq_cst. It is equivalient to calling fetchAdd(1), except that fetchAdd() returns the old state, and this operator returns the new state.

Note
This operator is only available for int and unsigned int.
Returns
The new state, after it has been incremented.

◆ operator++() [2/2]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::operator++ ( int  ) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Post-Increment operator.

This operator adds 1 to the current state using std::memory_order::seq_cst. It is equivalient to calling fetchAdd(1).

Note
This operator is only available for int and unsigned int.
Returns
The old state, before it has been incremented.

◆ operator+=()

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::operator+= ( State  desired) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Addition assignment operator.

This operator adds a value to the current state using std::memory_order::seq_cst. It is equivalient to calling fetchAdd(), except that fetchAdd() returns the old value, and this operator returns the new value.

Note
This operator is only available for int and unsigned int.
Returns
The new value, after it has been modified.

◆ operator--() [1/2]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::operator-- ( ) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Pre-Increment operator.

This operator subtracts 1 from the current state using std::memory_order::seq_cst. It is equivalient to calling fetchSubtract(1), except that fetchSubtract() returns the old state, and this operator returns the new state.

Note
This operator is only available for int and unsigned int.
Returns
The new state, after it has been decremented.

◆ operator--() [2/2]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::operator-- ( int  ) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Post-Increment operator.

This operator subtracts 1 from the current state using std::memory_order::seq_cst. It is equivalient to calling fetchSubtract(1).

Note
This operator is only available for int and unsigned int.
Returns
The old state, before it has been decremented.

◆ operator-=()

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::operator-= ( State  desired) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Subtraction assignment operator.

This operator adds a value to the current state using std::memory_order::seq_cst. It is equivalient to calling fetchSubtract(), except that fetchSubtract() returns the old value, and this operator returns the new value.

Note
This operator is only available for int and unsigned int.
Returns
The new value, after it has been modified.

◆ operator=()

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::operator= ( State  desired) -> State
noexcept

Assignment operator

This operator sets the current state using std::memory_order::seq_cst and wakes up all waiting threads. It is equivalent to calling store().

Parameters
desiredThe new state
Returns
Returns the new state

◆ operator^=()

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::operator^= ( State  desired) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Bitwise XOR assignment operator.

This operator performs a bitwise XOR operation on the current state using std::memory_order::seq_cst. It is equivalient to calling fetchXor(), except that fetchXor() returns the old value, and this operator returns the new value.

Note
This operator is only available for int and unsigned int.
Returns
The new value, after it has been modified.

◆ operator|=()

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::operator|= ( State  desired) -> State requires(std::is_integral_v<State> && !std::is_same_v<State, bool>)
noexcept

Bitwise OR assignment operator.

This operator performs a bitwise OR operation on the current state using std::memory_order::seq_cst. It is equivalient to calling fetchOr(), except that fetchOr() returns the old value, and this operator returns the new value.

Note
This operator is only available for int and unsigned int.
Returns
The new value, after it has been modified.

◆ store() [1/2]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::store ( State  desired,
NotifyOneTag  tag,
std::memory_order  memoryOrder = std::memory_order::seq_cst 
) -> void
noexcept

Sets the current state.

If any threads are waiting, this function wakes up at least one of the threads.

Parameters
desiredThe new state
tagAlways pass kNotifyOne as this parameter
memoryOrderThe memory order

◆ store() [2/2]

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::store ( State  desired,
std::memory_order  memoryOrder = std::memory_order::seq_cst 
) -> void
noexcept

Sets the current state.

This function wakes up all waiting threads.

Parameters
desiredThe new state
memoryOrderThe memory order

◆ wait()

template<typename State >
auto xentara::utils::lockFree::WaitableState< State >::wait ( State  oldState,
std::memory_order  memoryOrder = std::memory_order::seq_cst 
) const -> State
noexcept

Waits until the state differs from a given state.

This function will wait until the state is no longer oldState.

Note
Due to the ABA problem, transient changes from oldValue to another value and back to might not cause the wait to terminate. If you need to guarantee that every change is registered, use a regular atomic in combination with a ConditionVariable object.
Parameters
oldStateThe old state. The wait will finish once the state differs from this state. If the state is already different from oldState when this function is called, then the function will return immediately.
memoryOrderThe memory order. Must be std::memory_order::relaxed, std::memory_order::consume, std::memory_order::acquire or std::memory_order::seq_cst.
Returns
Returns the new state

◆ waitFor()

template<typename State >
template<typename Rep , typename Period >
auto xentara::utils::lockFree::WaitableState< State >::waitFor ( State  oldState,
const std::chrono::duration< Rep, Period > &  timeout,
std::memory_order  memoryOrder = std::memory_order::seq_cst 
) const -> State
noexcept

Waits until the state differs from a given state using a relative timeout.

This function will wait until the state is no longer oldState, or until a certain amount of time has elapsed.

Note
Due to the ABA problem, transient changes from oldValue to another value and back to might not cause the wait to finish. If you need to guarantee that every change is registered, use a regular atomic in combination with a ConditionVariable object.
Parameters
oldStateThe old state. The wait will finish once the state differs from this state, or if a timeout occurs. If the state is already different from oldState when this function is called, then the function will return immediately.
timeoutThe timeout.
memoryOrderThe memory order. Must be std::memory_order::relaxed, std::memory_order::consume, std::memory_order::acquire or std::memory_order::seq_cst.
Returns
Returns the new state, or oldState on timeout.

◆ waitUntil()

template<typename State >
template<typename Clock , typename Duration >
auto xentara::utils::lockFree::WaitableState< State >::waitUntil ( State  oldState,
const std::chrono::time_point< Clock, Duration > &  timeoutTime,
std::memory_order  memoryOrder = std::memory_order::seq_cst 
) const -> State
noexcept

Waits until the state differs from a given state using an absolute timeout.

This function will wait until the state is no longer oldState, or until a certain timeout time has been reached.

Note
Due to the ABA problem, transient changes from oldValue to another value and back to might not cause the wait to finish. If you need to guarantee that every change is registered, use a regular atomic in combination with a ConditionVariable object.
Parameters
oldStateThe old state. The wait will finish once the state differs from this state, or if a timeout occurs. If the state is already different from oldState when this function is called, then the function will return immediately.
timeoutTimeThe timeout time.
memoryOrderThe memory order. Must be std::memory_order::relaxed, std::memory_order::consume, std::memory_order::acquire or std::memory_order::seq_cst.
Returns
Returns the new state, or oldState on timeout.