Skip to content

Commit

Permalink
fix(StaticSingleThreadedExecutor): Fixed regression in spin()
Browse files Browse the repository at this point in the history
Signed-off-by: Janosch Machowinski <[email protected]>
  • Loading branch information
Janosch Machowinski committed Apr 2, 2024
1 parent f510db1 commit bb36ebb
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions rclcpp/src/rclcpp/executors/static_single_threaded_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,19 @@ StaticSingleThreadedExecutor::spin()
}
RCPPUTILS_SCOPE_EXIT(this->spinning.store(false); );

// This is essentially the contents of the rclcpp::Executor::wait_for_work method,
// except we need to keep the wait result to reproduce the StaticSingleThreadedExecutor
// behavior.
while (rclcpp::ok(this->context_) && spinning.load()) {
this->spin_once_impl(std::chrono::nanoseconds(-1));
while (rclcpp::ok(context_) && spinning.load()) {
// Get executables that are ready now
std::lock_guard<std::mutex> guard(mutex_);

// wait forever until the wait returns
auto wait_result = this->collect_and_wait(std::chrono::nanoseconds(-1));
if (wait_result.has_value()) {
// Execute ready executables
this->execute_ready_executables(
current_collection_,
wait_result.value(),
false);
}
}
}

Expand Down

0 comments on commit bb36ebb

Please sign in to comment.