Skip to content

Commit 2a88295

Browse files
committed
fix bug in StaticSTE that broke the add callback groups to executor tests
Signed-off-by: William Woodall <[email protected]>
1 parent 836946e commit 2a88295

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

rclcpp/src/rclcpp/executor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ Executor::Executor(const rclcpp::ExecutorOptions & options)
7272
}
7373
});
7474

75+
notify_waitable_->set_on_ready_callback([this](auto, auto) {
76+
this->entities_need_rebuild_.store(true);
77+
});
78+
7579
notify_waitable_->add_guard_condition(interrupt_guard_condition_);
7680
notify_waitable_->add_guard_condition(shutdown_guard_condition_);
7781
}

rclcpp/src/rclcpp/executors/executor_entities_collector.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ ExecutorEntitiesCollector::~ExecutorEntitiesCollector()
6161
if (group_ptr) {
6262
group_ptr->get_associated_with_executor_atomic().store(false);
6363
}
64+
// Disassociate the guard condition from the executor notify waitable
65+
auto guard_condition_it = weak_groups_to_guard_conditions_.find(weak_group_ptr);
66+
if (guard_condition_it != weak_groups_to_guard_conditions_.end()) {
67+
this->notify_waitable_->remove_guard_condition(guard_condition_it->second);
68+
weak_groups_to_guard_conditions_.erase(guard_condition_it);
69+
}
6470
}
6571
pending_manually_added_groups_.clear();
6672
pending_manually_removed_groups_.clear();
@@ -144,6 +150,11 @@ ExecutorEntitiesCollector::add_callback_group(rclcpp::CallbackGroup::SharedPtr g
144150
}
145151

146152
this->pending_manually_added_groups_.insert(group_ptr);
153+
154+
// Store callback group notify guard condition in map and add it to the notify waitable
155+
auto group_guard_condition = group_ptr->get_notify_guard_condition();
156+
weak_groups_to_guard_conditions_.insert({group_ptr, group_guard_condition});
157+
this->notify_waitable_->add_guard_condition(group_guard_condition);
147158
}
148159

149160
void
@@ -341,6 +352,13 @@ ExecutorEntitiesCollector::process_queues()
341352
auto group_ptr = weak_group_ptr.lock();
342353
if (group_ptr) {
343354
this->add_callback_group_to_collection(group_ptr, manually_added_groups_);
355+
} else {
356+
// Disassociate the guard condition from the executor notify waitable
357+
auto guard_condition_it = weak_groups_to_guard_conditions_.find(weak_group_ptr);
358+
if (guard_condition_it != weak_groups_to_guard_conditions_.end()) {
359+
this->notify_waitable_->remove_guard_condition(guard_condition_it->second);
360+
weak_groups_to_guard_conditions_.erase(guard_condition_it);
361+
}
344362
}
345363
}
346364
pending_manually_added_groups_.clear();

rclcpp/src/rclcpp/executors/static_single_threaded_executor.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// limitations under the License.
1414

1515
#include "rclcpp/executors/executor_entities_collection.hpp"
16-
#include "rclcpp/executors/executor_notify_waitable.hpp"
1716
#include "rcpputils/scope_exit.hpp"
1817

1918
#include "rclcpp/executors/static_single_threaded_executor.hpp"

rclcpp/test/rclcpp/test_add_callback_groups_to_executor.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,18 +200,25 @@ TYPED_TEST(TestAddCallbackGroupsToExecutor, add_callback_groups_after_add_node_t
200200
{
201201
using ExecutorType = TypeParam;
202202

203+
auto count_callback_groups_in_node = [](auto node) {
204+
size_t num = 0;
205+
node->get_node_base_interface()->for_each_callback_group([&num](auto) {
206+
num++;
207+
});
208+
return num;
209+
};
210+
203211
ExecutorType executor;
204212
auto node = std::make_shared<rclcpp::Node>("my_node", "/ns");
205213
executor.add_node(node->get_node_base_interface());
206-
ASSERT_EQ(executor.get_all_callback_groups().size(), 1u);
214+
ASSERT_EQ(executor.get_all_callback_groups().size(), count_callback_groups_in_node(node));
207215
std::atomic_size_t timer_count {0};
208216
auto timer_callback = [&executor, &timer_count]() {
209-
printf("in timer_callback(%zu)\n", timer_count.load());
210-
if (timer_count > 0) {
211-
ASSERT_GT(executor.get_all_callback_groups().size(), 1u);
217+
auto cur_timer_count = timer_count++;
218+
printf("in timer_callback(%zu)\n", cur_timer_count);
219+
if (cur_timer_count > 0) {
212220
executor.cancel();
213221
}
214-
timer_count++;
215222
};
216223
rclcpp::CallbackGroup::SharedPtr cb_grp = node->create_callback_group(
217224
rclcpp::CallbackGroupType::MutuallyExclusive);

0 commit comments

Comments
 (0)