Fri, 05 Oct 2012 13:23:25 +0200
moved allocator to seperate file
function signatures are now "generic" and not restricted to UcxMempool
ucx/Makefile | file | annotate | diff | comparison | revisions | |
ucx/allocator.c | file | annotate | diff | comparison | revisions | |
ucx/allocator.h | file | annotate | diff | comparison | revisions | |
ucx/mempool.c | file | annotate | diff | comparison | revisions | |
ucx/mempool.h | file | annotate | diff | comparison | revisions |
1.1 --- a/ucx/Makefile Fri Oct 05 11:55:36 2012 +0200 1.2 +++ b/ucx/Makefile Fri Oct 05 13:23:25 2012 +0200 1.3 @@ -29,7 +29,7 @@ 1.4 include ../$(CONF).mk 1.5 1.6 # list of source files 1.7 -SRC = list.c dlist.c map.c mempool.c string.c test.c 1.8 +SRC = list.c dlist.c map.c mempool.c string.c test.c allocator.c 1.9 1.10 OBJ = $(SRC:%.c=../build/%.$(OBJ_EXT)) 1.11
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/ucx/allocator.c Fri Oct 05 13:23:25 2012 +0200 2.3 @@ -0,0 +1,12 @@ 2.4 +#include "allocator.h" 2.5 +#include <stdlib.h> 2.6 + 2.7 +void *ucx_default_malloc(void *ignore, size_t n) { 2.8 + return malloc(n); 2.9 +} 2.10 +void *ucx_default_calloc(void *ignore, size_t n, size_t size) { 2.11 + return calloc(n, size); 2.12 +} 2.13 +void *ucx_default_realloc(void *ignore, void *data, size_t n) { 2.14 + return realloc(data, n); 2.15 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/ucx/allocator.h Fri Oct 05 13:23:25 2012 +0200 3.3 @@ -0,0 +1,32 @@ 3.4 +#ifndef ALLOCATOR_H 3.5 +#define ALLOCATOR_H 3.6 + 3.7 +#include <stddef.h> 3.8 + 3.9 +#ifdef __cplusplus 3.10 +extern "C" { 3.11 +#endif 3.12 + 3.13 +typedef void*(*ucx_allocator_malloc)(void *pool, size_t n); 3.14 +typedef void*(*ucx_allocator_calloc)(void *pool, size_t n, size_t size); 3.15 +typedef void*(*ucx_allocator_realloc)(void *pool, void *data, size_t n); 3.16 + 3.17 +typedef struct { 3.18 + void *pool; 3.19 + ucx_allocator_malloc malloc; 3.20 + ucx_allocator_calloc calloc; 3.21 + ucx_allocator_realloc realloc; 3.22 +} UcxAllocator; 3.23 + 3.24 +void *ucx_default_malloc(void *ignore, size_t n); 3.25 +void *ucx_default_calloc(void *ignore, size_t n, size_t size); 3.26 +void *ucx_default_realloc(void *ignore, void *data, size_t n); 3.27 + 3.28 +#define UCX_ALLOCATOR_DEFAULT {NULL, \ 3.29 + ucx_default_malloc, ucx_default_calloc, ucx_default_realloc} 3.30 + 3.31 +#ifdef __cplusplus 3.32 +} 3.33 +#endif 3.34 + 3.35 +#endif /* ALLOCATOR_H */
4.1 --- a/ucx/mempool.c Fri Oct 05 11:55:36 2012 +0200 4.2 +++ b/ucx/mempool.c Fri Oct 05 13:23:25 2012 +0200 4.3 @@ -24,16 +24,6 @@ 4.4 rd->destructor(rd->ptr); 4.5 } 4.6 4.7 -void *ucx_default_malloc(UcxMempool *ignore, size_t n) { 4.8 - return malloc(n); 4.9 -} 4.10 -void *ucx_default_calloc(UcxMempool *ignore, size_t n, size_t size) { 4.11 - return calloc(n, size); 4.12 -} 4.13 -void *ucx_default_realloc(UcxMempool *ignore, void *data, size_t n) { 4.14 - return realloc(data, n); 4.15 -} 4.16 - 4.17 UcxMempool *ucx_mempool_new(size_t n) { 4.18 UcxMempool *pool = (UcxMempool*)malloc(sizeof(UcxMempool)); 4.19 if (pool == NULL) return NULL;
5.1 --- a/ucx/mempool.h Fri Oct 05 11:55:36 2012 +0200 5.2 +++ b/ucx/mempool.h Fri Oct 05 13:23:25 2012 +0200 5.3 @@ -6,6 +6,7 @@ 5.4 #define MPOOL_H 5.5 5.6 #include <stddef.h> 5.7 +#include "allocator.h" 5.8 5.9 #ifdef __cplusplus 5.10 extern "C" { 5.11 @@ -19,25 +20,10 @@ 5.12 size_t size; 5.13 } UcxMempool; 5.14 5.15 -typedef void*(*ucx_allocator_malloc)(UcxMempool *pool, size_t n); 5.16 -typedef void*(*ucx_allocator_calloc)(UcxMempool *pool, size_t n, size_t size); 5.17 -typedef void*(*ucx_allocator_realloc)(UcxMempool *pool, void *data, size_t n); 5.18 - 5.19 -typedef struct { 5.20 - UcxMempool *pool; 5.21 - ucx_allocator_malloc malloc; 5.22 - ucx_allocator_calloc calloc; 5.23 - ucx_allocator_realloc realloc; 5.24 -} UcxAllocator; 5.25 - 5.26 -#define UCX_ALLOCATOR_DEFAULT {NULL, \ 5.27 - ucx_default_malloc, ucx_default_calloc, ucx_default_realloc} 5.28 #define UCX_ALLOCATOR_MEMPOOL(pool) {pool, \ 5.29 - ucx_mempool_malloc, ucx_mempool_calloc, ucx_mempool_realloc} 5.30 - 5.31 -void *ucx_default_malloc(UcxMempool *ignore, size_t n); 5.32 -void *ucx_default_calloc(UcxMempool *ignore, size_t n, size_t size); 5.33 -void *ucx_default_realloc(UcxMempool *ignore, void *data, size_t n); 5.34 + (ucx_allocator_malloc) ucx_mempool_malloc, \ 5.35 + (ucx_allocator_calloc) ucx_mempool_calloc, \ 5.36 + (ucx_allocator_realloc) ucx_mempool_realloc} 5.37 5.38 #define ucx_mempool_new_default() ucx_mempool_new(16) 5.39 UcxMempool *ucx_mempool_new(size_t n);