From 2b342357d9b0d69b2bc00a40780ca7c8d8ee8198 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Mon, 16 Nov 2015 17:13:46 -0800 Subject: [PATCH] use scope exit to ensure spinning is reset --- rclcpp/src/rclcpp/executor.cpp | 4 ++++ rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp | 3 +++ rclcpp/src/rclcpp/executors/single_threaded_executor.cpp | 3 +++ 3 files changed, 10 insertions(+) diff --git a/rclcpp/src/rclcpp/executor.cpp b/rclcpp/src/rclcpp/executor.cpp index b4f3793..48ac9c9 100644 --- a/rclcpp/src/rclcpp/executor.cpp +++ b/rclcpp/src/rclcpp/executor.cpp @@ -16,6 +16,8 @@ #include "rcl_interfaces/msg/intra_process_message.hpp" +#include "./scope_exit.hpp" + using rclcpp::executor::AnyExecutable; using rclcpp::executor::Executor; @@ -108,6 +110,7 @@ Executor::spin_node_some(rclcpp::node::Node::SharedPtr node) void Executor::spin_some() { + RCLCPP_SCOPE_EXIT(this->spinning.store(false); ); if (spinning.exchange(true)) { throw std::runtime_error("spin_some() called while already spinning"); } @@ -121,6 +124,7 @@ Executor::spin_some() void Executor::spin_once(std::chrono::nanoseconds timeout) { + RCLCPP_SCOPE_EXIT(this->spinning.store(false); ); if (spinning.exchange(true)) { throw std::runtime_error("spin_once() called while already spinning"); } diff --git a/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp b/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp index c59987c..e62dbcc 100644 --- a/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp +++ b/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp @@ -20,6 +20,8 @@ #include "rclcpp/utilities.hpp" +#include "../scope_exit.hpp" + using rclcpp::executors::multi_threaded_executor::MultiThreadedExecutor; MultiThreadedExecutor::MultiThreadedExecutor(rclcpp::memory_strategy::MemoryStrategy::SharedPtr ms) @@ -36,6 +38,7 @@ MultiThreadedExecutor::~MultiThreadedExecutor() {} void MultiThreadedExecutor::spin() { + RCLCPP_SCOPE_EXIT(this->spinning.store(false); ); if (spinning.exchange(true)) { throw std::runtime_error("spin() called while already spinning"); } diff --git a/rclcpp/src/rclcpp/executors/single_threaded_executor.cpp b/rclcpp/src/rclcpp/executors/single_threaded_executor.cpp index 962221b..00ce809 100644 --- a/rclcpp/src/rclcpp/executors/single_threaded_executor.cpp +++ b/rclcpp/src/rclcpp/executors/single_threaded_executor.cpp @@ -14,6 +14,8 @@ #include +#include "../scope_exit.hpp" + using rclcpp::executors::single_threaded_executor::SingleThreadedExecutor; SingleThreadedExecutor::SingleThreadedExecutor( @@ -26,6 +28,7 @@ SingleThreadedExecutor::~SingleThreadedExecutor() {} void SingleThreadedExecutor::spin() { + RCLCPP_SCOPE_EXIT(this->spinning.store(false); ); if (spinning.exchange(true)) { throw std::runtime_error("spin_some() called while already spinning"); }