Skip to content

Commit

Permalink
associated clocks should be protected by mutex. (#2255)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoya Fujita <[email protected]>
(cherry picked from commit 5d6e5fa)
  • Loading branch information
fujitatomoya authored and mergify[bot] committed Aug 2, 2023
1 parent 7b7531b commit ce4199d
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 ce4199d

Please sign in to comment.