rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

commit a72b2fddda000e0ab953069982f2c8d15dcf3dd1
parent 87c37666a2a5a9a407554e48f76c2f2323618ad8
Author: vaplv <vaplv@free.fr>
Date:   Wed, 27 Nov 2013 16:53:49 +0100

Add the support of an user defined allocator to the free list

Diffstat:
Msrc/free_list.h | 10+++++++---
Msrc/test_free_list.c | 2+-
2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/free_list.h b/src/free_list.h @@ -35,23 +35,27 @@ struct FLIST_TYPE__ { uint32_t name_next; struct FITEM_TYPE* items; uint32_t nitems; + struct mem_allocator* allocator; }; static FINLINE void -FLIST_FUNC__(init)(struct FLIST_TYPE__* list) +FLIST_FUNC__(init) + (struct mem_allocator* allocator, /* May be NULL <=> use default allocator */ + struct FLIST_TYPE__* list) { ASSERT(list); list->head = UINT32_MAX; list->name_next = 0; list->items = NULL; list->nitems = 0; + list->allocator = allocator ? allocator : &mem_default_allocator; } static FINLINE void FLIST_FUNC__(release)(struct FLIST_TYPE__* list) { ASSERT(list); - MEM_FREE(&mem_default_allocator, list->items); + MEM_FREE(list->allocator, list->items); } static FINLINE bool @@ -91,7 +95,7 @@ FLIST_FUNC__(add)(struct FLIST_TYPE__* list) id.index = list->nitems; list->items = MEM_REALLOC - (&mem_default_allocator, + (list->allocator, list->items, nitems_new * sizeof(struct FITEM_TYPE)); FOR_EACH(uint32_t, iitem, list->nitems, nitems_new - 1) { diff --git a/src/test_free_list.c b/src/test_free_list.c @@ -22,7 +22,7 @@ main(int argc, char** argv) id[i] = FID_NULL; } - flist_object_init(&list); + flist_object_init(NULL, &list); CHECK(flist_object_hold(&list, id[0]), false); CHECK(flist_object_get(&list, id[0]), NULL);