Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
BarrierNotifiable Class Reference

A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish. More...

#include <Notifiable.hxx>

Inheritance diagram for BarrierNotifiable:
Notifiable Atomic Destructable AsyncNotifiableBlock::QueuedBarrier

Public Member Functions

 BarrierNotifiable ()
 Constructs a barrier notifiable that is done.
 
 BarrierNotifiable (Notifiable *done)
 Constructs a barrier notifiable that is live.
 
BarrierNotifiablereset (Notifiable *done)
 Resets the barrier. Returns &*this. Asserts that is_done().
 
BarrierNotifiablenew_child ()
 Call this for each child task.
 
void maybe_done ()
 When there are no more child tasks to add, call maybe_done().
 
void notify () override
 Implementation of the barrier semantics.
 
bool is_done ()
 
bool abort_if_almost_done ()
 Checks if there is exactly one outstanding notification left in the barrier.
 

Protected Attributes

unsigned count_
 How many outstanding notifications we are still waiting for.
 
Notifiabledone_
 Notifiable to call when the barrier reaches zero.
 

Additional Inherited Members

- Protected Member Functions inherited from Atomic
void lock ()
 
void unlock ()
 

Detailed Description

A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish.

When the last one is finished, the parent done callback is called.

Definition at line 174 of file Notifiable.hxx.

Constructor & Destructor Documentation

◆ BarrierNotifiable() [1/2]

BarrierNotifiable::BarrierNotifiable ( )
inline

Constructs a barrier notifiable that is done.

Users should call reset() later.

Definition at line 179 of file Notifiable.hxx.

◆ BarrierNotifiable() [2/2]

BarrierNotifiable::BarrierNotifiable ( Notifiable done)
inline

Constructs a barrier notifiable that is live.

Parameters
donewill be called when the barrier reaches zero (all children are notified and the parent is notified).

Definition at line 185 of file Notifiable.hxx.

◆ ~BarrierNotifiable()

BarrierNotifiable::~BarrierNotifiable ( )

Definition at line 75 of file Notifiable.cxx.

Member Function Documentation

◆ abort_if_almost_done()

bool BarrierNotifiable::abort_if_almost_done ( )
inline

Checks if there is exactly one outstanding notification left in the barrier.

It is required that the caller be actually holding on to a child. Effectively this tests whether there were either no children created, or all were notified inline.

The use-case is that the owner of the barrier wants to figure out whether all children completed inline or not. If the children were completed inline, we may want to call the next phase immediately instead of yielding to the executor. For that the barrier must swallow the notification.

Returns
true, if there were exactly one outstanding notify pending, and in such case sets the barrier to done. Otherwise returns false and has no side-effect.

Definition at line 228 of file Notifiable.hxx.

◆ is_done()

bool BarrierNotifiable::is_done ( )
inline
Returns
true if the barrier condition is true, i.e., the owner has called maybe_done() and all children have called Done.

Definition at line 209 of file Notifiable.hxx.

◆ maybe_done()

void BarrierNotifiable::maybe_done ( )
inline

When there are no more child tasks to add, call maybe_done().

Then once all previously added child tasks are done, the parent callback will be called. If you haven't added any children, this will call the parent callback inline.

Definition at line 200 of file Notifiable.hxx.

◆ new_child()

BarrierNotifiable * BarrierNotifiable::new_child ( )

Call this for each child task.

Definition at line 56 of file Notifiable.cxx.

◆ notify()

void BarrierNotifiable::notify ( )
overridevirtual

Implementation of the barrier semantics.

Implements Notifiable.

Reimplemented in AsyncNotifiableBlock::QueuedBarrier.

Definition at line 62 of file Notifiable.cxx.

◆ reset()

BarrierNotifiable * BarrierNotifiable::reset ( Notifiable done)

Resets the barrier. Returns &*this. Asserts that is_done().

Definition at line 77 of file Notifiable.cxx.

Member Data Documentation

◆ count_

unsigned BarrierNotifiable::count_
protected

How many outstanding notifications we are still waiting for.

When 0, the barrier is not live; when reaches zero, done_ will be called.

Definition at line 246 of file Notifiable.hxx.

◆ done_

Notifiable* BarrierNotifiable::done_
protected

Notifiable to call when the barrier reaches zero.

Definition at line 248 of file Notifiable.hxx.


The documentation for this class was generated from the following files: