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 |
1.1 --- a/suncc.mk Mon Sep 09 14:26:12 2013 +0200 1.2 +++ b/suncc.mk Sat Dec 21 12:31:31 2013 +0100 1.3 @@ -35,7 +35,7 @@ 1.4 CFLAGS = -Kpic -O 1.5 CFLAGS_D = -Kpic -g 1.6 LDFLAGS = -lm 1.7 -SOLDFLAGS = -lm 1.8 +SOLDFLAGS = -G -lm 1.9 ARFLAGS = -r 1.10 RMFLAGS = -f -R 1.11 MKDIRFLAGS = -p
2.1 --- a/test/prop_tests.c Mon Sep 09 14:26:12 2013 +0200 2.2 +++ b/test/prop_tests.c Sat Dec 21 12:31:31 2013 +0100 2.3 @@ -365,8 +365,7 @@ 2.4 2.5 UCX_TEST(test_ucx_properties2map) { 2.6 UcxMempool *mp = ucx_mempool_new(64); 2.7 - UcxAllocator *a = ucx_mempool_allocator(mp); 2.8 - UcxMap *map = ucx_map_new_a(a, 16); 2.9 + UcxMap *map = ucx_map_new_a(mp->allocator, 16); 2.10 UcxProperties *parser = ucx_properties_new(); 2.11 2.12 UCX_TEST_BEGIN 2.13 @@ -393,7 +392,7 @@ 2.14 2.15 // second test 2.16 ucx_map_free(map); 2.17 - map = ucx_map_new_a(a, 16); 2.18 + map = ucx_map_new_a(mp->allocator, 16); 2.19 2.20 str = "\n#comment\n"; 2.21 ucx_properties_fill(parser, (char*)str, strlen(str));
3.1 --- a/ucx/mempool.c Mon Sep 09 14:26:12 2013 +0200 3.2 +++ b/ucx/mempool.c Sat Dec 21 12:31:31 2013 +0100 3.3 @@ -75,6 +75,20 @@ 3.4 3.5 pool->ndata = 0; 3.6 pool->size = n; 3.7 + 3.8 + UcxAllocator *allocator = (UcxAllocator*)malloc(sizeof(UcxAllocator)); 3.9 + if(!allocator) { 3.10 + free(pool->data); 3.11 + free(pool); 3.12 + return NULL; 3.13 + } 3.14 + allocator->malloc = (ucx_allocator_malloc)ucx_mempool_malloc; 3.15 + allocator->calloc = (ucx_allocator_calloc)ucx_mempool_calloc; 3.16 + allocator->realloc = (ucx_allocator_realloc)ucx_mempool_realloc; 3.17 + allocator->free = (ucx_allocator_free)ucx_mempool_free; 3.18 + allocator->pool = pool; 3.19 + pool->allocator = allocator; 3.20 + 3.21 return pool; 3.22 } 3.23 3.24 @@ -173,6 +187,7 @@ 3.25 } 3.26 } 3.27 free(pool->data); 3.28 + free(pool->allocator); 3.29 free(pool); 3.30 } 3.31 3.32 @@ -189,16 +204,3 @@ 3.33 ucx_mempool_set_destr(rd, ucx_mempool_shared_destr); 3.34 } 3.35 3.36 -UcxAllocator* ucx_mempool_allocator(UcxMempool *pool) { 3.37 - UcxAllocator *allocator = (UcxAllocator*)ucx_mempool_malloc( 3.38 - pool, sizeof(UcxAllocator)); 3.39 - if(!allocator) { 3.40 - return NULL; 3.41 - } 3.42 - allocator->malloc = (ucx_allocator_malloc)ucx_mempool_malloc; 3.43 - allocator->calloc = (ucx_allocator_calloc)ucx_mempool_calloc; 3.44 - allocator->realloc = (ucx_allocator_realloc)ucx_mempool_realloc; 3.45 - allocator->free = (ucx_allocator_free)ucx_mempool_free; 3.46 - allocator->pool = pool; 3.47 - return allocator; 3.48 -}
4.1 --- a/ucx/mempool.h Mon Sep 09 14:26:12 2013 +0200 4.2 +++ b/ucx/mempool.h Sat Dec 21 12:31:31 2013 +0100 4.3 @@ -57,14 +57,17 @@ 4.4 * UCX mempool structure. 4.5 */ 4.6 typedef struct { 4.7 + /** UcxAllocator based on this pool */ 4.8 + UcxAllocator *allocator; 4.9 + 4.10 /** List of pointers to pooled memory. */ 4.11 - void **data; 4.12 + void **data; 4.13 4.14 /** Count of pooled memory items. */ 4.15 - size_t ndata; 4.16 + size_t ndata; 4.17 4.18 /** Memory pool size. */ 4.19 - size_t size; 4.20 + size_t size; 4.21 } UcxMempool; 4.22 4.23 /** Shorthand for a new default memory pool with a capacity of 16 elements. */ 4.24 @@ -210,14 +213,6 @@ 4.25 */ 4.26 void ucx_mempool_reg_destr(UcxMempool *pool, void *ptr, ucx_destructor destr); 4.27 4.28 -/** 4.29 - * Creates an UcxAllocator based on an UcxMempool. 4.30 - * 4.31 - * @param pool the mempool to create the UcxAllocator for 4.32 - * @return a new UcxAllocator based on the specified pool 4.33 - */ 4.34 -UcxAllocator* ucx_mempool_allocator(UcxMempool *pool); 4.35 - 4.36 #ifdef __cplusplus 4.37 } 4.38 #endif