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