# HG changeset patch # User Mike Becker # Date 1349436205 -7200 # Node ID ff194559eb41e2d1f84737a9f61b76cb849f9dc0 # Parent 1771360b740dcfbd07d98b9822aa5cc11190c91f moved allocator to seperate file function signatures are now "generic" and not restricted to UcxMempool diff -r 1771360b740d -r ff194559eb41 ucx/Makefile --- a/ucx/Makefile Fri Oct 05 11:55:36 2012 +0200 +++ b/ucx/Makefile Fri Oct 05 13:23:25 2012 +0200 @@ -29,7 +29,7 @@ include ../$(CONF).mk # list of source files -SRC = list.c dlist.c map.c mempool.c string.c test.c +SRC = list.c dlist.c map.c mempool.c string.c test.c allocator.c OBJ = $(SRC:%.c=../build/%.$(OBJ_EXT)) diff -r 1771360b740d -r ff194559eb41 ucx/allocator.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ucx/allocator.c Fri Oct 05 13:23:25 2012 +0200 @@ -0,0 +1,12 @@ +#include "allocator.h" +#include + +void *ucx_default_malloc(void *ignore, size_t n) { + return malloc(n); +} +void *ucx_default_calloc(void *ignore, size_t n, size_t size) { + return calloc(n, size); +} +void *ucx_default_realloc(void *ignore, void *data, size_t n) { + return realloc(data, n); +} diff -r 1771360b740d -r ff194559eb41 ucx/allocator.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ucx/allocator.h Fri Oct 05 13:23:25 2012 +0200 @@ -0,0 +1,32 @@ +#ifndef ALLOCATOR_H +#define ALLOCATOR_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void*(*ucx_allocator_malloc)(void *pool, size_t n); +typedef void*(*ucx_allocator_calloc)(void *pool, size_t n, size_t size); +typedef void*(*ucx_allocator_realloc)(void *pool, void *data, size_t n); + +typedef struct { + void *pool; + ucx_allocator_malloc malloc; + ucx_allocator_calloc calloc; + ucx_allocator_realloc realloc; +} UcxAllocator; + +void *ucx_default_malloc(void *ignore, size_t n); +void *ucx_default_calloc(void *ignore, size_t n, size_t size); +void *ucx_default_realloc(void *ignore, void *data, size_t n); + +#define UCX_ALLOCATOR_DEFAULT {NULL, \ + ucx_default_malloc, ucx_default_calloc, ucx_default_realloc} + +#ifdef __cplusplus +} +#endif + +#endif /* ALLOCATOR_H */ diff -r 1771360b740d -r ff194559eb41 ucx/mempool.c --- a/ucx/mempool.c Fri Oct 05 11:55:36 2012 +0200 +++ b/ucx/mempool.c Fri Oct 05 13:23:25 2012 +0200 @@ -24,16 +24,6 @@ rd->destructor(rd->ptr); } -void *ucx_default_malloc(UcxMempool *ignore, size_t n) { - return malloc(n); -} -void *ucx_default_calloc(UcxMempool *ignore, size_t n, size_t size) { - return calloc(n, size); -} -void *ucx_default_realloc(UcxMempool *ignore, void *data, size_t n) { - return realloc(data, n); -} - UcxMempool *ucx_mempool_new(size_t n) { UcxMempool *pool = (UcxMempool*)malloc(sizeof(UcxMempool)); if (pool == NULL) return NULL; diff -r 1771360b740d -r ff194559eb41 ucx/mempool.h --- a/ucx/mempool.h Fri Oct 05 11:55:36 2012 +0200 +++ b/ucx/mempool.h Fri Oct 05 13:23:25 2012 +0200 @@ -6,6 +6,7 @@ #define MPOOL_H #include +#include "allocator.h" #ifdef __cplusplus extern "C" { @@ -19,25 +20,10 @@ size_t size; } UcxMempool; -typedef void*(*ucx_allocator_malloc)(UcxMempool *pool, size_t n); -typedef void*(*ucx_allocator_calloc)(UcxMempool *pool, size_t n, size_t size); -typedef void*(*ucx_allocator_realloc)(UcxMempool *pool, void *data, size_t n); - -typedef struct { - UcxMempool *pool; - ucx_allocator_malloc malloc; - ucx_allocator_calloc calloc; - ucx_allocator_realloc realloc; -} UcxAllocator; - -#define UCX_ALLOCATOR_DEFAULT {NULL, \ - ucx_default_malloc, ucx_default_calloc, ucx_default_realloc} #define UCX_ALLOCATOR_MEMPOOL(pool) {pool, \ - ucx_mempool_malloc, ucx_mempool_calloc, ucx_mempool_realloc} - -void *ucx_default_malloc(UcxMempool *ignore, size_t n); -void *ucx_default_calloc(UcxMempool *ignore, size_t n, size_t size); -void *ucx_default_realloc(UcxMempool *ignore, void *data, size_t n); + (ucx_allocator_malloc) ucx_mempool_malloc, \ + (ucx_allocator_calloc) ucx_mempool_calloc, \ + (ucx_allocator_realloc) ucx_mempool_realloc} #define ucx_mempool_new_default() ucx_mempool_new(16) UcxMempool *ucx_mempool_new(size_t n);