File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,21 @@ RCUTILS_WARN_UNUSED
108
108
rcutils_allocator_t
109
109
rcutils_get_default_allocator (void );
110
110
111
+ /// Override the default allocator returned by rcutils_get_default_allocator.
112
+ /**
113
+ * Attribute | Adherence
114
+ * ------------------ | -------------
115
+ * Allocates Memory | No
116
+ * Thread-Safe | No
117
+ * Uses Atomics | No
118
+ * Lock-Free | Yes
119
+ *
120
+ * \param[in] override_allocator The allocator to set as the default.
121
+ */
122
+ RCUTILS_PUBLIC
123
+ void
124
+ rcutils_set_default_allocator (rcutils_allocator_t override_allocator );
125
+
111
126
/// Return true if the given allocator has non-null function pointers.
112
127
/**
113
128
* \param[in] allocator to be checked by the function
Original file line number Diff line number Diff line change @@ -69,16 +69,31 @@ rcutils_get_zero_initialized_allocator(void)
69
69
return zero_allocator ;
70
70
}
71
71
72
+ static rcutils_allocator_t rcutils_override_default_allocator = {0 };
73
+
74
+ void
75
+ rcutils_set_default_allocator (rcutils_allocator_t override_allocator )
76
+ {
77
+ if (rcutils_allocator_is_valid (& override_allocator )) {
78
+ rcutils_override_default_allocator = override_allocator ;
79
+ }
80
+ }
81
+
72
82
rcutils_allocator_t
73
83
rcutils_get_default_allocator (void )
74
84
{
85
+ if (rcutils_allocator_is_valid (& rcutils_override_default_allocator )) {
86
+ return rcutils_override_default_allocator ;
87
+ }
88
+
75
89
static rcutils_allocator_t default_allocator = {
76
90
.allocate = __default_allocate ,
77
91
.deallocate = __default_deallocate ,
78
92
.reallocate = __default_reallocate ,
79
93
.zero_allocate = __default_zero_allocate ,
80
94
.state = NULL ,
81
95
};
96
+
82
97
return default_allocator ;
83
98
}
84
99
You can’t perform that action at this time.
0 commit comments