Skip to content

Commit

Permalink
Add new conditional variable to have unexpected behavior when working…
Browse files Browse the repository at this point in the history
… between threads
  • Loading branch information
saikishor committed Apr 22, 2024
1 parent 0856453 commit 2f7bbc2
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class AsyncFunctionHandler
if (is_running())
{
std::unique_lock<std::mutex> lock(async_mtx_);
async_update_condition_.wait(lock, [this] { return !trigger_in_progress_; });
cycle_end_condition_.wait(lock, [this] { return !trigger_in_progress_; });
}
}

Expand Down Expand Up @@ -218,13 +218,14 @@ class AsyncFunctionHandler
lock, [this] { return trigger_in_progress_ || async_update_stop_; });
if (async_update_stop_)
{
async_update_condition_.notify_one();
trigger_in_progress_ = false;
cycle_end_condition_.notify_one();
break;
}
async_update_return_ = async_function_(current_update_time_, current_update_period_);
trigger_in_progress_ = false;
}
async_update_condition_.notify_one();
cycle_end_condition_.notify_one();
}
});
}
Expand All @@ -242,6 +243,7 @@ class AsyncFunctionHandler
std::atomic_bool trigger_in_progress_{false};
std::atomic<T> async_update_return_;
std::condition_variable async_update_condition_;
std::condition_variable cycle_end_condition_;
std::mutex async_mtx_;
};
} // namespace ros2_control
Expand Down

0 comments on commit 2f7bbc2

Please sign in to comment.