Brian Silverman | 76f4836 | 2022-08-24 21:09:08 -0700 | [diff] [blame] | 1 | #include "aos/events/event_loop_runtime.h" |
| 2 | |
| 3 | namespace aos { |
| 4 | |
Adam Snaider | 48a5468 | 2023-09-28 21:50:42 -0700 | [diff] [blame] | 5 | OnRunForRust::OnRunForRust(const EventLoopRuntime *runtime) |
| 6 | : runtime_(runtime) { |
Brian Silverman | 76f4836 | 2022-08-24 21:09:08 -0700 | [diff] [blame] | 7 | ++runtime->child_count_; |
| 8 | } |
| 9 | OnRunForRust::~OnRunForRust() { --runtime_->child_count_; } |
| 10 | bool OnRunForRust::is_running() const { return runtime_->is_running(); } |
| 11 | |
Adam Snaider | 48a5468 | 2023-09-28 21:50:42 -0700 | [diff] [blame] | 12 | std::unique_ptr<TimerForRust> TimerForRust::Make( |
| 13 | const EventLoopRuntime *runtime) { |
Adam Snaider | cc8c2f7 | 2023-06-25 20:56:13 -0700 | [diff] [blame] | 14 | 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 | |
| 23 | bool TimerForRust::Poll() { |
| 24 | if (expired_) { |
| 25 | // Reset it for next poll. |
| 26 | expired_ = false; |
| 27 | return true; |
| 28 | } |
| 29 | return false; |
| 30 | } |
Brian Silverman | 76f4836 | 2022-08-24 21:09:08 -0700 | [diff] [blame] | 31 | } // namespace aos |