From 1c9eb0b36798cc202bc584cae5c0bce78d2ca307 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Tue, 17 Nov 2015 11:32:58 -0800 Subject: [PATCH] only set scope exit after it was determined that spinning was changed to true --- rclcpp/src/rclcpp/executor.cpp | 4 ++-- rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp | 2 +- rclcpp/src/rclcpp/executors/single_threaded_executor.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rclcpp/src/rclcpp/executor.cpp b/rclcpp/src/rclcpp/executor.cpp index 5e0f290..981934c 100644 --- a/rclcpp/src/rclcpp/executor.cpp +++ b/rclcpp/src/rclcpp/executor.cpp @@ -110,10 +110,10 @@ 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"); } + RCLCPP_SCOPE_EXIT(this->spinning.store(false); ); AnyExecutable::SharedPtr any_exec; while ((any_exec = get_next_executable(std::chrono::milliseconds::zero())) && spinning.load()) { execute_any_executable(any_exec); @@ -123,10 +123,10 @@ 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"); } + RCLCPP_SCOPE_EXIT(this->spinning.store(false); ); auto any_exec = get_next_executable(timeout); if (any_exec) { execute_any_executable(any_exec); diff --git a/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp b/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp index e7bcc63..63d555f 100644 --- a/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp +++ b/rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp @@ -38,10 +38,10 @@ 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"); } + RCLCPP_SCOPE_EXIT(this->spinning.store(false); ); std::vector threads; { std::lock_guard wait_lock(wait_mutex_); diff --git a/rclcpp/src/rclcpp/executors/single_threaded_executor.cpp b/rclcpp/src/rclcpp/executors/single_threaded_executor.cpp index 87c25bd..204d422 100644 --- a/rclcpp/src/rclcpp/executors/single_threaded_executor.cpp +++ b/rclcpp/src/rclcpp/executors/single_threaded_executor.cpp @@ -28,10 +28,10 @@ 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"); } + RCLCPP_SCOPE_EXIT(this->spinning.store(false); ); while (rclcpp::utilities::ok() && spinning.load()) { auto any_exec = get_next_executable(); execute_any_executable(any_exec);