Skip to content

Commit c5a13d5

Browse files
Janosch MachowinskiJanosch Machowinski
Janosch Machowinski
authored and
Janosch Machowinski
committed
fix(Executor): Fixed lost of entities rebuild request
Signed-off-by: Janosch Machowinski <[email protected]>
1 parent 760dae2 commit c5a13d5

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

Diff for: rclcpp/src/rclcpp/executor.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void Executor::trigger_entity_recollect(bool notify)
123123
{
124124
this->entities_need_rebuild_.store(true);
125125

126-
if (!spinning.load()) {
126+
if (!spinning.load() && entities_need_rebuild_.exchange(false)) {
127127
std::lock_guard<std::mutex> guard(mutex_);
128128
this->collect_entities();
129129
}
@@ -387,9 +387,7 @@ Executor::execute_any_executable(AnyExecutable & any_exec)
387387
}
388388

389389
// Reset the callback_group, regardless of type
390-
if (any_exec.callback_group) {
391-
any_exec.callback_group->can_be_taken_from().store(true);
392-
}
390+
any_exec.callback_group->can_be_taken_from().store(true);
393391
}
394392

395393
template<typename Taker, typename Handler>
@@ -626,7 +624,6 @@ Executor::collect_entities()
626624
// In the case that an entity already has an expired weak pointer
627625
// before being removed from the waitset, additionally prune the waitset.
628626
this->wait_set_.prune_deleted_entities();
629-
this->entities_need_rebuild_.store(false);
630627
}
631628

632629
void
@@ -639,7 +636,7 @@ Executor::wait_for_work(std::chrono::nanoseconds timeout)
639636

640637
{
641638
std::lock_guard<std::mutex> guard(mutex_);
642-
if (current_collection_.empty() || this->entities_need_rebuild_.load()) {
639+
if (this->entities_need_rebuild_.exchange(false) || current_collection_.empty()) {
643640
this->collect_entities();
644641
}
645642
}

Diff for: rclcpp/src/rclcpp/executors/static_single_threaded_executor.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ StaticSingleThreadedExecutor::spin_once_impl(std::chrono::nanoseconds timeout)
110110
std::optional<rclcpp::WaitResult<rclcpp::WaitSet>>
111111
StaticSingleThreadedExecutor::collect_and_wait(std::chrono::nanoseconds timeout)
112112
{
113-
if (current_collection_.empty() || this->entities_need_rebuild_.load()) {
113+
if (this->entities_need_rebuild_.exchange(false) || current_collection_.empty()) {
114114
this->collect_entities();
115115
}
116116
auto wait_result = wait_set_.wait(std::chrono::nanoseconds(timeout));

0 commit comments

Comments
 (0)