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 | |
| 5 | OnRunForRust::OnRunForRust(EventLoopRuntime *runtime) : runtime_(runtime) { |
| 6 | ++runtime->child_count_; |
| 7 | } |
| 8 | OnRunForRust::~OnRunForRust() { --runtime_->child_count_; } |
| 9 | bool OnRunForRust::is_running() const { return runtime_->is_running(); } |
| 10 | |
Adam Snaider | cc8c2f7 | 2023-06-25 20:56:13 -0700 | [diff] [blame] | 11 | std::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 | |
| 21 | bool TimerForRust::Poll() { |
| 22 | if (expired_) { |
| 23 | // Reset it for next poll. |
| 24 | expired_ = false; |
| 25 | return true; |
| 26 | } |
| 27 | return false; |
| 28 | } |
Brian Silverman | 76f4836 | 2022-08-24 21:09:08 -0700 | [diff] [blame] | 29 | } // namespace aos |