Skip to content

Commit

Permalink
associated clocks should be protected by mutex. (ros2#2255)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoya Fujita <Tomoya.Fujita@sony.com>
  • Loading branch information
fujitatomoya authored and Barry-Xu-2018 committed Jan 12, 2024
1 parent 875c1b7 commit 324fc28
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions rclcpp/src/rclcpp/time_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -71,11 +69,8 @@ class ClocksState final
ros_time_active_ = false;

// Update all attached clocks
std::lock_guard<std::mutex> guard(clock_list_lock_);
for (auto it = associated_clocks_.begin(); it != associated_clocks_.end(); ++it) {
auto msg = std::make_shared<builtin_interfaces::msg::Time>();
set_clock(msg, false, *it);
}
auto msg = std::make_shared<builtin_interfaces::msg::Time>();
set_all_clocks(msg, false);
}

// Check if ROS time is active
Expand Down

0 comments on commit 324fc28

Please sign in to comment.