|
xentara-utils v2.1
The Xentara Utility Library
|
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. | |
A simple state that can be waited for without locking.
This class can neither be moved nor copied.
| State | The 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. |
| using xentara::utils::lockFree::WaitableState< State >::value_type = State |
The type used for the state.
|
constexprdefaultnoexcept |
Default constructor.
This constructor value-initializes the state. This is the same as initializing the atomit with the value State().
|
constexprnoexcept |
Constructor that initializes the state to a specific value.
|
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.
| expected | The expected state. If the current state does not match the expected state, then this variable is set to the current state. |
| desired | The new state |
| tag | Always pass kNotifyOne as this parameter |
| memoryOrder | The memory order. See std::atomic::compare_exchange_weak for notes on the memory order. |
|
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.
| expected | The expected state. If the current state does not match the expected state, then this variable is set to the current state. |
| desired | The new state |
| tag | Always pass kNotifyOne as this parameter |
| memoryOrderSuccess | The memory order to use on success to store the value. See std::atomic::compare_exchange_weak for notes on the memory order. |
| memoryOrderFailure | The memory order to use on failure to read the current value. See std::atomic::compare_exchange_weak for notes on the memory order. |
|
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.
| expected | The expected state. If the current state does not match the expected state, then this variable is set to the current state. |
| desired | The new state |
| memoryOrder | The memory order. See std::atomic::compare_exchange_weak for notes on the memory order. |
|
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.
| expected | The expected state. If the current state does not match the expected state, then this variable is set to the current state. |
| desired | The new state |
| memoryOrderSuccess | The memory order to use on success to store the value. See std::atomic::compare_exchange_weak for notes on the memory order. |
| memoryOrderFailure | The memory order to use on failure to read the current value. See std::atomic::compare_exchange_weak for notes on the memory order. |
|
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.
| expected | The expected state. If the current state does not match the expected state, then this variable is set to the current state. |
| desired | The new state |
| tag | Always pass kNotifyOne as this parameter |
| memoryOrder | The memory order. See std::atomic::compare_exchange_weak for notes on the memory order. |
|
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.
| expected | The expected state. If the current state does not match the expected state, then this variable is set to the current state. |
| desired | The new state |
| tag | Always pass kNotifyOne as this parameter |
| memoryOrderSuccess | The memory order to use on success to store the value. See std::atomic::compare_exchange_weak for notes on the memory order. |
| memoryOrderFailure | The memory order to use on failure to read the current value. See std::atomic::compare_exchange_weak for notes on the memory order. |
|
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.
| expected | The expected state. If the current state does not match the expected state, then this variable is set to the current state. |
| desired | The new state |
| memoryOrder | The memory order. See std::atomic::compare_exchange_weak for notes on the memory order. |
|
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.
| expected | The expected state. If the current state does not match the expected state, then this variable is set to the current state. |
| desired | The new state |
| memoryOrderSuccess | The memory order to use on success to store the value. See std::atomic::compare_exchange_weak for notes on the memory order. |
| memoryOrderFailure | The memory order to use on failure to read the current value. See std::atomic::compare_exchange_weak for notes on the memory order. |
|
noexcept |
Exchanges the state with a new state.
If any threads are waiting, this function wakes up at least one of the threads.
| desired | The new state |
| tag | Always pass kNotifyOne as this parameter |
| memoryOrder | The memory order |
|
noexcept |
Exchanges the state with a new state.
This function wakes up all waiting threads.
| desired | The new state |
| memoryOrder | The memory order |
|
noexcept |
Fetches the current state, and then adds a value to the state.
| value | The value to add. |
| tag | Always pass kNotifyOne as this parameter |
| memoryOrder | The memory order |
|
noexcept |
Fetches the current state, and then adds a value to the state.
| value | The value to add. |
| memoryOrder | The memory order |
|
noexcept |
Fetches the current state, and then performs a bitwise AND operation.
| value | The value to AND into the state. |
| tag | Always pass kNotifyOne as this parameter |
| memoryOrder | The memory order |
|
noexcept |
Fetches the current state, and then performs a bitwise AND operation.
| value | The value to AND into the state. |
| memoryOrder | The memory order |
|
noexcept |
Fetches the current state, and then performs a bitwise OR operation.
| value | The value to OR into the state. |
| tag | Always pass kNotifyOne as this parameter |
| memoryOrder | The memory order |
|
noexcept |
Fetches the current state, and then performs a bitwise OR operation.
| value | The value to OR into the state. |
| memoryOrder | The memory order |
|
noexcept |
Fetches the current state, and then subtracts a value from the state.
| value | The value to substract. |
| tag | Always pass kNotifyOne as this parameter |
| memoryOrder | The memory order |
|
noexcept |
Fetches the current state, and then subtracts a value from the state.
| value | The value to substract. |
| memoryOrder | The memory order |
|
noexcept |
Fetches the current state, and then performs a bitwise XOR operation.
| value | The value to XOR into the state. |
| tag | Always pass kNotifyOne as this parameter |
| memoryOrder | The memory order |
|
noexcept |
Fetches the current state, and then performs a bitwise XOR operation.
| value | The value to XOR into the state. |
| memoryOrder | The memory order |
|
noexcept |
Gets the current state.
| memoryOrder | The memory order |
|
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().
|
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.
|
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.
|
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).
|
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.
|
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.
|
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).
|
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.
|
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().
| desired | The new state |
|
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.
|
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.
|
noexcept |
Sets the current state.
If any threads are waiting, this function wakes up at least one of the threads.
| desired | The new state |
| tag | Always pass kNotifyOne as this parameter |
| memoryOrder | The memory order |
|
noexcept |
Sets the current state.
This function wakes up all waiting threads.
| desired | The new state |
| memoryOrder | The memory order |
|
noexcept |
Waits until the state differs from a given state.
This function will wait until the state is no longer oldState.
| oldState | The 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. |
| memoryOrder | The memory order. Must be std::memory_order::relaxed, std::memory_order::consume, std::memory_order::acquire or std::memory_order::seq_cst. |
|
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.
| oldState | The 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. |
| timeout | The timeout. |
| memoryOrder | The memory order. Must be std::memory_order::relaxed, std::memory_order::consume, std::memory_order::acquire or std::memory_order::seq_cst. |
|
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.
| oldState | The 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. |
| timeoutTime | The timeout time. |
| memoryOrder | The memory order. Must be std::memory_order::relaxed, std::memory_order::consume, std::memory_order::acquire or std::memory_order::seq_cst. |