CallbackGroup keeps now WeakPtrs to Services. (#261)
It was not possible to shutdown a service when there was a shared pointer preventing destructor from being called.
This commit is contained in:
parent
a71ce25a5a
commit
d158dd46db
4 changed files with 11 additions and 8 deletions
|
@ -63,7 +63,7 @@ public:
|
||||||
get_timer_ptrs() const;
|
get_timer_ptrs() const;
|
||||||
|
|
||||||
RCLCPP_PUBLIC
|
RCLCPP_PUBLIC
|
||||||
const std::vector<rclcpp::service::ServiceBase::SharedPtr> &
|
const std::vector<rclcpp::service::ServiceBase::WeakPtr> &
|
||||||
get_service_ptrs() const;
|
get_service_ptrs() const;
|
||||||
|
|
||||||
RCLCPP_PUBLIC
|
RCLCPP_PUBLIC
|
||||||
|
@ -102,7 +102,7 @@ private:
|
||||||
mutable std::mutex mutex_;
|
mutable std::mutex mutex_;
|
||||||
std::vector<rclcpp::subscription::SubscriptionBase::WeakPtr> subscription_ptrs_;
|
std::vector<rclcpp::subscription::SubscriptionBase::WeakPtr> subscription_ptrs_;
|
||||||
std::vector<rclcpp::timer::TimerBase::WeakPtr> timer_ptrs_;
|
std::vector<rclcpp::timer::TimerBase::WeakPtr> timer_ptrs_;
|
||||||
std::vector<rclcpp::service::ServiceBase::SharedPtr> service_ptrs_;
|
std::vector<rclcpp::service::ServiceBase::WeakPtr> service_ptrs_;
|
||||||
std::vector<rclcpp::client::ClientBase::WeakPtr> client_ptrs_;
|
std::vector<rclcpp::client::ClientBase::WeakPtr> client_ptrs_;
|
||||||
std::atomic_bool can_be_taken_from_;
|
std::atomic_bool can_be_taken_from_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -162,7 +162,8 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto & service : group->get_service_ptrs()) {
|
for (auto & weak_service : group->get_service_ptrs()) {
|
||||||
|
auto service = weak_service.lock();
|
||||||
if (service) {
|
if (service) {
|
||||||
service_handles_.push_back(service->get_service_handle());
|
service_handles_.push_back(service->get_service_handle());
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ CallbackGroup::get_timer_ptrs() const
|
||||||
return timer_ptrs_;
|
return timer_ptrs_;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<rclcpp::service::ServiceBase::SharedPtr> &
|
const std::vector<rclcpp::service::ServiceBase::WeakPtr> &
|
||||||
CallbackGroup::get_service_ptrs() const
|
CallbackGroup::get_service_ptrs() const
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
|
|
@ -60,8 +60,9 @@ MemoryStrategy::get_service_by_handle(const rcl_service_t * service_handle,
|
||||||
if (!group) {
|
if (!group) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (auto & service : group->get_service_ptrs()) {
|
for (auto & weak_service : group->get_service_ptrs()) {
|
||||||
if (service->get_service_handle() == service_handle) {
|
auto service = weak_service.lock();
|
||||||
|
if (service && service->get_service_handle() == service_handle) {
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,8 +159,9 @@ MemoryStrategy::get_group_by_service(
|
||||||
if (!group) {
|
if (!group) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (auto & serv : group->get_service_ptrs()) {
|
for (auto & weak_serv : group->get_service_ptrs()) {
|
||||||
if (serv == service) {
|
auto serv = weak_serv.lock();
|
||||||
|
if (serv && serv == service) {
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue