Skip to content

Commit 86291f8

Browse files
committed
Backport workaround for reinitialized timers from upstream
1 parent 2253510 commit 86291f8

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

rclcpp/include/rclcpp/executors/executor_entities_collection.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ struct ExecutorEntitiesCollection
178178

179179
/// Clear the entities collection
180180
void clear();
181+
182+
/// Remove entities that have expired weak ownership
183+
/**
184+
* \return The total number of removed entities
185+
*/
186+
size_t remove_expired_entities();
181187
};
182188

183189
/// Build an entities collection from callback groups

rclcpp/src/rclcpp/executors/executor_entities_collection.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,30 @@ void ExecutorEntitiesCollection::clear()
3939
waitables.clear();
4040
}
4141

42+
size_t ExecutorEntitiesCollection::remove_expired_entities()
43+
{
44+
auto remove_entities = [](auto & collection) -> size_t {
45+
size_t removed = 0;
46+
for (auto it = collection.begin(); it != collection.end(); ) {
47+
if (it->second.entity.expired()) {
48+
++removed;
49+
it = collection.erase(it);
50+
} else {
51+
++it;
52+
}
53+
}
54+
return removed;
55+
};
56+
57+
return
58+
remove_entities(subscriptions) +
59+
remove_entities(timers) +
60+
remove_entities(guard_conditions) +
61+
remove_entities(clients) +
62+
remove_entities(services) +
63+
remove_entities(waitables);
64+
}
65+
4266
void
4367
build_entities_collection(
4468
const std::vector<rclcpp::CallbackGroup::WeakPtr> & callback_groups,

rclcpp/src/rclcpp/experimental/executors/events_executor/events_executor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@ EventsExecutor::refresh_current_collection(
431431
// Acquire lock before modifying the current collection
432432
std::lock_guard<std::recursive_mutex> lock(collection_mutex_);
433433

434+
current_entities_collection_->remove_expired_entities();
435+
434436
current_entities_collection_->timers.update(
435437
new_collection.timers,
436438
[this](rclcpp::TimerBase::SharedPtr timer) {timers_manager_->add_timer(timer);},

0 commit comments

Comments
 (0)