aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/daemon/memorypool.c11
-rw-r--r--src/daemon/memorypool.h32
2 files changed, 31 insertions, 12 deletions
diff --git a/src/daemon/memorypool.c b/src/daemon/memorypool.c
index 329a11c0..32f5217f 100644
--- a/src/daemon/memorypool.c
+++ b/src/daemon/memorypool.c
@@ -42,6 +42,11 @@
42 */ 42 */
43#define ROUND_TO_ALIGN(n) ((n+(ALIGN_SIZE-1)) & (~(ALIGN_SIZE-1))) 43#define ROUND_TO_ALIGN(n) ((n+(ALIGN_SIZE-1)) & (~(ALIGN_SIZE-1)))
44 44
45
46/**
47 * Handle for a memory pool. Pools are not reentrant and must not be
48 * used by multiple threads.
49 */
45struct MemoryPool 50struct MemoryPool
46{ 51{
47 52
@@ -71,6 +76,7 @@ struct MemoryPool
71 int is_mmap; 76 int is_mmap;
72}; 77};
73 78
79
74/** 80/**
75 * Create a memory pool. 81 * Create a memory pool.
76 * 82 *
@@ -110,6 +116,7 @@ MHD_pool_create (size_t max)
110 return pool; 116 return pool;
111} 117}
112 118
119
113/** 120/**
114 * Destroy a memory pool. 121 * Destroy a memory pool.
115 */ 122 */
@@ -125,6 +132,7 @@ MHD_pool_destroy (struct MemoryPool *pool)
125 free (pool); 132 free (pool);
126} 133}
127 134
135
128/** 136/**
129 * Allocate size bytes from the pool. 137 * Allocate size bytes from the pool.
130 * @return NULL if the pool cannot support size more 138 * @return NULL if the pool cannot support size more
@@ -152,6 +160,7 @@ MHD_pool_allocate (struct MemoryPool *pool,
152 return ret; 160 return ret;
153} 161}
154 162
163
155/** 164/**
156 * Reallocate a block of memory obtained from the pool. 165 * Reallocate a block of memory obtained from the pool.
157 * This is particularly efficient when growing or 166 * This is particularly efficient when growing or
@@ -209,6 +218,7 @@ MHD_pool_reallocate (struct MemoryPool *pool,
209 return NULL; 218 return NULL;
210} 219}
211 220
221
212/** 222/**
213 * Clear all entries from the memory pool except 223 * Clear all entries from the memory pool except
214 * for "keep" of the given "size". 224 * for "keep" of the given "size".
@@ -237,5 +247,4 @@ MHD_pool_reset (struct MemoryPool *pool,
237} 247}
238 248
239 249
240
241/* end of memorypool.c */ 250/* end of memorypool.c */
diff --git a/src/daemon/memorypool.h b/src/daemon/memorypool.h
index 51f81674..3dfd4dcc 100644
--- a/src/daemon/memorypool.h
+++ b/src/daemon/memorypool.h
@@ -37,17 +37,22 @@
37 */ 37 */
38struct MemoryPool; 38struct MemoryPool;
39 39
40
40/** 41/**
41 * Create a memory pool. 42 * Create a memory pool.
42 * 43 *
43 * @param max maximum size of the pool 44 * @param max maximum size of the pool
44 */ 45 */
45struct MemoryPool *MHD_pool_create (size_t max); 46struct MemoryPool *
47MHD_pool_create (size_t max);
48
46 49
47/** 50/**
48 * Destroy a memory pool. 51 * Destroy a memory pool.
49 */ 52 */
50void MHD_pool_destroy (struct MemoryPool *pool); 53void
54MHD_pool_destroy (struct MemoryPool *pool);
55
51 56
52/** 57/**
53 * Allocate size bytes from the pool. 58 * Allocate size bytes from the pool.
@@ -58,8 +63,10 @@ void MHD_pool_destroy (struct MemoryPool *pool);
58 * @return NULL if the pool cannot support size more 63 * @return NULL if the pool cannot support size more
59 * bytes 64 * bytes
60 */ 65 */
61void *MHD_pool_allocate (struct MemoryPool *pool, 66void *
62 size_t size, int from_end); 67MHD_pool_allocate (struct MemoryPool *pool,
68 size_t size, int from_end);
69
63 70
64/** 71/**
65 * Reallocate a block of memory obtained from the pool. 72 * Reallocate a block of memory obtained from the pool.
@@ -77,10 +84,12 @@ void *MHD_pool_allocate (struct MemoryPool *pool,
77 * NULL if the pool cannot support new_size 84 * NULL if the pool cannot support new_size
78 * bytes (old continues to be valid for old_size) 85 * bytes (old continues to be valid for old_size)
79 */ 86 */
80void *MHD_pool_reallocate (struct MemoryPool *pool, 87void *
81 void *old, 88MHD_pool_reallocate (struct MemoryPool *pool,
82 size_t old_size, 89 void *old,
83 size_t new_size); 90 size_t old_size,
91 size_t new_size);
92
84 93
85/** 94/**
86 * Clear all entries from the memory pool except 95 * Clear all entries from the memory pool except
@@ -90,8 +99,9 @@ void *MHD_pool_reallocate (struct MemoryPool *pool,
90 * @param size how many bytes need to be kept at this address 99 * @param size how many bytes need to be kept at this address
91 * @return addr new address of "keep" (if it had to change) 100 * @return addr new address of "keep" (if it had to change)
92 */ 101 */
93void *MHD_pool_reset (struct MemoryPool *pool, 102void *
94 void *keep, 103MHD_pool_reset (struct MemoryPool *pool,
95 size_t size); 104 void *keep,
105 size_t size);
96 106
97#endif 107#endif