Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Notifiable.cxx
Go to the documentation of this file.
1
35
36#include "utils/macros.h"
37
40
45
48
53
54void CrashNotifiable::notify() { DIE("Called CrashNotifiable."); }
55
57 AtomicHolder h(this);
58 count_++;
59 return this;
60}
61
63 unsigned new_value;
64 {
65 AtomicHolder h(this);
66 HASSERT(count_ && "barrier notifyable received too many notifys");
67 new_value = --count_;
68 }
69 if (!new_value) {
71 done_->notify();
72 }
73}
74
75BarrierNotifiable::~BarrierNotifiable() { HASSERT(!count_); }
76
78 AtomicHolder h(this);
80 count_ = 1;
81 done_ = done;
82 return this;
83}
static CrashNotifiable default_crash_notifiable
Default instance of a crashing notifiable.
static EmptyNotifiable default_empty_notifiable
Default instance of an empty notifiable.
See OSMutexLock in os/OS.hxx.
Definition Atomic.hxx:153
A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish.
void notify() override
Implementation of the barrier semantics.
unsigned count_
How many outstanding notifications we are still waiting for.
Notifiable * done_
Notifiable to call when the barrier reaches zero.
BarrierNotifiable * reset(Notifiable *done)
Resets the barrier. Returns &*this. Asserts that is_done().
BarrierNotifiable * new_child()
Call this for each child task.
A Notifiable that will crash whenever called.
void notify() override
Crashes.
static Notifiable * DefaultInstance()
A Notifiable that doesn't do anything when notified.
static Notifiable * DefaultInstance()
An object that can schedule itself on an executor to run.
virtual void notify()=0
Generic callback.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
Definition macros.h:138
#define DIE(MSG)
Unconditionally terminates the current process with a message.
Definition macros.h:143