Commit 2ae0aedb authored by Swann Perarnau's avatar Swann Perarnau

[refactor] rename create/purge to avoid confusion

create -> register
purge -> deregister

create is a name we are using elsewhere for dynamic allocation.
And those names match better what we are doing.
parent bcb6c923
......@@ -36,8 +36,8 @@ struct aml_area;
struct aml_arena_data;
struct aml_arena_ops {
int (*create)(struct aml_arena_data *, struct aml_area *);
int (*purge)(struct aml_arena_data *);
int (*register_arena)(struct aml_arena_data *, struct aml_area *);
int (*deregister_arena)(struct aml_arena_data *);
void *(*mallocx)(struct aml_arena_data *, size_t, int);
void (*dallocx)(struct aml_arena_data *, void *, int);
void *(*reallocx)(struct aml_arena_data *, void *, size_t, int);
......@@ -48,8 +48,8 @@ struct aml_arena {
struct aml_arena_data *data;
};
int aml_arena_create(struct aml_arena *, struct aml_area *);
int aml_arena_purge(struct aml_arena *);
int aml_arena_register(struct aml_arena *, struct aml_area *);
int aml_arena_deregister(struct aml_arena *);
void *aml_arena_mallocx(struct aml_arena *, size_t, int);
void aml_arena_dallocx(struct aml_arena *, void *, int);
void *aml_arena_reallocx(struct aml_arena *, void *, size_t, int);
......@@ -64,6 +64,17 @@ struct aml_arena_jemalloc_data {
int flags;
};
#define AML_ARENA_JEMALLOC_DECL(name) \
struct aml_arena_jemalloc_data __ ##name## _inner_data; \
struct aml_arena name = { \
&aml_arena_jemalloc_ops, \
(struct aml_arena_data *)&__ ## name ## _inner_data, \
};
#define AML_ARENA_JEMALLOC_ALLOCSIZE \
(sizeof(struct aml_arena_jemalloc_data) + \
sizeof(struct aml_arena))
int aml_arena_jemalloc_regular_init(struct aml_arena_jemalloc_data *);
int aml_arena_jemalloc_regular_destroy(struct aml_arena_jemalloc_data *);
int aml_arena_jemalloc_aligned_init(struct aml_arena_jemalloc_data *, size_t);
......
......@@ -7,17 +7,17 @@
* functions.
******************************************************************************/
int aml_arena_create(struct aml_arena *arena, struct aml_area *area)
int aml_arena_register(struct aml_arena *arena, struct aml_area *area)
{
assert(arena != NULL);
assert(area != NULL);
return arena->ops->create(arena->data, area);
return arena->ops->register_arena(arena->data, area);
}
int aml_arena_purge(struct aml_arena *arena)
int aml_arena_deregister(struct aml_arena *arena)
{
assert(arena != NULL);
return arena->ops->purge(arena->data);
return arena->ops->deregister_arena(arena->data);
}
void *aml_arena_mallocx(struct aml_arena *arena, size_t size, int flags)
......
......@@ -185,7 +185,8 @@ int aml_arena_jemalloc_flags(int flags)
}
/* TODO: make the function idempotent */
int aml_arena_jemalloc_create(struct aml_arena_data *a, struct aml_area *area)
int aml_arena_jemalloc_register_arena(struct aml_arena_data *a,
struct aml_area *area)
{
int err;
unsigned int newidx;
......@@ -217,7 +218,7 @@ exit:
}
/* TODO: make the function idempotent */
int aml_arena_jemalloc_purge(struct aml_arena_data *a)
int aml_arena_jemalloc_deregister_arena(struct aml_arena_data *a)
{
struct aml_arena_jemalloc_data *arena =
(struct aml_arena_jemalloc_data*) a;
......@@ -260,8 +261,8 @@ void aml_arena_jemalloc_dallocx(struct aml_arena_data *a, void *ptr,
}
struct aml_arena_ops aml_arena_jemalloc_ops = {
aml_arena_jemalloc_create,
aml_arena_jemalloc_purge,
aml_arena_jemalloc_register_arena,
aml_arena_jemalloc_deregister_arena,
aml_arena_jemalloc_mallocx,
aml_arena_jemalloc_dallocx,
aml_arena_jemalloc_reallocx,
......
......@@ -81,12 +81,12 @@ int main(int argc, char *argv[])
assert(!aml_area_linux_mbind_init(&area_data.data.mbind, MPOL_BIND,
nodemask));
assert(!aml_area_linux_mmap_anonymous_init(&area_data.data.mmap));
assert(!aml_arena_create(&arena, &area));
assert(!aml_arena_register(&arena, &area));
doit(&area);
/* same here, order matters. */
assert(!aml_arena_purge(&arena));
assert(!aml_arena_deregister(&arena));
assert(!aml_area_linux_mmap_anonymous_destroy(&area_data.data.mmap));
assert(!aml_area_linux_mbind_destroy(&area_data.data.mbind));
assert(!aml_area_linux_manager_single_destroy(&area_data.data.manager));
......
......@@ -15,7 +15,7 @@ void doit(struct aml_arena *arena)
unsigned long *a;
/* create the arena */
err = aml_arena_create(arena, &area);
err = aml_arena_register(arena, &area);
assert(err == 0);
/* try to allocate something */
......@@ -41,7 +41,7 @@ void doit(struct aml_arena *arena)
assert(ptr != NULL);
ptr = aml_arena_reallocx(arena, ptr, 0, 0);
err = aml_arena_purge(arena);
err = aml_arena_deregister(arena);
assert(err == 0);
}
......
......@@ -40,7 +40,7 @@ int main(int argc, char *argv[])
area.ops = &aml_area_posix_ops;
area.data = (struct aml_area_data *)&area_data;
assert(!aml_arena_jemalloc_regular_init(&arena_data));
assert(!aml_arena_create(&arena, &area));
assert(!aml_arena_register(&arena, &area));
aml_area_linux_manager_single_init(&config[0], &arena);
......@@ -48,7 +48,7 @@ int main(int argc, char *argv[])
doit(&config[i], &aml_area_linux_manager_single_ops);
aml_area_linux_manager_single_destroy(&config[0]);
assert(!aml_arena_purge(&arena));
assert(!aml_arena_deregister(&arena));
aml_arena_jemalloc_regular_destroy(&arena_data);
aml_area_posix_init(&area_data);
aml_finalize();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment