Skip to content

Commit 06f99cc

Browse files
mjcarrollJanosch Machowinski
andcommitted
Fix callback group logic in executor
Signed-off-by: Michael Carroll <[email protected]> Co-authored-by: Janosch Machowinski <[email protected]>
1 parent 03929e7 commit 06f99cc

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

rclcpp/src/rclcpp/executor.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,8 @@ Executor::get_next_ready_executable(AnyExecutable & any_executable)
689689
auto entity_iter = current_collection_.timers.find(timer->get_timer_handle().get());
690690
if (entity_iter != current_collection_.timers.end()) {
691691
auto callback_group = entity_iter->second.callback_group.lock();
692-
if (callback_group && !callback_group->can_be_taken_from()) {
692+
if (!callback_group || !callback_group->can_be_taken_from()) {
693+
current_timer_index++;
693694
continue;
694695
}
695696
// At this point the timer is either ready for execution or was perhaps
@@ -699,6 +700,7 @@ Executor::get_next_ready_executable(AnyExecutable & any_executable)
699700
wait_result_->clear_timer_with_index(current_timer_index);
700701
// Check that the timer should be called still, i.e. it wasn't canceled.
701702
if (!timer->call()) {
703+
current_timer_index++;
702704
continue;
703705
}
704706
any_executable.timer = timer;
@@ -715,7 +717,7 @@ Executor::get_next_ready_executable(AnyExecutable & any_executable)
715717
subscription->get_subscription_handle().get());
716718
if (entity_iter != current_collection_.subscriptions.end()) {
717719
auto callback_group = entity_iter->second.callback_group.lock();
718-
if (callback_group && !callback_group->can_be_taken_from()) {
720+
if (!callback_group || !callback_group->can_be_taken_from()) {
719721
continue;
720722
}
721723
any_executable.subscription = subscription;
@@ -731,7 +733,7 @@ Executor::get_next_ready_executable(AnyExecutable & any_executable)
731733
auto entity_iter = current_collection_.services.find(service->get_service_handle().get());
732734
if (entity_iter != current_collection_.services.end()) {
733735
auto callback_group = entity_iter->second.callback_group.lock();
734-
if (callback_group && !callback_group->can_be_taken_from()) {
736+
if (!callback_group || !callback_group->can_be_taken_from()) {
735737
continue;
736738
}
737739
any_executable.service = service;
@@ -747,7 +749,7 @@ Executor::get_next_ready_executable(AnyExecutable & any_executable)
747749
auto entity_iter = current_collection_.clients.find(client->get_client_handle().get());
748750
if (entity_iter != current_collection_.clients.end()) {
749751
auto callback_group = entity_iter->second.callback_group.lock();
750-
if (callback_group && !callback_group->can_be_taken_from()) {
752+
if (!callback_group || !callback_group->can_be_taken_from()) {
751753
continue;
752754
}
753755
any_executable.client = client;
@@ -763,7 +765,7 @@ Executor::get_next_ready_executable(AnyExecutable & any_executable)
763765
auto entity_iter = current_collection_.waitables.find(waitable.get());
764766
if (entity_iter != current_collection_.waitables.end()) {
765767
auto callback_group = entity_iter->second.callback_group.lock();
766-
if (callback_group && !callback_group->can_be_taken_from()) {
768+
if (!callback_group || !callback_group->can_be_taken_from()) {
767769
continue;
768770
}
769771
any_executable.waitable = waitable;
@@ -782,7 +784,6 @@ Executor::get_next_ready_executable(AnyExecutable & any_executable)
782784
}
783785
}
784786

785-
786787
return valid_executable;
787788
}
788789

rclcpp/src/rclcpp/executors/executor_entities_collection.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ ready_executables(
153153
continue;
154154
}
155155
auto group_info = group_cache(entity_iter->second.callback_group);
156-
if (group_info && !group_info->can_be_taken_from().load()) {
156+
if (!group_info || !group_info->can_be_taken_from().load()) {
157157
continue;
158158
}
159159
if (!entity->call()) {
@@ -176,7 +176,7 @@ ready_executables(
176176
continue;
177177
}
178178
auto group_info = group_cache(entity_iter->second.callback_group);
179-
if (group_info && !group_info->can_be_taken_from().load()) {
179+
if (!group_info || !group_info->can_be_taken_from().load()) {
180180
continue;
181181
}
182182
rclcpp::AnyExecutable exec;
@@ -196,7 +196,7 @@ ready_executables(
196196
continue;
197197
}
198198
auto group_info = group_cache(entity_iter->second.callback_group);
199-
if (group_info && !group_info->can_be_taken_from().load()) {
199+
if (!group_info || !group_info->can_be_taken_from().load()) {
200200
continue;
201201
}
202202
rclcpp::AnyExecutable exec;
@@ -216,7 +216,7 @@ ready_executables(
216216
continue;
217217
}
218218
auto group_info = group_cache(entity_iter->second.callback_group);
219-
if (group_info && !group_info->can_be_taken_from().load()) {
219+
if (!group_info || !group_info->can_be_taken_from().load()) {
220220
continue;
221221
}
222222
rclcpp::AnyExecutable exec;
@@ -236,7 +236,7 @@ ready_executables(
236236
continue;
237237
}
238238
auto group_info = group_cache(entry.callback_group);
239-
if (group_info && !group_info->can_be_taken_from().load()) {
239+
if (!group_info || !group_info->can_be_taken_from().load()) {
240240
continue;
241241
}
242242
rclcpp::AnyExecutable exec;

0 commit comments

Comments
 (0)