@@ -242,7 +242,6 @@ class TimeSource::NodeState final
242242 rclcpp::node_interfaces::NodeClockInterface::SharedPtr node_clock_interface,
243243 rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_parameters_interface)
244244 {
245- std::lock_guard<std::mutex> guard (node_base_lock_);
246245 node_base_ = node_base_interface;
247246 node_topics_ = node_topics_interface;
248247 node_graph_ = node_graph_interface;
@@ -287,14 +286,17 @@ class TimeSource::NodeState final
287286 parameter_subscription_ = rclcpp::AsyncParametersClient::on_parameter_event (
288287 node_topics_,
289288 [this ](std::shared_ptr<const rcl_interfaces::msg::ParameterEvent> event) {
290- this ->on_parameter_event (event);
289+ if (node_base_ != nullptr ) {
290+ this ->on_parameter_event (event);
291+ }
292+ // Do nothing if node_base_ is nullptr because it means the TimeSource is now
293+ // without an attached node
291294 });
292295 }
293296
294297 // Detach the attached node
295298 void detachNode ()
296299 {
297- std::lock_guard<std::mutex> guard (node_base_lock_);
298300 // destroy_clock_sub() *must* be first here, to ensure that the executor
299301 // can't possibly call any of the callbacks as we are cleaning up.
300302 destroy_clock_sub ();
@@ -331,7 +333,6 @@ class TimeSource::NodeState final
331333 std::thread clock_executor_thread_;
332334
333335 // Preserve the node reference
334- std::mutex node_base_lock_;
335336 rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base_{nullptr };
336337 rclcpp::node_interfaces::NodeTopicsInterface::SharedPtr node_topics_{nullptr };
337338 rclcpp::node_interfaces::NodeGraphInterface::SharedPtr node_graph_{nullptr };
@@ -469,14 +470,6 @@ class TimeSource::NodeState final
469470 // Callback for parameter updates
470471 void on_parameter_event (std::shared_ptr<const rcl_interfaces::msg::ParameterEvent> event)
471472 {
472- std::lock_guard<std::mutex> guard (node_base_lock_);
473-
474- if (node_base_ == nullptr ) {
475- // Do nothing if node_base_ is nullptr because it means the TimeSource is now
476- // without an attached node
477- return ;
478- }
479-
480473 // Filter out events on 'use_sim_time' parameter instances in other nodes.
481474 if (event->node != node_base_->get_fully_qualified_name ()) {
482475 return ;
0 commit comments