| 29 #include "cx/mempool.h" |
29 #include "cx/mempool.h" |
| 30 |
30 |
| 31 #include <string.h> |
31 #include <string.h> |
| 32 #include <errno.h> |
32 #include <errno.h> |
| 33 |
33 |
| |
34 /** A memory block in a simple memory pool. */ |
| |
35 struct cx_mempool_memory_s { |
| |
36 /** The destructor. */ |
| |
37 cx_destructor_func destructor; |
| |
38 /** The actual memory. */ |
| |
39 char c[]; |
| |
40 }; |
| |
41 |
| |
42 /** A memory block in an advanced memory pool. */ |
| |
43 struct cx_mempool_memory2_s { |
| |
44 /** The destructor. */ |
| |
45 cx_destructor_func2 destructor; |
| |
46 /** Data for the destructor. */ |
| |
47 void *data; |
| |
48 /** The actual memory. */ |
| |
49 char c[]; |
| |
50 }; |
| |
51 |
| |
52 /** Represents memory that is not allocated by, but registered with a pool. */ |
| |
53 struct cx_mempool_foreign_memory_s { |
| |
54 /** The foreign memory. */ |
| |
55 void* mem; |
| |
56 union { |
| |
57 /** Simple destructor. */ |
| |
58 cx_destructor_func destr; |
| |
59 /** Advanced destructor. */ |
| |
60 cx_destructor_func2 destr2; |
| |
61 }; |
| |
62 /** Data for the advanced destructor. */ |
| |
63 void *destr2_data; |
| |
64 }; |
| |
65 |
| 34 static int cx_mempool_ensure_capacity( |
66 static int cx_mempool_ensure_capacity( |
| 35 struct cx_mempool_s *pool, |
67 struct cx_mempool_s *pool, |
| 36 size_t needed_capacity |
68 size_t needed_capacity |
| 37 ) { |
69 ) { |
| 38 if (needed_capacity <= pool->capacity) return 0; |
70 if (needed_capacity <= pool->capacity) return 0; |