Skip to content

Commit ad64f8a

Browse files
committed
Deprecate AllocatorMemoryStrategy
Mark AllocatorMemoryStrategy as deprecated, as they have become dead code following the double-buffering changes in the executor. - Add [[deprecated]] attributes to classes and methods. - Add macros to silence test warnings Signed-off-by: Scott Duncan <scott.duncan.work@gmail.com>
1 parent 87be5fb commit ad64f8a

File tree

1 file changed

+70
-63
lines changed

1 file changed

+70
-63
lines changed

rclcpp/include/rclcpp/strategies/allocator_memory_strategy.hpp

Lines changed: 70 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@
1919
#include <vector>
2020

2121
#include "rcl/allocator.h"
22-
2322
#include "rclcpp/allocator/allocator_common.hpp"
2423
#include "rclcpp/detail/add_guard_condition_to_rcl_wait_set.hpp"
2524
#include "rclcpp/memory_strategy.hpp"
2625
#include "rclcpp/node.hpp"
2726
#include "rclcpp/visibility_control.hpp"
28-
2927
#include "rcutils/logging_macros.h"
30-
3128
#include "rmw/types.h"
3229

3330
namespace rclcpp
@@ -43,25 +40,36 @@ namespace allocator_memory_strategy
4340
* the rmw implementation after the executor waits for work, based on the number of entities that
4441
* come through.
4542
*/
46-
template<typename Alloc = std::allocator<void>>
47-
class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
43+
template <typename Alloc = std::allocator<void>>
44+
class [[deprecated("Changes executor leave this Class deprecated.")]] AllocatorMemoryStrategy
45+
: public memory_strategy::MemoryStrategy
4846
{
4947
public:
48+
#if !defined(_WIN32)
49+
#pragma GCC diagnostic push
50+
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
51+
#else // !defined(_WIN32)
52+
#pragma warning(push)
53+
#pragma warning(disable : 4996)
54+
#endif
5055
RCLCPP_SMART_PTR_DEFINITIONS(AllocatorMemoryStrategy<Alloc>)
5156

5257
using VoidAllocTraits = typename allocator::AllocRebind<void *, Alloc>;
5358
using VoidAlloc = typename VoidAllocTraits::allocator_type;
5459

60+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
5561
explicit AllocatorMemoryStrategy(std::shared_ptr<Alloc> allocator)
5662
{
5763
allocator_ = std::make_shared<VoidAlloc>(*allocator.get());
5864
}
5965

66+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
6067
AllocatorMemoryStrategy()
6168
{
6269
allocator_ = std::make_shared<VoidAlloc>();
6370
}
6471

72+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
6573
void add_guard_condition(const rclcpp::GuardCondition & guard_condition) override
6674
{
6775
for (const auto & existing_guard_condition : guard_conditions_) {
@@ -72,6 +80,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
7280
guard_conditions_.push_back(&guard_condition);
7381
}
7482

83+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
7584
void remove_guard_condition(const rclcpp::GuardCondition * guard_condition) override
7685
{
7786
for (auto it = guard_conditions_.begin(); it != guard_conditions_.end(); ++it) {
@@ -82,6 +91,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
8291
}
8392
}
8493

94+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
8595
void clear_handles() override
8696
{
8797
subscription_handles_.clear();
@@ -91,6 +101,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
91101
waitable_handles_.clear();
92102
}
93103

104+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
94105
void remove_null_handles(rcl_wait_set_t * wait_set) override
95106
{
96107
// TODO(jacobperron): Check if wait set sizes are what we expect them to be?
@@ -103,9 +114,9 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
103114
// Mark corresponding weak_ptr as expired for entities that are null in the wait set
104115
size_t valid_subscription_count = 0;
105116
for (size_t i = 0; i < subscription_handles_.size(); ++i) {
106-
if (valid_subscription_count < wait_set->size_of_subscriptions &&
107-
!wait_set->subscriptions[valid_subscription_count])
108-
{
117+
if (
118+
valid_subscription_count < wait_set->size_of_subscriptions &&
119+
!wait_set->subscriptions[valid_subscription_count]) {
109120
subscription_handles_[i] = std::weak_ptr<const rcl_subscription_t>{};
110121
}
111122
if (subscription_handles_[i].lock()) {
@@ -115,9 +126,9 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
115126

116127
size_t valid_service_count = 0;
117128
for (size_t i = 0; i < service_handles_.size(); ++i) {
118-
if (valid_service_count < wait_set->size_of_services &&
119-
!wait_set->services[valid_service_count])
120-
{
129+
if (
130+
valid_service_count < wait_set->size_of_services &&
131+
!wait_set->services[valid_service_count]) {
121132
service_handles_[i] = std::weak_ptr<const rcl_service_t>{};
122133
}
123134
if (service_handles_[i].lock()) {
@@ -127,9 +138,8 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
127138

128139
size_t valid_client_count = 0;
129140
for (size_t i = 0; i < client_handles_.size(); ++i) {
130-
if (valid_client_count < wait_set->size_of_clients &&
131-
!wait_set->clients[valid_client_count])
132-
{
141+
if (
142+
valid_client_count < wait_set->size_of_clients && !wait_set->clients[valid_client_count]) {
133143
client_handles_[i] = std::weak_ptr<const rcl_client_t>{};
134144
}
135145
if (client_handles_[i].lock()) {
@@ -139,9 +149,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
139149

140150
size_t valid_timer_count = 0;
141151
for (size_t i = 0; i < timer_handles_.size(); ++i) {
142-
if (valid_timer_count < wait_set->size_of_timers &&
143-
!wait_set->timers[valid_timer_count])
144-
{
152+
if (valid_timer_count < wait_set->size_of_timers && !wait_set->timers[valid_timer_count]) {
145153
timer_handles_[i] = std::weak_ptr<const rcl_timer_t>{};
146154
}
147155
if (timer_handles_[i].lock()) {
@@ -157,43 +165,37 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
157165

158166
// Remove expired weak_ptr instances
159167
subscription_handles_.erase(
160-
std::remove_if(subscription_handles_.begin(), subscription_handles_.end(),
161-
[](const std::weak_ptr<const rcl_subscription_t> & weak_ptr) {
162-
return weak_ptr.expired();
168+
std::remove_if(
169+
subscription_handles_.begin(), subscription_handles_.end(),
170+
[](const std::weak_ptr<const rcl_subscription_t> & weak_ptr) {
171+
return weak_ptr.expired();
163172
}),
164-
subscription_handles_.end()
165-
);
173+
subscription_handles_.end());
166174

167175
service_handles_.erase(
168-
std::remove_if(service_handles_.begin(), service_handles_.end(),
169-
[](const std::weak_ptr<const rcl_service_t> & weak_ptr) {
170-
return weak_ptr.expired();
171-
}),
172-
service_handles_.end()
173-
);
176+
std::remove_if(
177+
service_handles_.begin(), service_handles_.end(),
178+
[](const std::weak_ptr<const rcl_service_t> & weak_ptr) { return weak_ptr.expired(); }),
179+
service_handles_.end());
174180

175181
client_handles_.erase(
176-
std::remove_if(client_handles_.begin(), client_handles_.end(),
177-
[](const std::weak_ptr<const rcl_client_t> & weak_ptr) {
178-
return weak_ptr.expired();
179-
}),
180-
client_handles_.end()
181-
);
182+
std::remove_if(
183+
client_handles_.begin(), client_handles_.end(),
184+
[](const std::weak_ptr<const rcl_client_t> & weak_ptr) { return weak_ptr.expired(); }),
185+
client_handles_.end());
182186

183187
timer_handles_.erase(
184-
std::remove_if(timer_handles_.begin(), timer_handles_.end(),
185-
[](const std::weak_ptr<const rcl_timer_t> & weak_ptr) {
186-
return weak_ptr.expired();
187-
}),
188-
timer_handles_.end()
189-
);
188+
std::remove_if(
189+
timer_handles_.begin(), timer_handles_.end(),
190+
[](const std::weak_ptr<const rcl_timer_t> & weak_ptr) { return weak_ptr.expired(); }),
191+
timer_handles_.end());
190192

191193
waitable_handles_.erase(
192194
std::remove(waitable_handles_.begin(), waitable_handles_.end(), nullptr),
193-
waitable_handles_.end()
194-
);
195+
waitable_handles_.end());
195196
}
196197

198+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
197199
bool collect_entities(const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) override
198200
{
199201
bool has_invalid_weak_groups_or_nodes = false;
@@ -229,6 +231,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
229231
return has_invalid_weak_groups_or_nodes;
230232
}
231233

234+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
232235
void add_waitable_handle(const rclcpp::Waitable::SharedPtr & waitable) override
233236
{
234237
if (nullptr == waitable) {
@@ -237,19 +240,18 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
237240
waitable_handles_.push_back(waitable);
238241
}
239242

243+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
240244
bool add_handles_to_wait_set(rcl_wait_set_t * wait_set) override
241245
{
242246
for (const std::weak_ptr<const rcl_subscription_t> & weak_subscription :
243-
subscription_handles_)
244-
{
247+
subscription_handles_) {
245248
auto subscription = weak_subscription.lock();
246249
if (!subscription) {
247250
continue; // Skip expired handles
248251
}
249252
if (rcl_wait_set_add_subscription(wait_set, subscription.get(), NULL) != RCL_RET_OK) {
250253
RCUTILS_LOG_ERROR_NAMED(
251-
"rclcpp",
252-
"Couldn't add subscription to wait set: %s", rcl_get_error_string().str);
254+
"rclcpp", "Couldn't add subscription to wait set: %s", rcl_get_error_string().str);
253255
rcl_reset_error();
254256
return false;
255257
}
@@ -262,8 +264,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
262264
}
263265
if (rcl_wait_set_add_client(wait_set, client.get(), NULL) != RCL_RET_OK) {
264266
RCUTILS_LOG_ERROR_NAMED(
265-
"rclcpp",
266-
"Couldn't add client to wait set: %s", rcl_get_error_string().str);
267+
"rclcpp", "Couldn't add client to wait set: %s", rcl_get_error_string().str);
267268
rcl_reset_error();
268269
return false;
269270
}
@@ -276,8 +277,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
276277
}
277278
if (rcl_wait_set_add_service(wait_set, service.get(), NULL) != RCL_RET_OK) {
278279
RCUTILS_LOG_ERROR_NAMED(
279-
"rclcpp",
280-
"Couldn't add service to wait set: %s", rcl_get_error_string().str);
280+
"rclcpp", "Couldn't add service to wait set: %s", rcl_get_error_string().str);
281281
rcl_reset_error();
282282
return false;
283283
}
@@ -290,8 +290,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
290290
}
291291
if (rcl_wait_set_add_timer(wait_set, timer.get(), NULL) != RCL_RET_OK) {
292292
RCUTILS_LOG_ERROR_NAMED(
293-
"rclcpp",
294-
"Couldn't add timer to wait set: %s", rcl_get_error_string().str);
293+
"rclcpp", "Couldn't add timer to wait set: %s", rcl_get_error_string().str);
295294
rcl_reset_error();
296295
return false;
297296
}
@@ -307,8 +306,8 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
307306
return true;
308307
}
309308

310-
void
311-
get_next_subscription(
309+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
310+
void get_next_subscription(
312311
rclcpp::AnyExecutable & any_exec,
313312
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) override
314313
{
@@ -348,8 +347,8 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
348347
}
349348
}
350349

351-
void
352-
get_next_service(
350+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
351+
void get_next_service(
353352
rclcpp::AnyExecutable & any_exec,
354353
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) override
355354
{
@@ -389,8 +388,8 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
389388
}
390389
}
391390

392-
void
393-
get_next_client(
391+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
392+
void get_next_client(
394393
rclcpp::AnyExecutable & any_exec,
395394
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) override
396395
{
@@ -430,8 +429,8 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
430429
}
431430
}
432431

433-
void
434-
get_next_timer(
432+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
433+
void get_next_timer(
435434
rclcpp::AnyExecutable & any_exec,
436435
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) override
437436
{
@@ -478,8 +477,8 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
478477
}
479478
}
480479

481-
void
482-
get_next_waitable(
480+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
481+
void get_next_waitable(
483482
rclcpp::AnyExecutable & any_exec,
484483
const WeakCallbackGroupsToNodesMap & weak_groups_to_nodes) override
485484
{
@@ -513,6 +512,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
513512
}
514513
}
515514

515+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
516516
rcl_allocator_t get_allocator() override
517517
{
518518
if constexpr (std::is_same_v<Alloc, std::allocator<void>>) {
@@ -522,6 +522,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
522522
}
523523
}
524524

525+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
525526
size_t number_of_ready_subscriptions() const override
526527
{
527528
size_t number_of_subscriptions = 0;
@@ -537,6 +538,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
537538
return number_of_subscriptions;
538539
}
539540

541+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
540542
size_t number_of_ready_services() const override
541543
{
542544
size_t number_of_services = 0;
@@ -552,6 +554,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
552554
return number_of_services;
553555
}
554556

557+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
555558
size_t number_of_ready_events() const override
556559
{
557560
size_t number_of_events = 0;
@@ -561,6 +564,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
561564
return number_of_events;
562565
}
563566

567+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
564568
size_t number_of_ready_clients() const override
565569
{
566570
size_t number_of_clients = 0;
@@ -576,6 +580,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
576580
return number_of_clients;
577581
}
578582

583+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
579584
size_t number_of_guard_conditions() const override
580585
{
581586
size_t number_of_guard_conditions = guard_conditions_.size();
@@ -585,6 +590,7 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
585590
return number_of_guard_conditions;
586591
}
587592

593+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
588594
size_t number_of_ready_timers() const override
589595
{
590596
size_t number_of_timers = 0;
@@ -600,13 +606,14 @@ class AllocatorMemoryStrategy : public memory_strategy::MemoryStrategy
600606
return number_of_timers;
601607
}
602608

609+
[[deprecated("AllocatorMemoryStrategy is deprecated.")]]
603610
size_t number_of_waitables() const override
604611
{
605612
return waitable_handles_.size();
606613
}
607614

608615
private:
609-
template<typename T>
616+
template <typename T>
610617
using VectorRebind =
611618
std::vector<T, typename std::allocator_traits<Alloc>::template rebind_alloc<T>>;
612619

0 commit comments

Comments
 (0)