Thread safe atomic signals.
More...
|
| file | signal.hpp |
| | ion::{SignalSource, SignalToken} and algorithms
|
| |
|
| template<class T> |
| auto | ion::Wait (SignalToken< T > &token) noexcept -> T |
| | Wait until signal source changes and return current value.
|
| |
| template<class T, class Predicate> |
| auto | ion::Wait (SignalToken< T > &token, Predicate &&stop_waiting) noexcept -> T |
| | Wait with predicate.
|
| |
| template<class T> |
| auto | Wait (SignalToken< T > &token) noexcept -> T |
| | Wait until signal source changes and return current value.
|
| |
| template<class T, class Predicate> |
| auto | Wait (SignalToken< T > &token, Predicate &&stop_waiting) noexcept -> T |
| | Wait with predicate.
|
| |
|
| template<class T> |
| auto | ion::Wait (DifferenceTag, SignalToken< T > &token) noexcept -> T |
| | Wait until signal source changes and return difference (current - previous) value.
|
| |
| template<class T, class Predicate> |
| auto | ion::Wait (DifferenceTag, SignalToken< T > &token, Predicate &&stop_waiting) noexcept -> T |
| | Wait until signal source changes and return difference (current - previous) value.
|
| |
| template<class T> |
| auto | Wait (DifferenceTag, SignalToken< T > &token) noexcept -> T |
| | Wait until signal source changes and return difference (current - previous) value.
|
| |
| template<class T, class Predicate> |
| auto | Wait (DifferenceTag, SignalToken< T > &token, Predicate &&stop_waiting) noexcept -> T |
| | Wait until signal source changes and return difference (current - previous) value.
|
| |
|
Effects Load and compare each of the signals with previous value.
The first one to change will be recorded in the WaitAnyResult::index. Depending on the selected overload the result of WaitAnyResult::result is either the current, difference or the Status containing both previous and current value.
|
| template<class T1, class T2> |
| auto | ion::WaitAny (SignalToken< T1 > &token1, SignalToken< T2 > &token2) noexcept -> WaitAnyResult< T1, T2 > |
| | Wait for either of two signals to change.
|
| |
| template<class T1, class T2> |
| auto | ion::WaitAny (StatusTag, SignalToken< T1 > &token1, SignalToken< T2 > &token2) noexcept -> WaitAnyResult< Status< T1 >, Status< T2 > > |
| | Wait for either of two signals to change.
|
| |
| template<class T1, class T2> |
| auto | ion::WaitAny (DifferenceTag, SignalToken< T1 > &token1, SignalToken< T2 > &token2) noexcept -> WaitAnyResult< T1, T2 > |
| | Wait for either of two signals to change.
|
| |
| template<class T1, class T2> |
| auto | WaitAny (SignalToken< T1 > &token1, SignalToken< T2 > &token2) noexcept -> WaitAnyResult< T1, T2 > |
| | Wait for either of two signals to change.
|
| |
| template<class T1, class T2> |
| auto | WaitAny (StatusTag, SignalToken< T1 > &token1, SignalToken< T2 > &token2) noexcept -> WaitAnyResult< Status< T1 >, Status< T2 > > |
| | Wait for either of two signals to change.
|
| |
| template<class T1, class T2> |
| auto | WaitAny (DifferenceTag, SignalToken< T1 > &token1, SignalToken< T2 > &token2) noexcept -> WaitAnyResult< T1, T2 > |
| | Wait for either of two signals to change.
|
| |
Thread safe atomic signals.
#include <cstdint>
#include <thread>
int main() {
auto current = Wait(token);
std::cout << "Got signal: " << current << std::endl;
});
source.Store(42);
thread.join();
}
Atomic signal source.
Definition signal.hpp:66
Signal token that has an associated SignalSource and last known value.
Definition signal.hpp:187
ion::{SignalSource, SignalToken} and algorithms
◆ CompareExchangeTransform() [1/2]
template<class T, class UnaryOperation>
| auto CompareExchangeTransform |
( |
SignalSource< T > & | signal, |
|
|
UnaryOperation | op ) -> T |
|
related |
Performs atomic compare-exchange transformation of signal value.
- Note
- Provided transform operation
op will potentially be invoked any number of times - until underlying compare exchange operation is successful.
Example where S::second is reset to 0 without clobbering S::first - even if signal is modified from multiple threads.
struct S {
std::uint32_t first;
std::uint32_t second;
};
value.second = 0u;
return value;
});
}
auto CompareExchangeTransform(SignalSource< T > &signal, UnaryOperation op) noexcept -> T
Performs atomic compare-exchange transformation of signal value.
- Parameters
-
| signal | Signal to transform value on. |
| op | transform operation. |
- Returns
- Transformed value that was successfully stored in signal.
- Template Parameters
-
| UnaryOperation | Noexcept callable invocable as T callable(T const& t) noexcept, (which means T callable(T t) noexcept is also valid). |
◆ CompareExchangeTransform() [2/2]
template<class T, class UnaryOperation>
| auto CompareExchangeTransform |
( |
SignalSource< T > & | signal, |
|
|
UnaryOperation | op ) -> T |
|
related |
Performs atomic compare-exchange transformation of signal value.
- Note
- Provided transform operation
op will potentially be invoked any number of times - until underlying compare exchange operation is successful.
Example where S::second is reset to 0 without clobbering S::first - even if signal is modified from multiple threads.
struct S {
std::uint32_t first;
std::uint32_t second;
};
value.second = 0u;
return value;
});
}
- Parameters
-
| signal | Signal to transform value on. |
| op | transform operation. |
- Returns
- Transformed value that was successfully stored in signal.
- Template Parameters
-
| UnaryOperation | Noexcept callable invocable as T callable(T const& t) noexcept, (which means T callable(T t) noexcept is also valid). |
◆ operator!=() [1/2]
template<class T>
|
|
nodiscardconstexprnoexcept |
Inequality comparison.
- Parameters
-
| lhs | Left hand side of comparison. |
| rhs | RIght hand side of comparison. |
- Returns
- false if both
lhs and rhs are associated with the same signal source and have the same last value.
-
true otherwise.
- Template Parameters
-
| T | ValueType that must provide bool operator==(T const&, T const&) noexcept. |
◆ operator!=() [2/2]
Inequality comparison.
- Parameters
-
| lhs | Left hand side of comparison. |
| rhs | RIght hand side of comparison. |
- Returns
- false if both
lhs and rhs are associated with the same signal source and have the same last value.
-
true otherwise.
- Template Parameters
-
| T | ValueType that must provide bool operator==(T const&, T const&) noexcept. |
◆ operator==() [1/2]
template<class T>
|
|
nodiscardconstexprnoexcept |
Equality comparison.
- Parameters
-
| lhs | Left hand side of comparison. |
| rhs | RIght hand side of comparison. |
- Returns
- true if both
lhs and rhs are associated with the same signal source and have the same last value.
-
false otherwise.
- Template Parameters
-
| T | ValueType that must provide bool operator==(T const&, T const&) noexcept. |
◆ operator==() [2/2]
Equality comparison.
- Parameters
-
| lhs | Left hand side of comparison. |
| rhs | RIght hand side of comparison. |
- Returns
- true if both
lhs and rhs are associated with the same signal source and have the same last value.
-
false otherwise.
- Template Parameters
-
| T | ValueType that must provide bool operator==(T const&, T const&) noexcept. |
◆ Wait() [1/12]
Wait until signal source changes and return difference (current - previous) value.
- Note
- Requires that
T t2=t1-t0 is a valid expression where t0..t2 denotes an identifier of type T.
}
constexpr auto IsValid() const noexcept -> bool
auto Wait(SignalToken< T > &token) noexcept -> T
Wait until signal source changes and return current value.
constexpr DifferenceTag difference_tag
Constant instance of DifferenceTag.
Definition signal.hpp:384
- Precondition
token.IsValid() == true
- Parameters
-
- Returns
- Difference between current and previous signal value (current - previous).
◆ Wait() [2/12]
template<class T, class Predicate>
Wait until signal source changes and return difference (current - previous) value.
- Note
- Requires that
T t2=t1-t0 is a valid expression where t0..t2 denotes an identifier of type T.
- Precondition
token.IsValid() == true
- Parameters
-
| token | Signal token. |
| stop_waiting | Predicate invoked with each new signal value and should return true when to stop waiting. |
- Returns
- Difference between current and previous signal value (current - previous).
- Template Parameters
-
| Predicate | Callable invokable with signature bool(T). |
◆ Wait() [3/12]
Wait until signal source changes and return current value.
int current =
Wait(token);
}
- Precondition
token.IsValid() == true
- Parameters
-
- Returns
- New signal source value.
◆ Wait() [4/12]
template<class T, class Predicate>
| auto Wait |
( |
SignalToken< T > & | token, |
|
|
Predicate && | stop_waiting ) -> T |
|
related |
Wait with predicate.
Example using a predicate that waits until signal value is even.
int current =
Wait(token, [](
int value)
noexcept ->
bool {
return value % 2;
});
}
- Precondition
token.IsValid() == true
- Parameters
-
| token | Signal token. |
| stop_waiting | Predicate invoked with each new signal value and should return true when to stop waiting. |
- Returns
- New signal source value.
◆ Wait() [5/12]
Wait until signal source changes and return current and previous values.
}
constexpr StatusTag status_tag
Constant instance of StatusTag.
Definition signal.hpp:370
Represents signal source previous (old) and current (new) value.
Definition signal.hpp:329
- Precondition
token.IsValid() == true
- Parameters
-
- Returns
- Status containing current and previous values.
◆ Wait() [6/12]
template<class T, class Predicate>
Wait with predicate.
- Precondition
token.IsValid() == true
- Parameters
-
- Returns
- Status containing current and previous values.
- Parameters
-
| stop_waiting | Predicate invoked with each new signal value and should return true when to stop waiting. |
- Template Parameters
-
| Predicate | Callable invokable with signature bool(T). |
- See also
- Wait(StatusTag,SignalToken<T>&)
◆ Wait() [7/12]
Wait until signal source changes and return difference (current - previous) value.
- Note
- Requires that
T t2=t1-t0 is a valid expression where t0..t2 denotes an identifier of type T.
- Precondition
token.IsValid() == true
- Parameters
-
- Returns
- Difference between current and previous signal value (current - previous).
◆ Wait() [8/12]
template<class T, class Predicate>
Wait until signal source changes and return difference (current - previous) value.
- Note
- Requires that
T t2=t1-t0 is a valid expression where t0..t2 denotes an identifier of type T.
- Precondition
token.IsValid() == true
- Parameters
-
| token | Signal token. |
| stop_waiting | Predicate invoked with each new signal value and should return true when to stop waiting. |
- Returns
- Difference between current and previous signal value (current - previous).
- Template Parameters
-
| Predicate | Callable invokable with signature bool(T). |
◆ Wait() [9/12]
Wait until signal source changes and return current value.
int current =
Wait(token);
}
- Precondition
token.IsValid() == true
- Parameters
-
- Returns
- New signal source value.
◆ Wait() [10/12]
template<class T, class Predicate>
| auto Wait |
( |
SignalToken< T > & | token, |
|
|
Predicate && | stop_waiting ) -> T |
|
noexcept |
Wait with predicate.
Example using a predicate that waits until signal value is even.
int current =
Wait(token, [](
int value)
noexcept ->
bool {
return value % 2;
});
}
- Precondition
token.IsValid() == true
- Parameters
-
| token | Signal token. |
| stop_waiting | Predicate invoked with each new signal value and should return true when to stop waiting. |
- Returns
- New signal source value.
◆ Wait() [11/12]
Wait until signal source changes and return current and previous values.
- Precondition
token.IsValid() == true
- Parameters
-
- Returns
- Status containing current and previous values.
◆ Wait() [12/12]
template<class T, class Predicate>
Wait with predicate.
- Precondition
token.IsValid() == true
- Parameters
-
- Returns
- Status containing current and previous values.
- Parameters
-
| stop_waiting | Predicate invoked with each new signal value and should return true when to stop waiting. |
- Template Parameters
-
| Predicate | Callable invokable with signature bool(T). |
- See also
- Wait(StatusTag,SignalToken<T>&)
◆ WaitAny() [1/6]
template<class T1, class T2>
Wait for either of two signals to change.
- Precondition
token1.IsValid() && token2.IsValid()
- Parameters
-
| token1 | First signal token. |
| token2 | Second signal token. |
- Returns
- Wait result in which member
index specify which of the two signals has a new value. Member result contains the difference as "current value" - "previous value" of the signals.
◆ WaitAny() [2/6]
template<class T1, class T2>
Wait for either of two signals to change.
- Precondition
token1.IsValid() && token2.IsValid()
- Parameters
-
| token1 | First signal token. |
| token2 | Second signal token. |
- Returns
- Wait result in which member
index specify which of the two signals has a new value. Member result contains the current value of the signals.
◆ WaitAny() [3/6]
template<class T1, class T2>
Wait for either of two signals to change.
- Precondition
token1.IsValid() && token2.IsValid()
- Parameters
-
| token1 | First signal token. |
| token2 | Second signal token. |
- Returns
- Wait result in which member
index specify which of the two signals has a new value. Member result contains the current and previous value of the signals.
◆ WaitAny() [4/6]
template<class T1, class T2>
Wait for either of two signals to change.
- Precondition
token1.IsValid() && token2.IsValid()
- Parameters
-
| token1 | First signal token. |
| token2 | Second signal token. |
- Returns
- Wait result in which member
index specify which of the two signals has a new value. Member result contains the difference as "current value" - "previous value" of the signals.
◆ WaitAny() [5/6]
template<class T1, class T2>
Wait for either of two signals to change.
- Precondition
token1.IsValid() && token2.IsValid()
- Parameters
-
| token1 | First signal token. |
| token2 | Second signal token. |
- Returns
- Wait result in which member
index specify which of the two signals has a new value. Member result contains the current value of the signals.
◆ WaitAny() [6/6]
template<class T1, class T2>
Wait for either of two signals to change.
- Precondition
token1.IsValid() && token2.IsValid()
- Parameters
-
| token1 | First signal token. |
| token2 | Second signal token. |
- Returns
- Wait result in which member
index specify which of the two signals has a new value. Member result contains the current and previous value of the signals.