Skip to content

Commit 0d7f242

Browse files
authored
Merge pull request #213 from ldorau/Use_base_allocator_in_scalable_pool
Use base allocator in scalable pool
2 parents 2572937 + 143bfd7 commit 0d7f242

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/pool/pool_scalable.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <tbb/scalable_allocator.h>
2525

26+
#include "base_alloc_global.h"
2627
#include "utils_common.h"
2728
#include "utils_sanitizers.h"
2829

@@ -54,6 +55,9 @@ struct tbb_callbacks {
5455
struct tbb_memory_pool {
5556
umf_memory_provider_handle_t mem_provider;
5657
void *tbb_pool;
58+
59+
// saved pointer to the global base allocator
60+
umf_ba_pool_t *base_allocator;
5761
};
5862

5963
static struct tbb_callbacks g_tbb_ops;
@@ -146,12 +150,19 @@ static umf_result_t tbb_pool_initialize(umf_memory_provider_handle_t provider,
146150
return UMF_RESULT_ERROR_UNKNOWN;
147151
}
148152

149-
struct tbb_memory_pool *pool_data = malloc(sizeof(struct tbb_memory_pool));
153+
umf_ba_pool_t *base_allocator =
154+
umf_ba_get_pool(sizeof(struct tbb_memory_pool));
155+
if (!base_allocator) {
156+
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
157+
}
158+
159+
struct tbb_memory_pool *pool_data = umf_ba_alloc(base_allocator);
150160
if (!pool_data) {
151161
fprintf(stderr, "cannot allocate memory for metadata\n");
152162
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY;
153163
}
154164

165+
pool_data->base_allocator = base_allocator;
155166
pool_data->mem_provider = provider;
156167
int ret = g_tbb_ops.pool_create_v1((intptr_t)pool_data, &policy,
157168
&(pool_data->tbb_pool));
@@ -168,7 +179,7 @@ static void tbb_pool_finalize(void *pool) {
168179
pthread_once(&tbb_is_initialized, load_tbb_symbols);
169180
struct tbb_memory_pool *pool_data = (struct tbb_memory_pool *)pool;
170181
g_tbb_ops.pool_destroy(pool_data->tbb_pool);
171-
free(pool_data);
182+
umf_ba_free(pool_data->base_allocator, pool_data);
172183
}
173184

174185
static void *tbb_malloc(void *pool, size_t size) {

0 commit comments

Comments
 (0)