Skip to content

Commit adc43a9

Browse files
authored
Merge pull request #339 from igchor/critnib_use_global_alloc
Use global base alloc in critnib
2 parents c6c098d + 4d84444 commit adc43a9

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed

src/critnib/critnib.c

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,6 @@ struct critnib {
131131
uint64_t remove_count;
132132

133133
struct os_mutex_t mutex; /* writes/removes */
134-
135-
umf_ba_pool_t *pool_nodes;
136-
umf_ba_pool_t *pool_leaves;
137134
};
138135

139136
/*
@@ -195,25 +192,10 @@ struct critnib *critnib_new(void) {
195192
goto err_free_critnib;
196193
}
197194

198-
c->pool_nodes = umf_ba_create(sizeof(struct critnib_node));
199-
if (!c->pool_nodes) {
200-
goto err_util_mutex_destroy;
201-
}
202-
203-
c->pool_leaves = umf_ba_create(sizeof(struct critnib_leaf));
204-
if (!c->pool_leaves) {
205-
goto err_destroy_pool_nodes;
206-
}
207-
208195
VALGRIND_HG_DRD_DISABLE_CHECKING(&c->root, sizeof(c->root));
209196
VALGRIND_HG_DRD_DISABLE_CHECKING(&c->remove_count, sizeof(c->remove_count));
210197

211198
return c;
212-
213-
err_destroy_pool_nodes:
214-
umf_ba_destroy(c->pool_nodes);
215-
err_util_mutex_destroy:
216-
util_mutex_destroy_not_free(&c->mutex);
217199
err_free_critnib:
218200
umf_ba_global_free(c);
219201
return NULL;
@@ -224,15 +206,15 @@ struct critnib *critnib_new(void) {
224206
*/
225207
static void delete_node(struct critnib *c, struct critnib_node *__restrict n) {
226208
if (is_leaf(n)) {
227-
umf_ba_free(c->pool_leaves, to_leaf(n));
209+
umf_ba_global_free(to_leaf(n));
228210
} else {
229211
for (int i = 0; i < SLNODES; i++) {
230212
if (n->child[i]) {
231213
delete_node(c, n->child[i]);
232214
}
233215
}
234216

235-
umf_ba_free(c->pool_nodes, n);
217+
umf_ba_global_free(n);
236218
}
237219
}
238220

@@ -248,23 +230,21 @@ void critnib_delete(struct critnib *c) {
248230

249231
for (struct critnib_node *m = c->deleted_node; m;) {
250232
struct critnib_node *mm = m->child[0];
251-
umf_ba_free(c->pool_nodes, m);
233+
umf_ba_global_free(m);
252234
m = mm;
253235
}
254236

255237
for (struct critnib_leaf *k = c->deleted_leaf; k;) {
256238
struct critnib_leaf *kk = k->value;
257-
umf_ba_free(c->pool_leaves, k);
239+
umf_ba_global_free(k);
258240
k = kk;
259241
}
260242

261243
for (int i = 0; i < DELETED_LIFE; i++) {
262-
umf_ba_free(c->pool_nodes, c->pending_del_nodes[i]);
263-
umf_ba_free(c->pool_leaves, c->pending_del_leaves[i]);
244+
umf_ba_global_free(c->pending_del_nodes[i]);
245+
umf_ba_global_free(c->pending_del_leaves[i]);
264246
}
265247

266-
umf_ba_destroy(c->pool_nodes);
267-
umf_ba_destroy(c->pool_leaves);
268248
umf_ba_global_free(c);
269249
}
270250

@@ -292,7 +272,7 @@ static void free_node(struct critnib *__restrict c,
292272
*/
293273
static struct critnib_node *alloc_node(struct critnib *__restrict c) {
294274
if (!c->deleted_node) {
295-
return umf_ba_alloc(c->pool_nodes);
275+
return umf_ba_global_alloc(sizeof(struct critnib_node));
296276
}
297277

298278
struct critnib_node *n = c->deleted_node;
@@ -323,7 +303,7 @@ static void free_leaf(struct critnib *__restrict c,
323303
*/
324304
static struct critnib_leaf *alloc_leaf(struct critnib *__restrict c) {
325305
if (!c->deleted_leaf) {
326-
return umf_ba_alloc(c->pool_leaves);
306+
return umf_ba_global_alloc(sizeof(struct critnib_leaf));
327307
}
328308

329309
struct critnib_leaf *k = c->deleted_leaf;

0 commit comments

Comments
 (0)