@@ -120,8 +120,8 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
120120 }
121121 }
122122 for (size_t i = 0 ; i < waitable_handles_.size (); ++i) {
123- if (! waitable_handles_[i]->is_ready (wait_set)) {
124- waitable_handles_[i]. reset ( );
123+ if (waitable_handles_[i]->is_ready (wait_set)) {
124+ waitable_triggered_handles_. emplace_back ( waitable_handles_[i]);
125125 }
126126 }
127127
@@ -145,10 +145,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
145145 timer_handles_.end ()
146146 );
147147
148- waitable_handles_.erase (
149- std::remove (waitable_handles_.begin (), waitable_handles_.end (), nullptr ),
150- waitable_handles_.end ()
151- );
148+ waitable_handles_.clear ();
152149 }
153150
154151 bool collect_entities (const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) override
@@ -392,16 +389,18 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
392389 rclcpp::AnyExecutable & any_exec,
393390 const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) override
394391 {
395- auto it = waitable_handles_.begin ();
396- while (it != waitable_handles_.end ()) {
397- std::shared_ptr<Waitable> & waitable = *it;
392+ auto & waitable_handles =
393+ waitable_triggered_handles_.empty () ? waitable_handles_ : waitable_triggered_handles_;
394+ auto it = waitable_handles.begin ();
395+ while (it != waitable_handles.end ()) {
396+ std::shared_ptr<Waitable> waitable = *it;
398397 if (waitable) {
399398 // Find the group for this handle and see if it can be serviced
400399 auto group = get_group_by_waitable (waitable, weak_groups_to_nodes);
401400 if (!group) {
402401 // Group was not found, meaning the waitable is not valid...
403402 // Remove it from the ready list and continue looking
404- it = waitable_handles_ .erase (it);
403+ it = waitable_handles .erase (it);
405404 continue ;
406405 }
407406 if (!group->can_be_taken_from ().load ()) {
@@ -414,11 +413,11 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
414413 any_exec.waitable = waitable;
415414 any_exec.callback_group = group;
416415 any_exec.node_base = get_node_by_group (group, weak_groups_to_nodes);
417- waitable_handles_ .erase (it);
416+ waitable_handles .erase (it);
418417 return ;
419418 }
420419 // Else, the waitable is no longer valid, remove it and continue
421- it = waitable_handles_ .erase (it);
420+ it = waitable_handles .erase (it);
422421 }
423422 }
424423
@@ -499,6 +498,8 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
499498 VectorRebind<std::shared_ptr<const rcl_timer_t >> timer_handles_;
500499 VectorRebind<std::shared_ptr<Waitable>> waitable_handles_;
501500
501+ VectorRebind<std::shared_ptr<Waitable>> waitable_triggered_handles_;
502+
502503 std::shared_ptr<VoidAlloc> allocator_;
503504};
504505
0 commit comments