From 382c56320e5c9dfe8b2aebfaacf5ceaa0145d5a6 Mon Sep 17 00:00:00 2001 From: Takashi Sato Date: Mon, 3 Jun 2024 17:50:38 +0900 Subject: [PATCH] Changed to use spin instead of spin_once to enable multithreading with MultiThreadedExecutor (#315) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alejandro Hernández Cordero (cherry picked from commit 45035076408e6014cc911e8d4bc169572a25008c) --- ign_ros2_control/src/ign_ros2_control_plugin.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/ign_ros2_control/src/ign_ros2_control_plugin.cpp b/ign_ros2_control/src/ign_ros2_control_plugin.cpp index f5f7eeed..ca58f9fe 100644 --- a/ign_ros2_control/src/ign_ros2_control_plugin.cpp +++ b/ign_ros2_control/src/ign_ros2_control_plugin.cpp @@ -73,9 +73,6 @@ class IgnitionROS2ControlPluginPrivate /// \brief Thread where the executor will spin std::thread thread_executor_spin_; - /// \brief Flag to stop the executor thread when this plugin is exiting - bool stop_{false}; - /// \brief Executor to spin the controller rclcpp::executors::MultiThreadedExecutor::SharedPtr executor_; @@ -238,7 +235,6 @@ IgnitionROS2ControlPlugin::IgnitionROS2ControlPlugin() IgnitionROS2ControlPlugin::~IgnitionROS2ControlPlugin() { // Stop controller manager thread - this->dataPtr->stop_ = true; this->dataPtr->executor_->remove_node(this->dataPtr->controller_manager_); this->dataPtr->executor_->cancel(); this->dataPtr->thread_executor_spin_.join(); @@ -354,12 +350,9 @@ void IgnitionROS2ControlPlugin::Configure( this->dataPtr->node_ = rclcpp::Node::make_shared(node_name, ns); this->dataPtr->executor_ = std::make_shared(); this->dataPtr->executor_->add_node(this->dataPtr->node_); - this->dataPtr->stop_ = false; auto spin = [this]() { - while (rclcpp::ok() && !this->dataPtr->stop_) { - this->dataPtr->executor_->spin_once(); - } + this->dataPtr->executor_->spin(); }; this->dataPtr->thread_executor_spin_ = std::thread(spin);