only set scope exit after it was determined that spinning was changed to true
This commit is contained in:
parent
f1e7ea5ca0
commit
1c9eb0b367
3 changed files with 4 additions and 4 deletions
|
@ -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);
|
||||
|
|
|
@ -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<std::thread> threads;
|
||||
{
|
||||
std::lock_guard<std::mutex> wait_lock(wait_mutex_);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue