Sat, 31 Dec 2011 21:05:59 +0100
Added mempool
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 | |
olaf@13 | 8 | #ifdef __cplusplus |
olaf@13 | 9 | extern "C" { |
olaf@13 | 10 | #endif |
olaf@13 | 11 | |
olaf@13 | 12 | typedef void(*ucx_destructor)(void*); |
olaf@13 | 13 | |
olaf@13 | 14 | typedef struct { |
olaf@13 | 15 | void **data; |
olaf@13 | 16 | size_t ndata; |
olaf@13 | 17 | size_t size; |
olaf@13 | 18 | } UcxMempool; |
olaf@13 | 19 | |
olaf@13 | 20 | #define ucx_mempool_new_default() ucx_mempool_new(16) |
olaf@13 | 21 | UcxMempool *ucx_mempool_new(size_t n); |
olaf@13 | 22 | void ucx_mempool_chcap(UcxMempool *pool, size_t newcap); |
olaf@13 | 23 | |
olaf@13 | 24 | void *ucx_mempool_malloc(UcxMempool *pool, size_t n); |
olaf@13 | 25 | void *ucx_mempool_calloc(UcxMempool *pool, size_t nelem, size_t elsize); |
olaf@13 | 26 | void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n); |
olaf@13 | 27 | |
olaf@13 | 28 | void ucx_mempool_free(UcxMempool *pool); |
olaf@13 | 29 | |
olaf@13 | 30 | void ucx_mempool_set_destr(void *ptr, ucx_destructor func); |
olaf@13 | 31 | void ucx_mempool_reg_destr(UcxMempool *pool, void *ptr, ucx_destructor destr); |
olaf@13 | 32 | |
olaf@13 | 33 | |
olaf@13 | 34 | #ifdef __cplusplus |
olaf@13 | 35 | } |
olaf@13 | 36 | #endif |
olaf@13 | 37 | |
olaf@13 | 38 | #endif /* MPOOL_H */ |
olaf@13 | 39 |