Commit 8d2cc6ae authored by Swann Perarnau's avatar Swann Perarnau

[feature] add proper init functions for area_posix

Same schema as for arena, we create init functions for each type of
area, to make sure that users know what they are working with.

The functions are easy here, as posix is more an allocator than anything
proper.
parent 261755e7
......@@ -119,8 +119,20 @@ extern struct aml_area_ops aml_area_posix_ops;
struct aml_area_posix_data {
};
int aml_area_posix_init(struct aml_area_posix_data *);
int aml_area_posix_destroy(struct aml_area_posix_data *);
#define AML_AREA_POSIX_DECL(name) \
struct aml_area_posix_data __ ##name## _inner_data; \
struct aml_area name = { \
&aml_area_posix_ops, \
(struct aml_area_data *)&__ ## name ## _inner_data, \
};
#define AML_AREA_POSIX_ALLOCSIZE \
(sizeof(struct aml_area_posix_data) + \
sizeof(struct aml_area))
int aml_area_posix_create(struct aml_area **);
int aml_area_posix_init(struct aml_area *);
int aml_area_posix_destroy(struct aml_area *);
/*******************************************************************************
* Linux Area:
......
......@@ -80,13 +80,37 @@ struct aml_area_ops aml_area_posix_ops = {
* Initialization/Destroy function:
******************************************************************************/
int aml_area_posix_init(struct aml_area_posix_data *data)
int aml_area_posix_create(struct aml_area **a)
{
struct aml_area *ret = NULL;
intptr_t baseptr, dataptr;
/* alloc */
baseptr = (intptr_t) calloc(1, AML_AREA_POSIX_ALLOCSIZE);
dataptr = baseptr + sizeof(struct aml_area);
ret = (struct aml_area *)baseptr;
ret->data = (struct aml_area_data *)dataptr;
aml_area_posix_vinit(ret);
*a = ret;
return 0;
}
int aml_area_posix_vinit(struct aml_area *data)
{
assert(data != NULL);
return 0;
}
int aml_area_posix_init(struct aml_area *data)
{
assert(data != NULL);
return 0;
}
int aml_area_posix_destroy(struct aml_area_posix_data *data)
int aml_area_posix_destroy(struct aml_area *data)
{
assert(data != NULL);
return 0;
......
......@@ -3,8 +3,7 @@
int main(int argc, char *argv[])
{
struct aml_area area;
struct aml_area_posix_data data;
AML_AREA_POSIX_DECL(area);
void *ptr;
unsigned long *a, *b, *c;
unsigned long i;
......@@ -13,9 +12,7 @@ int main(int argc, char *argv[])
aml_init(&argc, &argv);
/* initialize the area itself */
aml_area_posix_init(&data);
area.ops = &aml_area_posix_ops;
area.data = (struct aml_area_data*)&data;
aml_area_posix_init(&area);
/* try to allocate something */
ptr = aml_area_malloc(&area, sizeof(unsigned long) * 10);
......@@ -54,7 +51,7 @@ int main(int argc, char *argv[])
assert(ptr != NULL);
ptr = aml_area_realloc(&area, ptr, 0);
aml_area_posix_destroy(&data);
aml_area_posix_destroy(&area);
aml_finalize();
return 0;
}
......@@ -4,9 +4,7 @@
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
/* posix area used as a backend */
struct aml_area area;
struct aml_area_posix_data posix_data;
AML_AREA_POSIX_DECL(area);
void doit(struct aml_arena *arena)
{
......@@ -52,9 +50,7 @@ int main(int argc, char *argv[])
aml_init(&argc, &argv);
/* area init */
aml_area_posix_init(&posix_data);
area.ops = &aml_area_posix_ops;
area.data = (struct aml_area_data *)&posix_data;
aml_area_posix_init(&area);
/* build up the data variants */
assert(!aml_arena_jemalloc_create(&arenas[0],
......@@ -77,5 +73,6 @@ int main(int argc, char *argv[])
assert(!aml_arena_jemalloc_destroy(arenas[i]));
free(arenas[i]);
}
aml_area_posix_destroy(&area);
return 0;
}
......@@ -24,9 +24,8 @@ void doit(struct aml_area_linux_manager_data *data,
int main(int argc, char *argv[])
{
struct aml_area area;
struct aml_area_posix_data area_data;
AML_ARENA_JEMALLOC_DECL(arena);
AML_AREA_POSIX_DECL(area);
struct aml_area_linux_manager_data config[1];
aml_init(&argc, &argv);
......@@ -34,9 +33,7 @@ int main(int argc, char *argv[])
/* init all the necessary objects:
* we use a posix area to provide mmap, and jemalloc arena as the
* managed arena.*/
aml_area_posix_init(&area_data);
area.ops = &aml_area_posix_ops;
area.data = (struct aml_area_data *)&area_data;
aml_area_posix_init(&area);
assert(!aml_arena_jemalloc_init(&arena, AML_ARENA_JEMALLOC_TYPE_REGULAR));
assert(!aml_arena_register(&arena, &area));
......@@ -48,7 +45,7 @@ int main(int argc, char *argv[])
aml_area_linux_manager_single_destroy(&config[0]);
assert(!aml_arena_deregister(&arena));
aml_arena_jemalloc_destroy(&arena);
aml_area_posix_init(&area_data);
aml_area_posix_destroy(&area);
aml_finalize();
return 0;
}
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