From ed4e1638d3ff73ffb25c4db3fb7c2465a441f6bf Mon Sep 17 00:00:00 2001 From: Alberto Soragna Date: Fri, 24 Mar 2023 13:04:21 +0000 Subject: [PATCH] do not try to execute head timer in spin_once_impl if we are not waiting for it Signed-off-by: Alberto Soragna --- .../src/rclcpp/executors/events_executor/events_executor.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/irobot_events_executor/src/rclcpp/executors/events_executor/events_executor.cpp b/irobot_events_executor/src/rclcpp/executors/events_executor/events_executor.cpp index b3556f9..4cd819f 100644 --- a/irobot_events_executor/src/rclcpp/executors/events_executor/events_executor.cpp +++ b/irobot_events_executor/src/rclcpp/executors/events_executor/events_executor.cpp @@ -159,9 +159,11 @@ EventsExecutor::spin_once_impl(std::chrono::nanoseconds timeout) } // Select the smallest between input timeout and timer timeout + bool is_timer_timeout = false; auto next_timer_timeout = timers_manager_->get_head_timeout(); if (next_timer_timeout < timeout) { timeout = next_timer_timeout; + is_timer_timeout = true; } ExecutorEvent event; @@ -171,7 +173,7 @@ EventsExecutor::spin_once_impl(std::chrono::nanoseconds timeout) // arrived before any of the timers expired. if (has_event) { this->execute_event(event); - } else { + } else if (is_timer_timeout) { timers_manager_->execute_head_timer(); } }