Skip to content

Commit e7afaa6

Browse files
jmachowinskiJanosch Machowinski
andauthored
fix(Executor): Fixed entities not beeing executed after just beeing added (#2724)
Fixes #2589 Signed-off-by: Janosch Machowinski <[email protected]> Co-authored-by: Janosch Machowinski <[email protected]>
1 parent 2d1b770 commit e7afaa6

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

rclcpp/src/rclcpp/executor.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,14 @@ Executor::spin_some_impl(std::chrono::nanoseconds max_duration, bool exhaustive)
371371
// both spin_some and spin_all wait for work at the beginning
372372
wait_result_.reset();
373373
wait_for_work(std::chrono::milliseconds(0));
374-
bool just_waited = true;
374+
bool entity_states_fully_polled = true;
375+
376+
if (entities_need_rebuild_) {
377+
// if the last wait triggered a collection rebuild, we need to call
378+
// wait_for_work once more, in order to do a collection rebuild and collect
379+
// events from the just added entities
380+
entity_states_fully_polled = false;
381+
}
375382

376383
// The logic of this while loop is as follows:
377384
//
@@ -393,12 +400,14 @@ Executor::spin_some_impl(std::chrono::nanoseconds max_duration, bool exhaustive)
393400
AnyExecutable any_exec;
394401
if (get_next_ready_executable(any_exec)) {
395402
execute_any_executable(any_exec);
396-
just_waited = false;
403+
// during the execution some entity might got ready therefore we need
404+
// to repoll the states of all entities
405+
entity_states_fully_polled = false;
397406
} else {
398407
// if nothing is ready, reset the result to clear it
399408
wait_result_.reset();
400409

401-
if (just_waited) {
410+
if (entity_states_fully_polled) {
402411
// there was no work after just waiting, always exit in this case
403412
// before the exhaustive condition can be checked
404413
break;
@@ -408,7 +417,13 @@ Executor::spin_some_impl(std::chrono::nanoseconds max_duration, bool exhaustive)
408417
// if exhaustive, wait for work again
409418
// this only happens for spin_all; spin_some only waits at the start
410419
wait_for_work(std::chrono::milliseconds(0));
411-
just_waited = true;
420+
entity_states_fully_polled = true;
421+
if (entities_need_rebuild_) {
422+
// if the last wait triggered a collection rebuild, we need to call
423+
// wait_for_work once more, in order to do a collection rebuild and
424+
// collect events from the just added entities
425+
entity_states_fully_polled = false;
426+
}
412427
} else {
413428
break;
414429
}

rclcpp/test/rclcpp/executors/test_executors_warmup.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,6 @@ TYPED_TEST(TestExecutorsWarmup, spin_all_doesnt_require_warmup_with_cbgroup)
9999
{
100100
using ExecutorType = TypeParam;
101101

102-
// TODO(alsora): Enable when https://github.com/ros2/rclcpp/pull/2595 gets merged
103-
if (
104-
std::is_same<ExecutorType, rclcpp::executors::SingleThreadedExecutor>() ||
105-
std::is_same<ExecutorType, rclcpp::executors::MultiThreadedExecutor>())
106-
{
107-
GTEST_SKIP();
108-
}
109-
110102
ExecutorType executor;
111103

112104
// Enable intra-process to guarantee deterministic and synchronous delivery of the message / event

0 commit comments

Comments
 (0)