Sat, 21 Dec 2013 12:31:31 +0100
Added allocator to mempool struct + fixed suncc.mk
suncc.mk | file | annotate | diff | comparison | revisions | |
test/prop_tests.c | file | annotate | diff | comparison | revisions | |
ucx/mempool.c | file | annotate | diff | comparison | revisions | |
ucx/mempool.h | file | annotate | diff | comparison | revisions |
--- a/suncc.mk Mon Sep 09 14:26:12 2013 +0200 +++ b/suncc.mk Sat Dec 21 12:31:31 2013 +0100 @@ -35,7 +35,7 @@ CFLAGS = -Kpic -O CFLAGS_D = -Kpic -g LDFLAGS = -lm -SOLDFLAGS = -lm +SOLDFLAGS = -G -lm ARFLAGS = -r RMFLAGS = -f -R MKDIRFLAGS = -p
--- a/test/prop_tests.c Mon Sep 09 14:26:12 2013 +0200 +++ b/test/prop_tests.c Sat Dec 21 12:31:31 2013 +0100 @@ -365,8 +365,7 @@ UCX_TEST(test_ucx_properties2map) { UcxMempool *mp = ucx_mempool_new(64); - UcxAllocator *a = ucx_mempool_allocator(mp); - UcxMap *map = ucx_map_new_a(a, 16); + UcxMap *map = ucx_map_new_a(mp->allocator, 16); UcxProperties *parser = ucx_properties_new(); UCX_TEST_BEGIN @@ -393,7 +392,7 @@ // second test ucx_map_free(map); - map = ucx_map_new_a(a, 16); + map = ucx_map_new_a(mp->allocator, 16); str = "\n#comment\n"; ucx_properties_fill(parser, (char*)str, strlen(str));
--- a/ucx/mempool.c Mon Sep 09 14:26:12 2013 +0200 +++ b/ucx/mempool.c Sat Dec 21 12:31:31 2013 +0100 @@ -75,6 +75,20 @@ pool->ndata = 0; pool->size = n; + + UcxAllocator *allocator = (UcxAllocator*)malloc(sizeof(UcxAllocator)); + if(!allocator) { + free(pool->data); + free(pool); + return NULL; + } + allocator->malloc = (ucx_allocator_malloc)ucx_mempool_malloc; + allocator->calloc = (ucx_allocator_calloc)ucx_mempool_calloc; + allocator->realloc = (ucx_allocator_realloc)ucx_mempool_realloc; + allocator->free = (ucx_allocator_free)ucx_mempool_free; + allocator->pool = pool; + pool->allocator = allocator; + return pool; } @@ -173,6 +187,7 @@ } } free(pool->data); + free(pool->allocator); free(pool); } @@ -189,16 +204,3 @@ ucx_mempool_set_destr(rd, ucx_mempool_shared_destr); } -UcxAllocator* ucx_mempool_allocator(UcxMempool *pool) { - UcxAllocator *allocator = (UcxAllocator*)ucx_mempool_malloc( - pool, sizeof(UcxAllocator)); - if(!allocator) { - return NULL; - } - allocator->malloc = (ucx_allocator_malloc)ucx_mempool_malloc; - allocator->calloc = (ucx_allocator_calloc)ucx_mempool_calloc; - allocator->realloc = (ucx_allocator_realloc)ucx_mempool_realloc; - allocator->free = (ucx_allocator_free)ucx_mempool_free; - allocator->pool = pool; - return allocator; -}
--- a/ucx/mempool.h Mon Sep 09 14:26:12 2013 +0200 +++ b/ucx/mempool.h Sat Dec 21 12:31:31 2013 +0100 @@ -57,14 +57,17 @@ * UCX mempool structure. */ typedef struct { + /** UcxAllocator based on this pool */ + UcxAllocator *allocator; + /** List of pointers to pooled memory. */ - void **data; + void **data; /** Count of pooled memory items. */ - size_t ndata; + size_t ndata; /** Memory pool size. */ - size_t size; + size_t size; } UcxMempool; /** Shorthand for a new default memory pool with a capacity of 16 elements. */ @@ -210,14 +213,6 @@ */ void ucx_mempool_reg_destr(UcxMempool *pool, void *ptr, ucx_destructor destr); -/** - * Creates an UcxAllocator based on an UcxMempool. - * - * @param pool the mempool to create the UcxAllocator for - * @return a new UcxAllocator based on the specified pool - */ -UcxAllocator* ucx_mempool_allocator(UcxMempool *pool); - #ifdef __cplusplus } #endif