|
Open Model Railroad Network (OpenMRN)
|
A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish. More...
#include <Notifiable.hxx>
Public Member Functions | |
| BarrierNotifiable () | |
| Constructs a barrier notifiable that is done. | |
| BarrierNotifiable (Notifiable *done) | |
| Constructs a barrier notifiable that is live. | |
| BarrierNotifiable * | reset (Notifiable *done) |
| Resets the barrier. Returns &*this. Asserts that is_done(). | |
| BarrierNotifiable * | new_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. | |
| Notifiable * | done_ |
| Notifiable to call when the barrier reaches zero. | |
Additional Inherited Members | |
Protected Member Functions inherited from Atomic | |
| void | lock () |
| void | unlock () |
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.
|
inline |
Constructs a barrier notifiable that is done.
Users should call reset() later.
Definition at line 179 of file Notifiable.hxx.
|
inline |
Constructs a barrier notifiable that is live.
| done | will 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 | ( | ) |
Definition at line 75 of file Notifiable.cxx.
|
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.
Definition at line 228 of file Notifiable.hxx.
|
inline |
Definition at line 209 of file Notifiable.hxx.
|
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.
| BarrierNotifiable * BarrierNotifiable::new_child | ( | ) |
Call this for each child task.
Definition at line 56 of file Notifiable.cxx.
|
overridevirtual |
Implementation of the barrier semantics.
Implements Notifiable.
Reimplemented in AsyncNotifiableBlock::QueuedBarrier.
Definition at line 62 of file Notifiable.cxx.
| BarrierNotifiable * BarrierNotifiable::reset | ( | Notifiable * | done | ) |
Resets the barrier. Returns &*this. Asserts that is_done().
Definition at line 77 of file Notifiable.cxx.
|
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.
|
protected |
Notifiable to call when the barrier reaches zero.
Definition at line 248 of file Notifiable.hxx.