hpx::lcos::local::and_gate#
Defined in header hpx/modules/lcos_local.hpp.
See Public API for a list of names and headers that are part of the public HPX API.
-
namespace hpx
-
namespace lcos
-
namespace local#
-
struct and_gate : public hpx::lcos::local::base_and_gate<hpx::no_mutex>#
- #include <and_gate.hpp>
An AND-gate synchronization primitive that fires once all of its expected inputs have been received.
Note
This type is not thread-safe. It has to be protected from concurrent access by different threads by the code using instances of this type.
Public Functions
-
inline explicit and_gate(std::size_t const count = 0)#
Construct an and_gate from the number of participants to synchronize the control flow with.
- Parameters
count – The number of inputs that need to be received before the gate is triggered.
-
~and_gate() = default#
-
template<typename Lock, typename Ptr = std::nullptr_t>
inline hpx::future<void> get_future(Lock &l, Ptr generation_value = nullptr, error_code &ec = hpx::throws)# Get a future allowing to wait for the gate to fire.
- Template Parameters
Lock – Type of the lock object used by the caller to protect the gate.
Ptr – Type of the (optional) pointer used to receive the current generation value.
- Parameters
l – The lock object that is currently holding the gate’s associated (outer) lock.
generation_value – [out] Optional pointer to a variable that will receive the current generation value of the gate.
ec – Used to hold error information if the operation fails.
- Returns
A future that becomes ready once the gate has fired.
Get a shared future allowing to wait for the gate to fire.
- Template Parameters
Lock – Type of the lock object used by the caller to protect the gate.
Ptr – Type of the (optional) pointer used to receive the current generation value.
- Parameters
l – The lock object that is currently holding the gate’s associated (outer) lock.
generation_value – [out] Optional pointer to a variable that will receive the current generation value of the gate.
ec – Used to hold error information if the operation fails.
- Returns
A shared future that becomes ready once the gate has fired.
-
template<typename Lock, typename F = std::nullptr_t>
inline bool set(std::size_t which, Lock &l, F &&f = nullptr, error_code &ec = hpx::throws)# Set the data which has to go into the segment
which.- Template Parameters
Lock – Type of the lock object used by the caller to protect the gate.
F – Type of the (optional) callback function invoked once the gate is triggered.
- Parameters
which – The zero-based index of the segment (input) to set.
l – The lock object that is currently holding the gate’s associated (outer) lock.
f – Optional callback that is invoked, with
lheld, when this call causes the gate to fire.ec – Used to hold error information if the operation fails.
- Returns
trueif this call caused the gate to fire (i.e. all inputs have now been received),falseotherwise.
-
template<typename Lock>
inline void synchronize(std::size_t generation_value, Lock &l, char const *function_name = "and_gate::synchronize", error_code &ec = throws)# Wait for the generational counter to reach the requested stage.
- Template Parameters
Lock – Type of the lock object used by the caller to protect the gate.
- Parameters
generation_value – The generation the caller waits for the gate to reach.
l – The lock object that is currently holding the gate’s associated (outer) lock.
function_name – The name to be used for error reporting.
ec – Used to hold error information if the operation fails.
Private Types
-
using base_type = base_and_gate<hpx::no_mutex>#
-
inline explicit and_gate(std::size_t const count = 0)#
-
template<typename Mutex = hpx::spinlock>
struct base_and_gate# - #include <and_gate.hpp>
A gate that waits for a fixed number of participants to “arrive” before releasing all waiters (an AND-synchronization primitive).
The base_and_gate implements a synchronization construct similar to a countdown latch/barrier: it is initialized with a number of expected participants (“segments”). Each participant signals its arrival, and once all expected participants have arrived, futures obtained from get_future() become ready and callbacks passed to set() are invoked.
After firing, the gate can be reused for subsequent synchronization rounds. The generation is advanced explicitly with next_generation(). Callers can use the generation number to guard against stale/late notifications from a previous round.
Note
Not copyable, but movable. Moving invalidates the moved-from object’s generation (set to an invalid-generation sentinel).
Note
Typically used via hpx::lcos::local::and_gate rather than directly.
- Template Parameters
Mutex – The mutex type protecting internal state. Defaults to hpx::spinlock.
Public Functions
-
inline explicit base_and_gate(std::size_t const count = 0)#
Construct a base_and_gate from the number of participants to synchronize the control flow with.
- Parameters
count – The number of inputs that need to be received before the gate is triggered.
-
base_and_gate(base_and_gate const &rhs) = delete#
base_and_gate is not copyable nor is it copy-assignable.
-
base_and_gate &operator=(base_and_gate const &rhs) = delete#
-
inline base_and_gate(base_and_gate &&rhs) noexcept#
Move-construct a base_and_gate, leaving
rhsin a moved-from state.- Parameters
rhs – The base_and_gate to move from.
-
inline base_and_gate &operator=(base_and_gate &&rhs) noexcept#
Move-assign a base_and_gate, leaving
rhsin a moved-from state.- Parameters
rhs – The base_and_gate to move from.
- Returns
A reference to
*this.
-
~base_and_gate() = default#
-
template<typename Ptr = std::nullptr_t>
inline hpx::future<void> get_future(Ptr generation_value = nullptr, error_code &ec = hpx::throws)# Get a future allowing to wait for the gate to fire.
- Template Parameters
Ptr – Type of the (optional) pointer used to receive the current generation value.
- Parameters
generation_value – [out] Optional pointer to a variable that will receive the current generation value of the gate.
ec – Used to hold error information if the operation fails.
- Returns
A future that becomes ready once the gate has fired.
Get a shared future allowing to wait for the gate to fire.
- Template Parameters
Ptr – Type of the (optional) pointer used to receive the current generation value.
- Parameters
generation_value – [out] Optional pointer to a variable that will receive the current generation value of the gate.
ec – Used to hold error information if the operation fails.
- Returns
A shared future that becomes ready once the gate has fired.
-
template<typename F = std::nullptr_t>
inline bool set(std::size_t which, F &&f = nullptr, error_code &ec = throws)# Mark the segment
whichas received.- Template Parameters
F – Type of the (optional) callback function invoked once the gate is triggered.
- Parameters
which – The zero-based index of the segment (input) to set.
f – Optional callback that is invoked, with the outer lock held, when this call causes the gate to fire.
ec – Used to hold error information if the operation fails.
- Returns
trueif this call caused the gate to fire (i.e. all inputs have now been received),falseotherwise.
-
inline void synchronize(std::size_t generation_value, char const *function_name = "base_and_gate<>::synchronize", error_code &ec = throws)#
Wait for the generational counter to reach the requested stage.
- Parameters
generation_value – The generation the caller waits for the gate to reach.
function_name – The name to be used for error reporting.
ec – Used to hold error information if the operation fails.
-
template<typename Lock>
inline std::size_t next_generation(Lock &l, std::size_t const new_generation = static_cast<std::size_t>(-1), error_code &ec = throws)# Advance the generational counter of the gate, unblocking any waiters whose requested generation has now been reached.
- Template Parameters
Lock – Type of the lock object used by the caller to protect the gate; must already be locked when this overload is called.
- Parameters
l – The lock object that is currently holding the gate’s associated (outer) lock.
new_generation – The generation value the gate’s counter should be reset to before being advanced; if not given the gate is simply advanced to the next generation. The returned generation value is one beyond this value.
ec – Used to hold error information if the operation fails.
- Returns
The new generation value of the gate.
-
inline std::size_t next_generation(std::size_t new_generation = static_cast<std::size_t>(-1), error_code &ec = throws)#
Advance the generational counter of the gate, unblocking any waiters whose requested generation has now been reached.
- Parameters
new_generation – The generation value the gate’s counter should be reset to before being advanced; if not given the gate is simply advanced to the next generation. The returned generation value is one beyond this value.
ec – Used to hold error information if the operation fails.
- Returns
The new generation value of the gate.
-
template<typename Lock>
inline std::size_t generation(Lock &l) const noexcept# Query the current generation value of the gate.
- Template Parameters
Lock – Type of the lock object used by the caller to protect the gate; must already be locked when this overload is called.
- Parameters
l – The lock object that is currently holding the gate’s associated (outer) lock.
- Returns
The current generation value of the gate.
Protected Functions
-
template<typename OuterLock, typename Ptr = std::nullptr_t>
inline hpx::future<void> get_future(OuterLock &outer_lock, Ptr generation_value = nullptr, error_code &ec = hpx::throws)#
-
template<typename OuterLock, typename F>
inline bool set(std::size_t const which, OuterLock &outer_lock, F &&f, error_code &ec = throws)#
-
template<typename Lock>
inline void synchronize(std::size_t generation_value, Lock &l, char const *function_name = "base_and_gate<>::synchronize", error_code &ec = throws)#
Private Types
-
using condition_list_type = hpx::detail::intrusive_list<condition_list_entry>#
-
struct condition_list_entry : public conditional_cv#
Public Functions
-
condition_list_entry() = default#
-
condition_list_entry() = default#
-
struct manage_condition#
Public Functions
-
inline manage_condition(base_and_gate &gate, condition_list_entry &cond) noexcept#
-
manage_condition(manage_condition const&) = delete#
-
manage_condition(manage_condition&&) = delete#
-
manage_condition &operator=(manage_condition const&) = delete#
-
manage_condition &operator=(manage_condition&&) = delete#
-
inline ~manage_condition()#
-
inline manage_condition(base_and_gate &gate, condition_list_entry &cond) noexcept#
-
struct and_gate : public hpx::lcos::local::base_and_gate<hpx::no_mutex>#
-
namespace local#
-
namespace lcos