13
13
#include "utils_common.h"
14
14
#include "utils_concurrency.h"
15
15
16
+ #ifndef NDEBUG
17
+ #define DEBUG_RUN_CHECKS (pool ) ba_debug_checks(pool)
18
+ #define DEBUG_SET_VAR (var , value ) DO_WHILE_EXPRS((var = value))
19
+ #define DEBUG_INC_VAR (var ) DO_WHILE_EXPRS((var++))
20
+ #else
21
+ #define DEBUG_RUN_CHECKS (pool ) DO_WHILE_EMPTY
22
+ #define DEBUG_SET_VAR (var , value ) DO_WHILE_EMPTY
23
+ #define DEBUG_INC_VAR (var ) DO_WHILE_EMPTY
24
+ #endif /* NDEBUG */
25
+
16
26
// minimum size of a single pool of the linear base allocator
17
27
#define MINIMUM_LINEAR_POOL_SIZE (ba_os_get_page_size())
18
28
@@ -94,9 +104,7 @@ umf_ba_linear_pool_t *umf_ba_linear_create(size_t pool_size) {
94
104
pool -> metadata .data_ptr = data_ptr ;
95
105
pool -> metadata .size_left = size_left ;
96
106
pool -> next_pool = NULL ; // this is the only pool now
97
- #ifndef NDEBUG
98
- pool -> metadata .n_pools = 1 ;
99
- #endif /* NDEBUG */
107
+ DEBUG_SET_VAR (pool -> metadata .n_pools , 1 );
100
108
101
109
// init lock
102
110
os_mutex_t * lock = util_mutex_init (& pool -> metadata .lock );
@@ -143,18 +151,14 @@ void *umf_ba_linear_alloc(umf_ba_linear_pool_t *pool, size_t size) {
143
151
// add the new pool to the list of pools
144
152
new_pool -> next_pool = pool -> next_pool ;
145
153
pool -> next_pool = new_pool ;
146
- #ifndef NDEBUG
147
- pool -> metadata .n_pools ++ ;
148
- #endif /* NDEBUG */
154
+ DEBUG_INC_VAR (pool -> metadata .n_pools );
149
155
}
150
156
151
157
assert (pool -> metadata .size_left >= aligned_size );
152
158
void * ptr = pool -> metadata .data_ptr ;
153
159
pool -> metadata .data_ptr += aligned_size ;
154
160
pool -> metadata .size_left -= aligned_size ;
155
- #ifndef NDEBUG
156
- ba_debug_checks (pool );
157
- #endif /* NDEBUG */
161
+ DEBUG_RUN_CHECKS (pool );
158
162
util_mutex_unlock (& pool -> metadata .lock );
159
163
160
164
return ptr ;
@@ -168,9 +172,7 @@ void umf_ba_linear_destroy(umf_ba_linear_pool_t *pool) {
168
172
return ;
169
173
}
170
174
171
- #ifndef NDEBUG
172
- ba_debug_checks (pool );
173
- #endif /* NDEBUG */
175
+ DEBUG_RUN_CHECKS (pool );
174
176
175
177
umf_ba_next_linear_pool_t * current_pool ;
176
178
umf_ba_next_linear_pool_t * next_pool = pool -> next_pool ;
0 commit comments