blob: c857bb65b3d7e1bac2ee1ac6b016dcdc1fc52829 [file] [log] [blame]
Alex Perrycb7da4b2019-08-28 19:35:56 -07001#include "aos/events/simulated_event_loop.h"
2
3#include <algorithm>
4#include <deque>
Austin Schuh5f1cc5c2019-12-01 18:01:11 -08005#include <string_view>
Alex Perrycb7da4b2019-08-28 19:35:56 -07006
7#include "absl/container/btree_map.h"
Austin Schuh898f4972020-01-11 17:21:25 -08008#include "aos/events/simulated_network_bridge.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -07009#include "aos/json_to_flatbuffer.h"
10#include "aos/util/phased_loop.h"
11
12namespace aos {
13
14// Container for both a message, and the context for it for simulation. This
15// makes tracking the timestamps associated with the data easy.
16struct SimulatedMessage {
Alex Perrycb7da4b2019-08-28 19:35:56 -070017 // Context for the data.
18 Context context;
19
20 // The data.
Brian Silvermana1652f32020-01-29 20:41:44 -080021 char *data(size_t buffer_size) {
22 return RoundChannelData(&actual_data[0], buffer_size);
23 }
Alex Perrycb7da4b2019-08-28 19:35:56 -070024
Brian Silvermana1652f32020-01-29 20:41:44 -080025 // Then the data, including padding on the end so we can align the buffer we
26 // actually return from data().
27 char actual_data[];
Alex Perrycb7da4b2019-08-28 19:35:56 -070028};
29
Austin Schuh7d87b672019-12-01 20:23:49 -080030class SimulatedEventLoop;
Alex Perrycb7da4b2019-08-28 19:35:56 -070031class SimulatedFetcher;
Austin Schuh39788ff2019-12-01 18:22:57 -080032class SimulatedChannel;
33
Austin Schuh7d87b672019-12-01 20:23:49 -080034class SimulatedWatcher : public WatcherState {
Austin Schuh39788ff2019-12-01 18:22:57 -080035 public:
Austin Schuh7d87b672019-12-01 20:23:49 -080036 SimulatedWatcher(
37 SimulatedEventLoop *simulated_event_loop, EventScheduler *scheduler,
Austin Schuhac0771c2020-01-07 18:36:30 -080038 NodeEventLoopFactory *node_event_loop_factory,
Austin Schuh7d87b672019-12-01 20:23:49 -080039 const Channel *channel,
40 std::function<void(const Context &context, const void *message)> fn);
Austin Schuh39788ff2019-12-01 18:22:57 -080041
Austin Schuh7d87b672019-12-01 20:23:49 -080042 ~SimulatedWatcher() override;
Austin Schuh39788ff2019-12-01 18:22:57 -080043
44 void Startup(EventLoop * /*event_loop*/) override {}
45
Austin Schuh7d87b672019-12-01 20:23:49 -080046 void Schedule(std::shared_ptr<SimulatedMessage> message);
47
48 void HandleEvent();
Austin Schuh39788ff2019-12-01 18:22:57 -080049
50 void SetSimulatedChannel(SimulatedChannel *channel) {
51 simulated_channel_ = channel;
52 }
53
54 private:
Austin Schuh7d87b672019-12-01 20:23:49 -080055 void DoSchedule(monotonic_clock::time_point event_time);
56
57 ::std::deque<std::shared_ptr<SimulatedMessage>> msgs_;
58
59 SimulatedEventLoop *simulated_event_loop_;
60 EventHandler<SimulatedWatcher> event_;
61 EventScheduler *scheduler_;
Austin Schuhac0771c2020-01-07 18:36:30 -080062 NodeEventLoopFactory *node_event_loop_factory_;
Austin Schuh7d87b672019-12-01 20:23:49 -080063 EventScheduler::Token token_;
Austin Schuh39788ff2019-12-01 18:22:57 -080064 SimulatedChannel *simulated_channel_ = nullptr;
65};
Alex Perrycb7da4b2019-08-28 19:35:56 -070066
67class SimulatedChannel {
68 public:
69 explicit SimulatedChannel(const Channel *channel, EventScheduler *scheduler)
Austin Schuh39788ff2019-12-01 18:22:57 -080070 : channel_(channel),
Alex Perrycb7da4b2019-08-28 19:35:56 -070071 scheduler_(scheduler),
72 next_queue_index_(ipc_lib::QueueIndex::Zero(channel->max_size())) {}
73
74 ~SimulatedChannel() { CHECK_EQ(0u, fetchers_.size()); }
75
76 // Makes a connected raw sender which calls Send below.
77 ::std::unique_ptr<RawSender> MakeRawSender(EventLoop *event_loop);
78
79 // Makes a connected raw fetcher.
Austin Schuh39788ff2019-12-01 18:22:57 -080080 ::std::unique_ptr<RawFetcher> MakeRawFetcher(EventLoop *event_loop);
Alex Perrycb7da4b2019-08-28 19:35:56 -070081
82 // Registers a watcher for the queue.
Austin Schuh7d87b672019-12-01 20:23:49 -080083 void MakeRawWatcher(SimulatedWatcher *watcher);
Austin Schuh39788ff2019-12-01 18:22:57 -080084
Austin Schuh7d87b672019-12-01 20:23:49 -080085 void RemoveWatcher(SimulatedWatcher *watcher) {
Austin Schuh39788ff2019-12-01 18:22:57 -080086 watchers_.erase(std::find(watchers_.begin(), watchers_.end(), watcher));
87 }
Alex Perrycb7da4b2019-08-28 19:35:56 -070088
Austin Schuhad154822019-12-27 15:45:13 -080089 // Sends the message to all the connected receivers and fetchers. Returns the
90 // sent queue index.
91 uint32_t Send(std::shared_ptr<SimulatedMessage> message);
Alex Perrycb7da4b2019-08-28 19:35:56 -070092
93 // Unregisters a fetcher.
94 void UnregisterFetcher(SimulatedFetcher *fetcher);
95
96 std::shared_ptr<SimulatedMessage> latest_message() { return latest_message_; }
97
Austin Schuh39788ff2019-12-01 18:22:57 -080098 size_t max_size() const { return channel()->max_size(); }
Alex Perrycb7da4b2019-08-28 19:35:56 -070099
Austin Schuh5f1cc5c2019-12-01 18:01:11 -0800100 const std::string_view name() const {
Austin Schuh39788ff2019-12-01 18:22:57 -0800101 return channel()->name()->string_view();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700102 }
103
Austin Schuh39788ff2019-12-01 18:22:57 -0800104 const Channel *channel() const { return channel_; }
105
Alex Perrycb7da4b2019-08-28 19:35:56 -0700106 private:
Austin Schuh39788ff2019-12-01 18:22:57 -0800107 const Channel *channel_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700108
109 // List of all watchers.
Austin Schuh7d87b672019-12-01 20:23:49 -0800110 ::std::vector<SimulatedWatcher *> watchers_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700111
112 // List of all fetchers.
113 ::std::vector<SimulatedFetcher *> fetchers_;
114 std::shared_ptr<SimulatedMessage> latest_message_;
115 EventScheduler *scheduler_;
116
117 ipc_lib::QueueIndex next_queue_index_;
118};
119
120namespace {
121
122// Creates a SimulatedMessage with size bytes of storage.
123// This is a shared_ptr so we don't have to implement refcounting or copying.
124std::shared_ptr<SimulatedMessage> MakeSimulatedMessage(size_t size) {
125 SimulatedMessage *message = reinterpret_cast<SimulatedMessage *>(
Brian Silvermana1652f32020-01-29 20:41:44 -0800126 malloc(sizeof(SimulatedMessage) + size + kChannelDataAlignment - 1));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700127 message->context.size = size;
Brian Silvermana1652f32020-01-29 20:41:44 -0800128 message->context.data = message->data(size);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700129
130 return std::shared_ptr<SimulatedMessage>(message, free);
131}
132
133class SimulatedSender : public RawSender {
134 public:
135 SimulatedSender(SimulatedChannel *simulated_channel, EventLoop *event_loop)
Austin Schuh39788ff2019-12-01 18:22:57 -0800136 : RawSender(event_loop, simulated_channel->channel()),
Austin Schuh54cf95f2019-11-29 13:14:18 -0800137 simulated_channel_(simulated_channel),
138 event_loop_(event_loop) {}
Alex Perrycb7da4b2019-08-28 19:35:56 -0700139 ~SimulatedSender() {}
140
141 void *data() override {
142 if (!message_) {
143 message_ = MakeSimulatedMessage(simulated_channel_->max_size());
144 }
Brian Silvermana1652f32020-01-29 20:41:44 -0800145 return message_->data(simulated_channel_->max_size());
Alex Perrycb7da4b2019-08-28 19:35:56 -0700146 }
147
148 size_t size() override { return simulated_channel_->max_size(); }
149
Austin Schuhad154822019-12-27 15:45:13 -0800150 bool DoSend(size_t length,
151 aos::monotonic_clock::time_point monotonic_remote_time,
152 aos::realtime_clock::time_point realtime_remote_time,
153 uint32_t remote_queue_index) override {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700154 CHECK_LE(length, size()) << ": Attempting to send too big a message.";
Austin Schuhad154822019-12-27 15:45:13 -0800155 message_->context.monotonic_event_time = event_loop_->monotonic_now();
156 message_->context.monotonic_remote_time = monotonic_remote_time;
157 message_->context.remote_queue_index = remote_queue_index;
158 message_->context.realtime_event_time = event_loop_->realtime_now();
159 message_->context.realtime_remote_time = realtime_remote_time;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700160 CHECK_LE(length, message_->context.size);
161 message_->context.size = length;
162
163 // TODO(austin): Track sending too fast.
Austin Schuhad154822019-12-27 15:45:13 -0800164 sent_queue_index_ = simulated_channel_->Send(message_);
165 monotonic_sent_time_ = event_loop_->monotonic_now();
166 realtime_sent_time_ = event_loop_->realtime_now();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700167
168 // Drop the reference to the message so that we allocate a new message for
169 // next time. Otherwise we will continue to reuse the same memory for all
170 // messages and corrupt it.
171 message_.reset();
172 return true;
173 }
174
Austin Schuhad154822019-12-27 15:45:13 -0800175 bool DoSend(const void *msg, size_t size,
176 aos::monotonic_clock::time_point monotonic_remote_time,
177 aos::realtime_clock::time_point realtime_remote_time,
178 uint32_t remote_queue_index) override {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700179 CHECK_LE(size, this->size()) << ": Attempting to send too big a message.";
180
181 // This is wasteful, but since flatbuffers fill from the back end of the
182 // queue, we need it to be full sized.
183 message_ = MakeSimulatedMessage(simulated_channel_->max_size());
184
185 // Now fill in the message. size is already populated above, and
Austin Schuhac0771c2020-01-07 18:36:30 -0800186 // queue_index will be populated in simulated_channel_. Put this at the
187 // back of the data segment.
Brian Silvermana1652f32020-01-29 20:41:44 -0800188 memcpy(message_->data(simulated_channel_->max_size()) +
189 simulated_channel_->max_size() - size,
190 msg, size);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700191
Austin Schuhac0771c2020-01-07 18:36:30 -0800192 return DoSend(size, monotonic_remote_time, realtime_remote_time,
193 remote_queue_index);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700194 }
195
Alex Perrycb7da4b2019-08-28 19:35:56 -0700196 private:
197 SimulatedChannel *simulated_channel_;
198 EventLoop *event_loop_;
199
200 std::shared_ptr<SimulatedMessage> message_;
201};
202} // namespace
203
204class SimulatedFetcher : public RawFetcher {
205 public:
Austin Schuhac0771c2020-01-07 18:36:30 -0800206 explicit SimulatedFetcher(EventLoop *event_loop,
207 SimulatedChannel *simulated_channel)
208 : RawFetcher(event_loop, simulated_channel->channel()),
209 simulated_channel_(simulated_channel) {}
210 ~SimulatedFetcher() { simulated_channel_->UnregisterFetcher(this); }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700211
Austin Schuh39788ff2019-12-01 18:22:57 -0800212 std::pair<bool, monotonic_clock::time_point> DoFetchNext() override {
213 if (msgs_.size() == 0) {
214 return std::make_pair(false, monotonic_clock::min_time);
215 }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700216
217 SetMsg(msgs_.front());
218 msgs_.pop_front();
Austin Schuha5e14192020-01-06 18:02:41 -0800219 return std::make_pair(true, event_loop()->monotonic_now());
Alex Perrycb7da4b2019-08-28 19:35:56 -0700220 }
221
Austin Schuh39788ff2019-12-01 18:22:57 -0800222 std::pair<bool, monotonic_clock::time_point> DoFetch() override {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700223 if (msgs_.size() == 0) {
Austin Schuh7d87b672019-12-01 20:23:49 -0800224 // TODO(austin): Can we just do this logic unconditionally? It is a lot
225 // simpler. And call clear, obviously.
Austin Schuhac0771c2020-01-07 18:36:30 -0800226 if (!msg_ && simulated_channel_->latest_message()) {
227 SetMsg(simulated_channel_->latest_message());
Austin Schuha5e14192020-01-06 18:02:41 -0800228 return std::make_pair(true, event_loop()->monotonic_now());
Alex Perrycb7da4b2019-08-28 19:35:56 -0700229 } else {
Austin Schuh39788ff2019-12-01 18:22:57 -0800230 return std::make_pair(false, monotonic_clock::min_time);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700231 }
232 }
233
234 // We've had a message enqueued, so we don't need to go looking for the
235 // latest message from before we started.
236 SetMsg(msgs_.back());
237 msgs_.clear();
Austin Schuha5e14192020-01-06 18:02:41 -0800238 return std::make_pair(true, event_loop()->monotonic_now());
Alex Perrycb7da4b2019-08-28 19:35:56 -0700239 }
240
241 private:
242 friend class SimulatedChannel;
243
244 // Updates the state inside RawFetcher to point to the data in msg_.
245 void SetMsg(std::shared_ptr<SimulatedMessage> msg) {
246 msg_ = msg;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700247 context_ = msg_->context;
Austin Schuhad154822019-12-27 15:45:13 -0800248 if (context_.remote_queue_index == 0xffffffffu) {
249 context_.remote_queue_index = context_.queue_index;
250 }
251 if (context_.monotonic_remote_time == aos::monotonic_clock::min_time) {
252 context_.monotonic_remote_time = context_.monotonic_event_time;
253 }
254 if (context_.realtime_remote_time == aos::realtime_clock::min_time) {
255 context_.realtime_remote_time = context_.realtime_event_time;
256 }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700257 }
258
259 // Internal method for Simulation to add a message to the buffer.
260 void Enqueue(std::shared_ptr<SimulatedMessage> buffer) {
261 msgs_.emplace_back(buffer);
262 }
263
Austin Schuhac0771c2020-01-07 18:36:30 -0800264 SimulatedChannel *simulated_channel_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700265 std::shared_ptr<SimulatedMessage> msg_;
266
267 // Messages queued up but not in use.
268 ::std::deque<std::shared_ptr<SimulatedMessage>> msgs_;
269};
270
271class SimulatedTimerHandler : public TimerHandler {
272 public:
273 explicit SimulatedTimerHandler(EventScheduler *scheduler,
Austin Schuhac0771c2020-01-07 18:36:30 -0800274 NodeEventLoopFactory *node_event_loop_factory,
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800275 SimulatedEventLoop *simulated_event_loop,
Austin Schuh39788ff2019-12-01 18:22:57 -0800276 ::std::function<void()> fn);
Austin Schuh7d87b672019-12-01 20:23:49 -0800277 ~SimulatedTimerHandler() { Disable(); }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700278
279 void Setup(monotonic_clock::time_point base,
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800280 monotonic_clock::duration repeat_offset) override;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700281
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800282 void HandleEvent();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700283
Austin Schuh7d87b672019-12-01 20:23:49 -0800284 void Disable() override;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700285
Alex Perrycb7da4b2019-08-28 19:35:56 -0700286 private:
Austin Schuh7d87b672019-12-01 20:23:49 -0800287 SimulatedEventLoop *simulated_event_loop_;
288 EventHandler<SimulatedTimerHandler> event_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700289 EventScheduler *scheduler_;
Austin Schuhac0771c2020-01-07 18:36:30 -0800290 NodeEventLoopFactory *node_event_loop_factory_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700291 EventScheduler::Token token_;
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800292
Alex Perrycb7da4b2019-08-28 19:35:56 -0700293 monotonic_clock::time_point base_;
294 monotonic_clock::duration repeat_offset_;
295};
296
297class SimulatedPhasedLoopHandler : public PhasedLoopHandler {
298 public:
299 SimulatedPhasedLoopHandler(EventScheduler *scheduler,
Austin Schuhac0771c2020-01-07 18:36:30 -0800300 NodeEventLoopFactory *node_event_loop_factory,
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800301 SimulatedEventLoop *simulated_event_loop,
Alex Perrycb7da4b2019-08-28 19:35:56 -0700302 ::std::function<void(int)> fn,
303 const monotonic_clock::duration interval,
Austin Schuh39788ff2019-12-01 18:22:57 -0800304 const monotonic_clock::duration offset);
Austin Schuh7d87b672019-12-01 20:23:49 -0800305 ~SimulatedPhasedLoopHandler();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700306
Austin Schuh7d87b672019-12-01 20:23:49 -0800307 void HandleEvent();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700308
Austin Schuh7d87b672019-12-01 20:23:49 -0800309 void Schedule(monotonic_clock::time_point sleep_time) override;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700310
311 private:
Austin Schuh39788ff2019-12-01 18:22:57 -0800312 SimulatedEventLoop *simulated_event_loop_;
Austin Schuh7d87b672019-12-01 20:23:49 -0800313 EventHandler<SimulatedPhasedLoopHandler> event_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700314
Austin Schuh39788ff2019-12-01 18:22:57 -0800315 EventScheduler *scheduler_;
Austin Schuhac0771c2020-01-07 18:36:30 -0800316 NodeEventLoopFactory *node_event_loop_factory_;
Austin Schuh39788ff2019-12-01 18:22:57 -0800317 EventScheduler::Token token_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700318};
319
320class SimulatedEventLoop : public EventLoop {
321 public:
322 explicit SimulatedEventLoop(
323 EventScheduler *scheduler,
Austin Schuhac0771c2020-01-07 18:36:30 -0800324 NodeEventLoopFactory *node_event_loop_factory,
Alex Perrycb7da4b2019-08-28 19:35:56 -0700325 absl::btree_map<SimpleChannel, std::unique_ptr<SimulatedChannel>>
326 *channels,
327 const Configuration *configuration,
328 std::vector<std::pair<EventLoop *, std::function<void(bool)>>>
Austin Schuh39788ff2019-12-01 18:22:57 -0800329 *raw_event_loops,
Austin Schuh217a9782019-12-21 23:02:50 -0800330 const Node *node, pid_t tid)
Austin Schuh39788ff2019-12-01 18:22:57 -0800331 : EventLoop(CHECK_NOTNULL(configuration)),
Alex Perrycb7da4b2019-08-28 19:35:56 -0700332 scheduler_(scheduler),
Austin Schuhac0771c2020-01-07 18:36:30 -0800333 node_event_loop_factory_(node_event_loop_factory),
Alex Perrycb7da4b2019-08-28 19:35:56 -0700334 channels_(channels),
Austin Schuh39788ff2019-12-01 18:22:57 -0800335 raw_event_loops_(raw_event_loops),
Austin Schuh217a9782019-12-21 23:02:50 -0800336 node_(node),
Austin Schuh39788ff2019-12-01 18:22:57 -0800337 tid_(tid) {
338 raw_event_loops_->push_back(std::make_pair(this, [this](bool value) {
339 if (!has_setup_) {
340 Setup();
341 has_setup_ = true;
342 }
343 set_is_running(value);
344 }));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700345 }
346 ~SimulatedEventLoop() override {
Austin Schuh39788ff2019-12-01 18:22:57 -0800347 // Trigger any remaining senders or fetchers to be cleared before destroying
348 // the event loop so the book keeping matches.
349 timing_report_sender_.reset();
350
351 // Force everything with a registered fd with epoll to be destroyed now.
352 timers_.clear();
353 phased_loops_.clear();
354 watchers_.clear();
355
Alex Perrycb7da4b2019-08-28 19:35:56 -0700356 for (auto it = raw_event_loops_->begin(); it != raw_event_loops_->end();
357 ++it) {
358 if (it->first == this) {
359 raw_event_loops_->erase(it);
360 break;
361 }
362 }
363 }
364
Austin Schuh7d87b672019-12-01 20:23:49 -0800365 std::chrono::nanoseconds send_delay() const { return send_delay_; }
366 void set_send_delay(std::chrono::nanoseconds send_delay) {
367 send_delay_ = send_delay;
368 }
369
Alex Perrycb7da4b2019-08-28 19:35:56 -0700370 ::aos::monotonic_clock::time_point monotonic_now() override {
Austin Schuhac0771c2020-01-07 18:36:30 -0800371 return node_event_loop_factory_->monotonic_now();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700372 }
373
374 ::aos::realtime_clock::time_point realtime_now() override {
Austin Schuhac0771c2020-01-07 18:36:30 -0800375 return node_event_loop_factory_->realtime_now();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700376 }
377
378 ::std::unique_ptr<RawSender> MakeRawSender(const Channel *channel) override;
379
380 ::std::unique_ptr<RawFetcher> MakeRawFetcher(const Channel *channel) override;
381
382 void MakeRawWatcher(
383 const Channel *channel,
384 ::std::function<void(const Context &context, const void *message)>
385 watcher) override;
386
387 TimerHandler *AddTimer(::std::function<void()> callback) override {
Austin Schuh39788ff2019-12-01 18:22:57 -0800388 CHECK(!is_running());
Austin Schuhac0771c2020-01-07 18:36:30 -0800389 return NewTimer(::std::unique_ptr<TimerHandler>(new SimulatedTimerHandler(
390 scheduler_, node_event_loop_factory_, this, callback)));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700391 }
392
393 PhasedLoopHandler *AddPhasedLoop(::std::function<void(int)> callback,
394 const monotonic_clock::duration interval,
395 const monotonic_clock::duration offset =
396 ::std::chrono::seconds(0)) override {
Austin Schuhac0771c2020-01-07 18:36:30 -0800397 return NewPhasedLoop(::std::unique_ptr<PhasedLoopHandler>(
398 new SimulatedPhasedLoopHandler(scheduler_, node_event_loop_factory_,
399 this, callback, interval, offset)));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700400 }
401
402 void OnRun(::std::function<void()> on_run) override {
Austin Schuh39788ff2019-12-01 18:22:57 -0800403 scheduler_->ScheduleOnRun(on_run);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700404 }
405
Austin Schuh217a9782019-12-21 23:02:50 -0800406 const Node *node() const override { return node_; }
407
James Kuszmaul3ae42262019-11-08 12:33:41 -0800408 void set_name(const std::string_view name) override {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700409 name_ = std::string(name);
410 }
James Kuszmaul3ae42262019-11-08 12:33:41 -0800411 const std::string_view name() const override { return name_; }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700412
413 SimulatedChannel *GetSimulatedChannel(const Channel *channel);
414
Austin Schuh39788ff2019-12-01 18:22:57 -0800415 void SetRuntimeRealtimePriority(int priority) override {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700416 CHECK(!is_running()) << ": Cannot set realtime priority while running.";
Austin Schuh39788ff2019-12-01 18:22:57 -0800417 priority_ = priority;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700418 }
419
Austin Schuh39788ff2019-12-01 18:22:57 -0800420 int priority() const override { return priority_; }
421
422 void Setup() { MaybeScheduleTimingReports(); }
423
Alex Perrycb7da4b2019-08-28 19:35:56 -0700424 private:
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800425 friend class SimulatedTimerHandler;
Austin Schuh7d87b672019-12-01 20:23:49 -0800426 friend class SimulatedPhasedLoopHandler;
427 friend class SimulatedWatcher;
428
429 void HandleEvent() {
430 while (true) {
431 if (EventCount() == 0 || PeekEvent()->event_time() > monotonic_now()) {
432 break;
433 }
434
435 EventLoopEvent *event = PopEvent();
436 event->HandleEvent();
437 }
438 }
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800439
Austin Schuh39788ff2019-12-01 18:22:57 -0800440 pid_t GetTid() override { return tid_; }
441
Alex Perrycb7da4b2019-08-28 19:35:56 -0700442 EventScheduler *scheduler_;
Austin Schuhac0771c2020-01-07 18:36:30 -0800443 NodeEventLoopFactory *node_event_loop_factory_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700444 absl::btree_map<SimpleChannel, std::unique_ptr<SimulatedChannel>> *channels_;
445 std::vector<std::pair<EventLoop *, std::function<void(bool)>>>
446 *raw_event_loops_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700447
448 ::std::string name_;
Austin Schuh39788ff2019-12-01 18:22:57 -0800449
450 int priority_ = 0;
451
452 bool has_setup_ = false;
453
Austin Schuh7d87b672019-12-01 20:23:49 -0800454 std::chrono::nanoseconds send_delay_;
455
Austin Schuh217a9782019-12-21 23:02:50 -0800456 const Node *const node_;
Austin Schuh39788ff2019-12-01 18:22:57 -0800457 const pid_t tid_;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700458};
459
Austin Schuh7d87b672019-12-01 20:23:49 -0800460void SimulatedEventLoopFactory::set_send_delay(
461 std::chrono::nanoseconds send_delay) {
462 send_delay_ = send_delay;
463 for (std::pair<EventLoop *, std::function<void(bool)>> &loop :
464 raw_event_loops_) {
465 reinterpret_cast<SimulatedEventLoop *>(loop.first)
466 ->set_send_delay(send_delay_);
467 }
468}
469
Alex Perrycb7da4b2019-08-28 19:35:56 -0700470void SimulatedEventLoop::MakeRawWatcher(
471 const Channel *channel,
472 std::function<void(const Context &channel, const void *message)> watcher) {
Brian Silverman0fc69932020-01-24 21:54:02 -0800473 TakeWatcher(channel);
Austin Schuh217a9782019-12-21 23:02:50 -0800474
Austin Schuhac0771c2020-01-07 18:36:30 -0800475 std::unique_ptr<SimulatedWatcher> shm_watcher(new SimulatedWatcher(
476 this, scheduler_, node_event_loop_factory_, channel, std::move(watcher)));
Austin Schuh39788ff2019-12-01 18:22:57 -0800477
478 GetSimulatedChannel(channel)->MakeRawWatcher(shm_watcher.get());
479 NewWatcher(std::move(shm_watcher));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700480}
481
482std::unique_ptr<RawSender> SimulatedEventLoop::MakeRawSender(
483 const Channel *channel) {
Brian Silverman0fc69932020-01-24 21:54:02 -0800484 TakeSender(channel);
485
Alex Perrycb7da4b2019-08-28 19:35:56 -0700486 return GetSimulatedChannel(channel)->MakeRawSender(this);
487}
488
489std::unique_ptr<RawFetcher> SimulatedEventLoop::MakeRawFetcher(
490 const Channel *channel) {
Austin Schuh39788ff2019-12-01 18:22:57 -0800491 ChannelIndex(channel);
Austin Schuh217a9782019-12-21 23:02:50 -0800492
Austin Schuhca4828c2019-12-28 14:21:35 -0800493 if (!configuration::ChannelIsReadableOnNode(channel, node())) {
494 LOG(FATAL) << "Channel { \"name\": \"" << channel->name()->string_view()
495 << "\", \"type\": \"" << channel->type()->string_view()
496 << "\" } is not able to be fetched on this node. Check your "
497 "configuration.";
Austin Schuh217a9782019-12-21 23:02:50 -0800498 }
499
Austin Schuh39788ff2019-12-01 18:22:57 -0800500 return GetSimulatedChannel(channel)->MakeRawFetcher(this);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700501}
502
503SimulatedChannel *SimulatedEventLoop::GetSimulatedChannel(
504 const Channel *channel) {
505 auto it = channels_->find(SimpleChannel(channel));
506 if (it == channels_->end()) {
507 it = channels_
508 ->emplace(SimpleChannel(channel),
509 std::unique_ptr<SimulatedChannel>(
510 new SimulatedChannel(channel, scheduler_)))
511 .first;
512 }
513 return it->second.get();
514}
515
Austin Schuh7d87b672019-12-01 20:23:49 -0800516SimulatedWatcher::SimulatedWatcher(
517 SimulatedEventLoop *simulated_event_loop, EventScheduler *scheduler,
Austin Schuhac0771c2020-01-07 18:36:30 -0800518 NodeEventLoopFactory *node_event_loop_factory, const Channel *channel,
Austin Schuh7d87b672019-12-01 20:23:49 -0800519 std::function<void(const Context &context, const void *message)> fn)
520 : WatcherState(simulated_event_loop, channel, std::move(fn)),
521 simulated_event_loop_(simulated_event_loop),
522 event_(this),
523 scheduler_(scheduler),
Austin Schuhac0771c2020-01-07 18:36:30 -0800524 node_event_loop_factory_(node_event_loop_factory),
Austin Schuh7d87b672019-12-01 20:23:49 -0800525 token_(scheduler_->InvalidToken()) {}
526
527SimulatedWatcher::~SimulatedWatcher() {
528 simulated_event_loop_->RemoveEvent(&event_);
529 if (token_ != scheduler_->InvalidToken()) {
530 scheduler_->Deschedule(token_);
531 }
532 simulated_channel_->RemoveWatcher(this);
533}
534
535void SimulatedWatcher::Schedule(std::shared_ptr<SimulatedMessage> message) {
Austin Schuha5e14192020-01-06 18:02:41 -0800536 monotonic_clock::time_point event_time =
537 simulated_event_loop_->monotonic_now();
Austin Schuh7d87b672019-12-01 20:23:49 -0800538
539 // Messages are queued in order. If we are the first, add ourselves.
540 // Otherwise, don't.
541 if (msgs_.size() == 0) {
Austin Schuhad154822019-12-27 15:45:13 -0800542 event_.set_event_time(message->context.monotonic_event_time);
Austin Schuh7d87b672019-12-01 20:23:49 -0800543 simulated_event_loop_->AddEvent(&event_);
544
545 DoSchedule(event_time);
546 }
547
548 msgs_.emplace_back(message);
549}
550
551void SimulatedWatcher::HandleEvent() {
552 CHECK_NE(msgs_.size(), 0u) << ": No events to handle.";
553
554 const monotonic_clock::time_point monotonic_now =
555 simulated_event_loop_->monotonic_now();
Austin Schuhad154822019-12-27 15:45:13 -0800556 Context context = msgs_.front()->context;
557
558 if (context.remote_queue_index == 0xffffffffu) {
559 context.remote_queue_index = context.queue_index;
560 }
561 if (context.monotonic_remote_time == aos::monotonic_clock::min_time) {
562 context.monotonic_remote_time = context.monotonic_event_time;
563 }
564 if (context.realtime_remote_time == aos::realtime_clock::min_time) {
565 context.realtime_remote_time = context.realtime_event_time;
566 }
567
568 DoCallCallback([monotonic_now]() { return monotonic_now; }, context);
Austin Schuh7d87b672019-12-01 20:23:49 -0800569
570 msgs_.pop_front();
571 if (msgs_.size() != 0) {
Austin Schuhad154822019-12-27 15:45:13 -0800572 event_.set_event_time(msgs_.front()->context.monotonic_event_time);
Austin Schuh7d87b672019-12-01 20:23:49 -0800573 simulated_event_loop_->AddEvent(&event_);
574
575 DoSchedule(event_.event_time());
576 } else {
577 token_ = scheduler_->InvalidToken();
578 }
579}
580
581void SimulatedWatcher::DoSchedule(monotonic_clock::time_point event_time) {
Austin Schuhac0771c2020-01-07 18:36:30 -0800582 token_ = scheduler_->Schedule(
583 node_event_loop_factory_->ToDistributedClock(
584 event_time + simulated_event_loop_->send_delay()),
585 [this]() { simulated_event_loop_->HandleEvent(); });
Austin Schuh7d87b672019-12-01 20:23:49 -0800586}
587
588void SimulatedChannel::MakeRawWatcher(SimulatedWatcher *watcher) {
Austin Schuh39788ff2019-12-01 18:22:57 -0800589 watcher->SetSimulatedChannel(this);
590 watchers_.emplace_back(watcher);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700591}
592
593::std::unique_ptr<RawSender> SimulatedChannel::MakeRawSender(
594 EventLoop *event_loop) {
595 return ::std::unique_ptr<RawSender>(new SimulatedSender(this, event_loop));
596}
597
Austin Schuh39788ff2019-12-01 18:22:57 -0800598::std::unique_ptr<RawFetcher> SimulatedChannel::MakeRawFetcher(
599 EventLoop *event_loop) {
600 ::std::unique_ptr<SimulatedFetcher> fetcher(
601 new SimulatedFetcher(event_loop, this));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700602 fetchers_.push_back(fetcher.get());
603 return ::std::move(fetcher);
604}
605
Austin Schuhad154822019-12-27 15:45:13 -0800606uint32_t SimulatedChannel::Send(std::shared_ptr<SimulatedMessage> message) {
607 const uint32_t queue_index = next_queue_index_.index();
608 message->context.queue_index = queue_index;
Brian Silvermana1652f32020-01-29 20:41:44 -0800609 message->context.data = message->data(channel()->max_size()) +
610 channel()->max_size() - message->context.size;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700611 next_queue_index_ = next_queue_index_.Increment();
612
613 latest_message_ = message;
614 if (scheduler_->is_running()) {
Austin Schuh7d87b672019-12-01 20:23:49 -0800615 for (SimulatedWatcher *watcher : watchers_) {
616 watcher->Schedule(message);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700617 }
618 }
619 for (auto &fetcher : fetchers_) {
620 fetcher->Enqueue(message);
621 }
Austin Schuhad154822019-12-27 15:45:13 -0800622
623 return queue_index;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700624}
625
626void SimulatedChannel::UnregisterFetcher(SimulatedFetcher *fetcher) {
627 fetchers_.erase(::std::find(fetchers_.begin(), fetchers_.end(), fetcher));
628}
629
Austin Schuh39788ff2019-12-01 18:22:57 -0800630SimulatedTimerHandler::SimulatedTimerHandler(
Austin Schuhac0771c2020-01-07 18:36:30 -0800631 EventScheduler *scheduler, NodeEventLoopFactory *node_event_loop_factory,
632 SimulatedEventLoop *simulated_event_loop, ::std::function<void()> fn)
Austin Schuh39788ff2019-12-01 18:22:57 -0800633 : TimerHandler(simulated_event_loop, std::move(fn)),
Austin Schuh7d87b672019-12-01 20:23:49 -0800634 simulated_event_loop_(simulated_event_loop),
635 event_(this),
Austin Schuh39788ff2019-12-01 18:22:57 -0800636 scheduler_(scheduler),
Austin Schuhac0771c2020-01-07 18:36:30 -0800637 node_event_loop_factory_(node_event_loop_factory),
Austin Schuh39788ff2019-12-01 18:22:57 -0800638 token_(scheduler_->InvalidToken()) {}
639
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800640void SimulatedTimerHandler::Setup(monotonic_clock::time_point base,
641 monotonic_clock::duration repeat_offset) {
642 Disable();
643 const ::aos::monotonic_clock::time_point monotonic_now =
Austin Schuha5e14192020-01-06 18:02:41 -0800644 simulated_event_loop_->monotonic_now();
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800645 base_ = base;
646 repeat_offset_ = repeat_offset;
647 if (base < monotonic_now) {
Austin Schuh7d87b672019-12-01 20:23:49 -0800648 token_ = scheduler_->Schedule(
Austin Schuhac0771c2020-01-07 18:36:30 -0800649 node_event_loop_factory_->ToDistributedClock(monotonic_now),
650 [this]() { simulated_event_loop_->HandleEvent(); });
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800651 } else {
Austin Schuh7d87b672019-12-01 20:23:49 -0800652 token_ = scheduler_->Schedule(
Austin Schuhac0771c2020-01-07 18:36:30 -0800653 node_event_loop_factory_->ToDistributedClock(base),
654 [this]() { simulated_event_loop_->HandleEvent(); });
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800655 }
Austin Schuh7d87b672019-12-01 20:23:49 -0800656 event_.set_event_time(base_);
657 simulated_event_loop_->AddEvent(&event_);
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800658}
659
660void SimulatedTimerHandler::HandleEvent() {
661 const ::aos::monotonic_clock::time_point monotonic_now =
Austin Schuha5e14192020-01-06 18:02:41 -0800662 simulated_event_loop_->monotonic_now();
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800663 if (repeat_offset_ != ::aos::monotonic_clock::zero()) {
664 // Reschedule.
665 while (base_ <= monotonic_now) base_ += repeat_offset_;
Austin Schuh7d87b672019-12-01 20:23:49 -0800666 token_ = scheduler_->Schedule(
Austin Schuhac0771c2020-01-07 18:36:30 -0800667 node_event_loop_factory_->ToDistributedClock(base_),
668 [this]() { simulated_event_loop_->HandleEvent(); });
Austin Schuh7d87b672019-12-01 20:23:49 -0800669 event_.set_event_time(base_);
670 simulated_event_loop_->AddEvent(&event_);
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800671 } else {
672 token_ = scheduler_->InvalidToken();
673 }
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800674
Austin Schuh39788ff2019-12-01 18:22:57 -0800675 Call([monotonic_now]() { return monotonic_now; }, monotonic_now);
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800676}
677
Austin Schuh7d87b672019-12-01 20:23:49 -0800678void SimulatedTimerHandler::Disable() {
679 simulated_event_loop_->RemoveEvent(&event_);
680 if (token_ != scheduler_->InvalidToken()) {
681 scheduler_->Deschedule(token_);
682 token_ = scheduler_->InvalidToken();
683 }
684}
685
Austin Schuh39788ff2019-12-01 18:22:57 -0800686SimulatedPhasedLoopHandler::SimulatedPhasedLoopHandler(
Austin Schuhac0771c2020-01-07 18:36:30 -0800687 EventScheduler *scheduler, NodeEventLoopFactory *node_event_loop_factory,
688 SimulatedEventLoop *simulated_event_loop, ::std::function<void(int)> fn,
689 const monotonic_clock::duration interval,
Austin Schuh39788ff2019-12-01 18:22:57 -0800690 const monotonic_clock::duration offset)
691 : PhasedLoopHandler(simulated_event_loop, std::move(fn), interval, offset),
692 simulated_event_loop_(simulated_event_loop),
Austin Schuh7d87b672019-12-01 20:23:49 -0800693 event_(this),
Austin Schuh39788ff2019-12-01 18:22:57 -0800694 scheduler_(scheduler),
Austin Schuhac0771c2020-01-07 18:36:30 -0800695 node_event_loop_factory_(node_event_loop_factory),
Austin Schuh39788ff2019-12-01 18:22:57 -0800696 token_(scheduler_->InvalidToken()) {}
697
Austin Schuh7d87b672019-12-01 20:23:49 -0800698SimulatedPhasedLoopHandler::~SimulatedPhasedLoopHandler() {
699 if (token_ != scheduler_->InvalidToken()) {
700 scheduler_->Deschedule(token_);
701 token_ = scheduler_->InvalidToken();
702 }
703 simulated_event_loop_->RemoveEvent(&event_);
704}
705
706void SimulatedPhasedLoopHandler::HandleEvent() {
Austin Schuh39788ff2019-12-01 18:22:57 -0800707 monotonic_clock::time_point monotonic_now =
708 simulated_event_loop_->monotonic_now();
709 Call(
710 [monotonic_now]() { return monotonic_now; },
711 [this](monotonic_clock::time_point sleep_time) { Schedule(sleep_time); });
712}
Austin Schuhde8a8ff2019-11-30 15:25:36 -0800713
Austin Schuh7d87b672019-12-01 20:23:49 -0800714void SimulatedPhasedLoopHandler::Schedule(
715 monotonic_clock::time_point sleep_time) {
716 token_ = scheduler_->Schedule(
Austin Schuhac0771c2020-01-07 18:36:30 -0800717 node_event_loop_factory_->ToDistributedClock(sleep_time),
718 [this]() { simulated_event_loop_->HandleEvent(); });
Austin Schuh7d87b672019-12-01 20:23:49 -0800719 event_.set_event_time(sleep_time);
720 simulated_event_loop_->AddEvent(&event_);
721}
722
Austin Schuhac0771c2020-01-07 18:36:30 -0800723NodeEventLoopFactory::NodeEventLoopFactory(
724 EventScheduler *scheduler, SimulatedEventLoopFactory *factory,
725 const Node *node,
726 std::vector<std::pair<EventLoop *, std::function<void(bool)>>>
727 *raw_event_loops)
728 : scheduler_(scheduler),
729 factory_(factory),
730 node_(node),
731 raw_event_loops_(raw_event_loops) {}
732
Alex Perrycb7da4b2019-08-28 19:35:56 -0700733SimulatedEventLoopFactory::SimulatedEventLoopFactory(
734 const Configuration *configuration)
Austin Schuhac0771c2020-01-07 18:36:30 -0800735 : configuration_(CHECK_NOTNULL(configuration)) {
736 if (configuration::MultiNode(configuration_)) {
737 for (const Node *node : *configuration->nodes()) {
738 nodes_.emplace_back(node);
Austin Schuh15649d62019-12-28 16:36:38 -0800739 }
Austin Schuhac0771c2020-01-07 18:36:30 -0800740 } else {
741 nodes_.emplace_back(nullptr);
742 }
743
744 for (const Node *node : nodes_) {
745 node_factories_.emplace_back(
746 new NodeEventLoopFactory(&scheduler_, this, node, &raw_event_loops_));
Austin Schuh15649d62019-12-28 16:36:38 -0800747 }
Austin Schuh898f4972020-01-11 17:21:25 -0800748
749 if (configuration::MultiNode(configuration)) {
750 bridge_ = std::make_unique<message_bridge::SimulatedMessageBridge>(this);
751 }
Austin Schuh15649d62019-12-28 16:36:38 -0800752}
753
Alex Perrycb7da4b2019-08-28 19:35:56 -0700754SimulatedEventLoopFactory::~SimulatedEventLoopFactory() {}
755
Austin Schuhac0771c2020-01-07 18:36:30 -0800756NodeEventLoopFactory *SimulatedEventLoopFactory::GetNodeEventLoopFactory(
757 const Node *node) {
758 auto result = std::find_if(
759 node_factories_.begin(), node_factories_.end(),
760 [node](const std::unique_ptr<NodeEventLoopFactory> &node_factory) {
761 return node_factory->node() == node;
762 });
763
764 CHECK(result != node_factories_.end())
765 << ": Failed to find node " << FlatbufferToJson(node);
766
767 return result->get();
768}
769
Austin Schuh5f1cc5c2019-12-01 18:01:11 -0800770::std::unique_ptr<EventLoop> SimulatedEventLoopFactory::MakeEventLoop(
Austin Schuhac0771c2020-01-07 18:36:30 -0800771 std::string_view name, const Node *node) {
772 if (node == nullptr) {
773 CHECK(!configuration::MultiNode(configuration()))
774 << ": Can't make a single node event loop in a multi-node world.";
775 } else {
776 CHECK(configuration::MultiNode(configuration()))
777 << ": Can't make a multi-node event loop in a single-node world.";
778 }
779 return GetNodeEventLoopFactory(node)->MakeEventLoop(name);
780}
781
782::std::unique_ptr<EventLoop> NodeEventLoopFactory::MakeEventLoop(
Austin Schuh5f1cc5c2019-12-01 18:01:11 -0800783 std::string_view name) {
Austin Schuh39788ff2019-12-01 18:22:57 -0800784 pid_t tid = tid_;
785 ++tid_;
Austin Schuh7d87b672019-12-01 20:23:49 -0800786 ::std::unique_ptr<SimulatedEventLoop> result(new SimulatedEventLoop(
Austin Schuhac0771c2020-01-07 18:36:30 -0800787 scheduler_, this, &channels_, factory_->configuration(), raw_event_loops_,
788 node_, tid));
Austin Schuh5f1cc5c2019-12-01 18:01:11 -0800789 result->set_name(name);
Austin Schuhac0771c2020-01-07 18:36:30 -0800790 result->set_send_delay(factory_->send_delay());
Austin Schuh7d87b672019-12-01 20:23:49 -0800791 return std::move(result);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700792}
793
794void SimulatedEventLoopFactory::RunFor(monotonic_clock::duration duration) {
795 for (const std::pair<EventLoop *, std::function<void(bool)>> &event_loop :
796 raw_event_loops_) {
797 event_loop.second(true);
798 }
799 scheduler_.RunFor(duration);
Austin Schuh39788ff2019-12-01 18:22:57 -0800800 for (const std::pair<EventLoop *, std::function<void(bool)>> &event_loop :
801 raw_event_loops_) {
802 event_loop.second(false);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700803 }
804}
805
806void SimulatedEventLoopFactory::Run() {
807 for (const std::pair<EventLoop *, std::function<void(bool)>> &event_loop :
808 raw_event_loops_) {
809 event_loop.second(true);
810 }
811 scheduler_.Run();
Austin Schuh39788ff2019-12-01 18:22:57 -0800812 for (const std::pair<EventLoop *, std::function<void(bool)>> &event_loop :
813 raw_event_loops_) {
814 event_loop.second(false);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700815 }
816}
817
818} // namespace aos