blob: 790fe9e699008d7bd91e3f30ddb47142453ea309 [file] [log] [blame]
Brian Silverman76f48362022-08-24 21:09:08 -07001#include "aos/events/event_loop_runtime.h"
2
3namespace aos {
4
Adam Snaider48a54682023-09-28 21:50:42 -07005OnRunForRust::OnRunForRust(const EventLoopRuntime *runtime)
6 : runtime_(runtime) {
Brian Silverman76f48362022-08-24 21:09:08 -07007 ++runtime->child_count_;
8}
9OnRunForRust::~OnRunForRust() { --runtime_->child_count_; }
10bool OnRunForRust::is_running() const { return runtime_->is_running(); }
11
Adam Snaider48a54682023-09-28 21:50:42 -070012std::unique_ptr<TimerForRust> TimerForRust::Make(
13 const EventLoopRuntime *runtime) {
Adam Snaidercc8c2f72023-06-25 20:56:13 -070014 auto handler = std::unique_ptr<TimerForRust>(new TimerForRust());
15 TimerForRust *inner = handler.get();
16 handler->timer_ = runtime->event_loop()->AddTimer([inner, runtime] {
17 inner->expired_ = true;
18 runtime->DoPoll();
19 });
20 return handler;
21}
22
23bool TimerForRust::Poll() {
24 if (expired_) {
25 // Reset it for next poll.
26 expired_ = false;
27 return true;
28 }
29 return false;
30}
Brian Silverman76f48362022-08-24 21:09:08 -070031} // namespace aos