Fri, 05 Oct 2012 13:23:25 +0200
moved allocator to seperate file
function signatures are now "generic" and not restricted to UcxMempool
olaf@13 | 1 | /* |
olaf@13 | 2 | * |
olaf@13 | 3 | */ |
olaf@13 | 4 | |
olaf@13 | 5 | #ifndef MPOOL_H |
olaf@13 | 6 | #define MPOOL_H |
olaf@13 | 7 | |
universe@38 | 8 | #include <stddef.h> |
universe@50 | 9 | #include "allocator.h" |
universe@38 | 10 | |
olaf@13 | 11 | #ifdef __cplusplus |
olaf@13 | 12 | extern "C" { |
olaf@13 | 13 | #endif |
olaf@13 | 14 | |
olaf@13 | 15 | typedef void(*ucx_destructor)(void*); |
olaf@13 | 16 | |
olaf@13 | 17 | typedef struct { |
olaf@13 | 18 | void **data; |
olaf@13 | 19 | size_t ndata; |
olaf@13 | 20 | size_t size; |
olaf@13 | 21 | } UcxMempool; |
olaf@13 | 22 | |
universe@48 | 23 | #define UCX_ALLOCATOR_MEMPOOL(pool) {pool, \ |
universe@50 | 24 | (ucx_allocator_malloc) ucx_mempool_malloc, \ |
universe@50 | 25 | (ucx_allocator_calloc) ucx_mempool_calloc, \ |
universe@50 | 26 | (ucx_allocator_realloc) ucx_mempool_realloc} |
universe@48 | 27 | |
olaf@13 | 28 | #define ucx_mempool_new_default() ucx_mempool_new(16) |
olaf@13 | 29 | UcxMempool *ucx_mempool_new(size_t n); |
universe@15 | 30 | int ucx_mempool_chcap(UcxMempool *pool, size_t newcap); |
olaf@13 | 31 | |
olaf@13 | 32 | void *ucx_mempool_malloc(UcxMempool *pool, size_t n); |
olaf@13 | 33 | void *ucx_mempool_calloc(UcxMempool *pool, size_t nelem, size_t elsize); |
olaf@13 | 34 | void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n); |
olaf@13 | 35 | |
olaf@13 | 36 | void ucx_mempool_free(UcxMempool *pool); |
olaf@13 | 37 | |
olaf@13 | 38 | void ucx_mempool_set_destr(void *ptr, ucx_destructor func); |
olaf@13 | 39 | void ucx_mempool_reg_destr(UcxMempool *pool, void *ptr, ucx_destructor destr); |
olaf@13 | 40 | |
olaf@13 | 41 | |
olaf@13 | 42 | #ifdef __cplusplus |
olaf@13 | 43 | } |
olaf@13 | 44 | #endif |
olaf@13 | 45 | |
olaf@13 | 46 | #endif /* MPOOL_H */ |
olaf@13 | 47 |