Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
AsyncNotifiableBlock.hxx
Go to the documentation of this file.
1
38#ifndef _EXECUTOR_ASYNCNOTIFIABLEBLOCK_HXX_
39#define _EXECUTOR_ASYNCNOTIFIABLEBLOCK_HXX_
40
41#include <memory>
42
44#include "utils/Queue.hxx"
45#include "utils/logging.h"
46
47#include "utils/Buffer.hxx"
48
53class AsyncNotifiableBlock : private Notifiable, public QAsync
54{
55private:
59 {
60 public:
68 void notify() override
69 {
70 AtomicHolder h(this);
71 if (count_ == 1)
72 {
73 LOG(VERBOSE, "block notifiable %p returned pool size %u",
74 (BarrierNotifiable *)this,
75 (unsigned)mainBufferPool->total_size());
76 auto *tgt = static_cast<AsyncNotifiableBlock *>(done_);
77 tgt->insert(this);
78 }
79 else
80 {
81 --count_;
82 }
83 }
84
87 {
88 HASSERT(count_ == 1);
89 }
90 };
91
92public:
95 AsyncNotifiableBlock(unsigned num_parallelism)
96 : count_(num_parallelism)
97 , barriers_(new QueuedBarrier[num_parallelism])
98 {
99 for (unsigned i = 0; i < num_parallelism; ++i)
100 {
101 barriers_[i].reset(this);
102 this->insert(&barriers_[i]);
103 }
104 }
105
108
115 {
116 QueuedBarrier *b = static_cast<QueuedBarrier *>(entry);
117 // We must be owning this entry.
118 HASSERT(barriers_.get() <= b);
119 HASSERT(b <= (barriers_.get() + count_));
120 b->check_one_count();
121 return b;
122 }
123
125 void notify() override
126 {
127 DIE("Should not receive this notification");
128 }
129
130private:
132 unsigned count_;
134 std::unique_ptr<QueuedBarrier[]> barriers_;
135
137};
138
139#endif // _EXECUTOR_ASYNCNOTIFIABLEBLOCK_HXX_
DynamicPool * mainBufferPool
main buffer pool instance
Definition Buffer.cxx:37
Notifiable class that can act as a BarrierNotifiable but also be enlisted in a queue.
void notify() override
Notification implementation.
void check_one_count()
Checks that there is exactly one count in here.
A block of BarrierNotifiable objects, with an asynchronous allocation call.
AsyncNotifiableBlock(unsigned num_parallelism)
Constructor.
BarrierNotifiable * initialize(QMember *entry)
Turns an allocated entry from the QAsync into a usable BarrierNotifiable.
void notify() override
Notification implementation – should never be called.
std::unique_ptr< QueuedBarrier[]> barriers_
The pointer to the block of barriernotifiables.
unsigned count_
How many barriers do we have.
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.
unsigned count_
How many outstanding notifications we are still waiting for.
Notifiable * done_
Notifiable to call when the barrier reaches zero.
An object that can schedule itself on an executor to run.
size_t total_size()
Definition Buffer.hxx:281
Asynchronous specialization of Q.
Definition Queue.hxx:254
void insert(QMember *item, unsigned index=0)
Add an item to the back of the queue.
Definition Queue.hxx:273
Essentially a "next" pointer container.
Definition QMember.hxx:42
#define LOG(level, message...)
Conditionally write a message to the logging output.
Definition logging.h:99
static const int VERBOSE
Loglevel that is usually not printed, reporting debugging information.
Definition logging.h:59
#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
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
Definition macros.h:171