Skip to content

Commit 1c9eb0b

Browse files
committed
only set scope exit after it was determined that spinning was changed to true
1 parent f1e7ea5 commit 1c9eb0b

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

rclcpp/src/rclcpp/executor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ Executor::spin_node_some(rclcpp::node::Node::SharedPtr node)
110110
void
111111
Executor::spin_some()
112112
{
113-
RCLCPP_SCOPE_EXIT(this->spinning.store(false); );
114113
if (spinning.exchange(true)) {
115114
throw std::runtime_error("spin_some() called while already spinning");
116115
}
116+
RCLCPP_SCOPE_EXIT(this->spinning.store(false); );
117117
AnyExecutable::SharedPtr any_exec;
118118
while ((any_exec = get_next_executable(std::chrono::milliseconds::zero())) && spinning.load()) {
119119
execute_any_executable(any_exec);
@@ -123,10 +123,10 @@ Executor::spin_some()
123123
void
124124
Executor::spin_once(std::chrono::nanoseconds timeout)
125125
{
126-
RCLCPP_SCOPE_EXIT(this->spinning.store(false); );
127126
if (spinning.exchange(true)) {
128127
throw std::runtime_error("spin_once() called while already spinning");
129128
}
129+
RCLCPP_SCOPE_EXIT(this->spinning.store(false); );
130130
auto any_exec = get_next_executable(timeout);
131131
if (any_exec) {
132132
execute_any_executable(any_exec);

rclcpp/src/rclcpp/executors/multi_threaded_executor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ MultiThreadedExecutor::~MultiThreadedExecutor() {}
3838
void
3939
MultiThreadedExecutor::spin()
4040
{
41-
RCLCPP_SCOPE_EXIT(this->spinning.store(false); );
4241
if (spinning.exchange(true)) {
4342
throw std::runtime_error("spin() called while already spinning");
4443
}
44+
RCLCPP_SCOPE_EXIT(this->spinning.store(false); );
4545
std::vector<std::thread> threads;
4646
{
4747
std::lock_guard<std::mutex> wait_lock(wait_mutex_);

rclcpp/src/rclcpp/executors/single_threaded_executor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ SingleThreadedExecutor::~SingleThreadedExecutor() {}
2828
void
2929
SingleThreadedExecutor::spin()
3030
{
31-
RCLCPP_SCOPE_EXIT(this->spinning.store(false); );
3231
if (spinning.exchange(true)) {
3332
throw std::runtime_error("spin_some() called while already spinning");
3433
}
34+
RCLCPP_SCOPE_EXIT(this->spinning.store(false); );
3535
while (rclcpp::utilities::ok() && spinning.load()) {
3636
auto any_exec = get_next_executable();
3737
execute_any_executable(any_exec);

0 commit comments

Comments
 (0)