From 5d6e5fa766b9ec1237a698b1eefa2733bcdeb506 Mon Sep 17 00:00:00 2001 From: Tomoya Fujita Date: Tue, 1 Aug 2023 22:43:02 -0700 Subject: [PATCH] associated clocks should be protected by mutex. (#2255) Signed-off-by: Tomoya Fujita --- rclcpp/src/rclcpp/time_source.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/rclcpp/src/rclcpp/time_source.cpp b/rclcpp/src/rclcpp/time_source.cpp index 7f3b3b9536..e5c9b994f2 100644 --- a/rclcpp/src/rclcpp/time_source.cpp +++ b/rclcpp/src/rclcpp/time_source.cpp @@ -54,9 +54,7 @@ class ClocksState final ros_time_active_ = true; // Update all attached clocks to zero or last recorded time - for (auto it = associated_clocks_.begin(); it != associated_clocks_.end(); ++it) { - set_clock(last_time_msg_, true, *it); - } + set_all_clocks(last_time_msg_, true); } // An internal method to use in the clock callback that iterates and disables all clocks @@ -71,11 +69,8 @@ class ClocksState final ros_time_active_ = false; // Update all attached clocks - std::lock_guard guard(clock_list_lock_); - for (auto it = associated_clocks_.begin(); it != associated_clocks_.end(); ++it) { - auto msg = std::make_shared(); - set_clock(msg, false, *it); - } + auto msg = std::make_shared(); + set_all_clocks(msg, false); } // Check if ROS time is active