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