15 #ifndef RCLCPP__STRATEGIES__ALLOCATOR_MEMORY_STRATEGY_HPP_ 16 #define RCLCPP__STRATEGIES__ALLOCATOR_MEMORY_STRATEGY_HPP_ 34 namespace memory_strategies
36 namespace allocator_memory_strategy
45 template<
typename Alloc = std::allocator<
void>>
56 allocator_ = std::make_shared<VoidAlloc>(*allocator.get());
61 allocator_ = std::make_shared<VoidAlloc>();
66 for (
const auto & existing_guard_condition : guard_conditions_) {
67 if (existing_guard_condition == guard_condition) {
71 guard_conditions_.push_back(guard_condition);
76 for (
auto it = guard_conditions_.begin(); it != guard_conditions_.end(); ++it) {
77 if (*it == guard_condition) {
78 guard_conditions_.erase(it);
86 subscription_handles_.clear();
87 service_handles_.clear();
88 client_handles_.clear();
89 timer_handles_.clear();
90 waitable_handles_.clear();
101 for (
size_t i = 0; i < subscription_handles_.size(); ++i) {
103 subscription_handles_[i].reset();
106 for (
size_t i = 0; i < service_handles_.size(); ++i) {
108 service_handles_[i].reset();
111 for (
size_t i = 0; i < client_handles_.size(); ++i) {
113 client_handles_[i].reset();
116 for (
size_t i = 0; i < timer_handles_.size(); ++i) {
117 if (!wait_set->
timers[i]) {
118 timer_handles_[i].reset();
121 for (
size_t i = 0; i < waitable_handles_.size(); ++i) {
122 if (!waitable_handles_[i]->is_ready(wait_set)) {
123 waitable_handles_[i].reset();
127 subscription_handles_.erase(
128 std::remove(subscription_handles_.begin(), subscription_handles_.end(),
nullptr),
129 subscription_handles_.end()
132 service_handles_.erase(
133 std::remove(service_handles_.begin(), service_handles_.end(),
nullptr),
134 service_handles_.end()
137 client_handles_.erase(
138 std::remove(client_handles_.begin(), client_handles_.end(),
nullptr),
139 client_handles_.end()
142 timer_handles_.erase(
143 std::remove(timer_handles_.begin(), timer_handles_.end(),
nullptr),
147 waitable_handles_.erase(
148 std::remove(waitable_handles_.begin(), waitable_handles_.end(),
nullptr),
149 waitable_handles_.end()
155 bool has_invalid_weak_nodes =
false;
156 for (
auto & weak_node : weak_nodes) {
157 auto node = weak_node.lock();
159 has_invalid_weak_nodes =
true;
162 for (
auto & weak_group : node->get_callback_groups()) {
163 auto group = weak_group.lock();
164 if (!group || !group->can_be_taken_from().load()) {
167 group->find_subscription_ptrs_if(
169 subscription_handles_.push_back(subscription->get_subscription_handle());
174 service_handles_.push_back(service->get_service_handle());
178 client_handles_.push_back(client->get_client_handle());
182 timer_handles_.push_back(timer->get_timer_handle());
186 waitable_handles_.push_back(waitable);
191 return has_invalid_weak_nodes;
196 for (
auto subscription : subscription_handles_) {
205 for (
auto client : client_handles_) {
214 for (
auto service : service_handles_) {
223 for (
auto timer : timer_handles_) {
232 for (
auto guard_condition : guard_conditions_) {
236 "Couldn't add guard_condition to wait set: %s",
242 for (
auto waitable : waitable_handles_) {
243 if (!waitable->add_to_wait_set(wait_set)) {
258 auto it = subscription_handles_.begin();
259 while (it != subscription_handles_.end()) {
267 it = subscription_handles_.erase(it);
270 if (!group->can_be_taken_from().load()) {
280 subscription_handles_.erase(it);
284 it = subscription_handles_.erase(it);
293 auto it = service_handles_.begin();
294 while (it != service_handles_.end()) {
302 it = service_handles_.erase(it);
305 if (!group->can_be_taken_from().load()) {
315 service_handles_.erase(it);
319 it = service_handles_.erase(it);
326 auto it = client_handles_.begin();
327 while (it != client_handles_.end()) {
335 it = client_handles_.erase(it);
338 if (!group->can_be_taken_from().load()) {
348 client_handles_.erase(it);
352 it = client_handles_.erase(it);
361 auto it = timer_handles_.begin();
362 while (it != timer_handles_.end()) {
370 it = timer_handles_.erase(it);
373 if (!group->can_be_taken_from().load()) {
380 any_exec.
timer = timer;
383 timer_handles_.erase(it);
387 it = timer_handles_.erase(it);
394 auto it = waitable_handles_.begin();
395 while (it != waitable_handles_.end()) {
403 it = waitable_handles_.erase(it);
406 if (!group->can_be_taken_from().load()) {
416 waitable_handles_.erase(it);
420 it = waitable_handles_.erase(it);
426 return rclcpp::allocator::get_rcl_allocator<void *, VoidAlloc>(*allocator_.
get());
431 size_t number_of_subscriptions = subscription_handles_.size();
432 for (
auto waitable : waitable_handles_) {
433 number_of_subscriptions += waitable->get_number_of_ready_subscriptions();
435 return number_of_subscriptions;
440 size_t number_of_services = service_handles_.size();
441 for (
auto waitable : waitable_handles_) {
442 number_of_services += waitable->get_number_of_ready_services();
444 return number_of_services;
449 size_t number_of_events = 0;
450 for (
auto waitable : waitable_handles_) {
451 number_of_events += waitable->get_number_of_ready_events();
453 return number_of_events;
458 size_t number_of_clients = client_handles_.size();
459 for (
auto waitable : waitable_handles_) {
460 number_of_clients += waitable->get_number_of_ready_clients();
462 return number_of_clients;
468 for (
auto waitable : waitable_handles_) {
469 number_of_guard_conditions += waitable->get_number_of_ready_guard_conditions();
476 size_t number_of_timers = timer_handles_.size();
477 for (
auto waitable : waitable_handles_) {
478 number_of_timers += waitable->get_number_of_ready_timers();
480 return number_of_timers;
485 return waitable_handles_.size();
508 #endif // RCLCPP__STRATEGIES__ALLOCATOR_MEMORY_STRATEGY_HPP_ #define rcl_get_error_string
const rcl_service_t ** services
rclcpp::ServiceBase::SharedPtr service
Definition: any_executable.hpp:46
rclcpp::node_interfaces::NodeBaseInterface::SharedPtr node_base
Definition: any_executable.hpp:51
Delegate for handling memory allocations while the Executor is executing.
Definition: memory_strategy.hpp:41
rclcpp::Waitable::SharedPtr waitable
Definition: any_executable.hpp:48
size_t number_of_guard_conditions() const
Definition: allocator_memory_strategy.hpp:465
rclcpp::TimerBase::SharedPtr timer
Definition: any_executable.hpp:45
Definition: any_executable.hpp:35
virtual rcl_allocator_t get_allocator()
Definition: allocator_memory_strategy.hpp:424
This header provides the get_node_base_interface() template function.
Definition: allocator_common.hpp:24
rclcpp::ClientBase::SharedPtr client
Definition: any_executable.hpp:47
size_t number_of_ready_subscriptions() const
Definition: allocator_memory_strategy.hpp:429
size_t number_of_ready_services() const
Definition: allocator_memory_strategy.hpp:438
const rcl_client_t ** clients
AllocatorMemoryStrategy()
Definition: allocator_memory_strategy.hpp:59
bool collect_entities(const WeakNodeList &weak_nodes)
Definition: allocator_memory_strategy.hpp:153
typename VoidAllocTraits::allocator_type VoidAlloc
Definition: allocator_memory_strategy.hpp:52
const rcl_timer_t ** timers
virtual void get_next_service(executor::AnyExecutable &any_exec, const WeakNodeList &weak_nodes)
Definition: allocator_memory_strategy.hpp:289
rclcpp::SubscriptionBase::SharedPtr subscription
Definition: any_executable.hpp:44
typename std::allocator_traits< Alloc >::template rebind_traits< T > AllocRebind
Definition: allocator_common.hpp:30
virtual void get_next_waitable(executor::AnyExecutable &any_exec, const WeakNodeList &weak_nodes)
Definition: allocator_memory_strategy.hpp:392
static rclcpp::node_interfaces::NodeBaseInterface::SharedPtr get_node_by_group(rclcpp::callback_group::CallbackGroup::SharedPtr group, const WeakNodeList &weak_nodes)
#define RCLCPP_SMART_PTR_DEFINITIONS(...)
Definition: macros.hpp:36
virtual void get_next_client(executor::AnyExecutable &any_exec, const WeakNodeList &weak_nodes)
Definition: allocator_memory_strategy.hpp:324
virtual void get_next_subscription(executor::AnyExecutable &any_exec, const WeakNodeList &weak_nodes)
Definition: allocator_memory_strategy.hpp:254
void add_guard_condition(const rcl_guard_condition_t *guard_condition)
Definition: allocator_memory_strategy.hpp:64
static rclcpp::callback_group::CallbackGroup::SharedPtr get_group_by_waitable(rclcpp::Waitable::SharedPtr waitable, const WeakNodeList &weak_nodes)
static rclcpp::TimerBase::SharedPtr get_timer_by_handle(std::shared_ptr< const rcl_timer_t > timer_handle, const WeakNodeList &weak_nodes)
rcl_ret_t rcl_wait_set_add_timer(rcl_wait_set_t *wait_set, const rcl_timer_t *timer, size_t *index)
static rclcpp::callback_group::CallbackGroup::SharedPtr get_group_by_client(rclcpp::ClientBase::SharedPtr client, const WeakNodeList &weak_nodes)
size_t number_of_ready_clients() const
Definition: allocator_memory_strategy.hpp:456
typename allocator::AllocRebind< void *, Alloc > VoidAllocTraits
Definition: allocator_memory_strategy.hpp:51
rcl_ret_t rcl_wait_set_add_service(rcl_wait_set_t *wait_set, const rcl_service_t *service, size_t *index)
#define RCUTILS_LOG_ERROR_NAMED(name,...)
rclcpp::callback_group::CallbackGroup::SharedPtr callback_group
Definition: any_executable.hpp:50
virtual void remove_null_handles(rcl_wait_set_t *wait_set)
Definition: allocator_memory_strategy.hpp:93
static rclcpp::callback_group::CallbackGroup::SharedPtr get_group_by_service(rclcpp::ServiceBase::SharedPtr service, const WeakNodeList &weak_nodes)
void remove_guard_condition(const rcl_guard_condition_t *guard_condition)
Definition: allocator_memory_strategy.hpp:74
Set the data type used in the intra-process buffer as std::shared_ptr<MessageT>
void clear_handles()
Definition: allocator_memory_strategy.hpp:84
static rclcpp::callback_group::CallbackGroup::SharedPtr get_group_by_subscription(rclcpp::SubscriptionBase::SharedPtr subscription, const WeakNodeList &weak_nodes)
static rclcpp::SubscriptionBase::SharedPtr get_subscription_by_handle(std::shared_ptr< const rcl_subscription_t > subscriber_handle, const WeakNodeList &weak_nodes)
static rclcpp::callback_group::CallbackGroup::SharedPtr get_group_by_timer(rclcpp::TimerBase::SharedPtr timer, const WeakNodeList &weak_nodes)
rcl_ret_t rcl_wait_set_add_subscription(rcl_wait_set_t *wait_set, const rcl_subscription_t *subscription, size_t *index)
size_t number_of_waitables() const
Definition: allocator_memory_strategy.hpp:483
rcl_ret_t rcl_wait_set_add_client(rcl_wait_set_t *wait_set, const rcl_client_t *client, size_t *index)
virtual void get_next_timer(executor::AnyExecutable &any_exec, const WeakNodeList &weak_nodes)
Definition: allocator_memory_strategy.hpp:357
static rclcpp::ServiceBase::SharedPtr get_service_by_handle(std::shared_ptr< const rcl_service_t > service_handle, const WeakNodeList &weak_nodes)
static rclcpp::ClientBase::SharedPtr get_client_by_handle(std::shared_ptr< const rcl_client_t > client_handle, const WeakNodeList &weak_nodes)
size_t number_of_ready_timers() const
Definition: allocator_memory_strategy.hpp:474
size_t number_of_ready_events() const
Definition: allocator_memory_strategy.hpp:447
bool add_handles_to_wait_set(rcl_wait_set_t *wait_set)
Definition: allocator_memory_strategy.hpp:194
Delegate for handling memory allocations while the Executor is executing.
Definition: allocator_memory_strategy.hpp:46
const rcl_subscription_t ** subscriptions
rcl_ret_t rcl_wait_set_add_guard_condition(rcl_wait_set_t *wait_set, const rcl_guard_condition_t *guard_condition, size_t *index)