aboutsummaryrefslogtreecommitdiff
path: root/mempool/src
diff options
context:
space:
mode:
Diffstat (limited to 'mempool/src')
-rw-r--r--mempool/src/mempool.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/mempool/src/mempool.c b/mempool/src/mempool.c
index 46f1053..c398c4f 100644
--- a/mempool/src/mempool.c
+++ b/mempool/src/mempool.c
@@ -34,7 +34,7 @@ bool mempool_make_(
34 block_info = calloc(num_blocks, sizeof(BlockInfo)); 34 block_info = calloc(num_blocks, sizeof(BlockInfo));
35 blocks = calloc(num_blocks, block_size_bytes); 35 blocks = calloc(num_blocks, block_size_bytes);
36 pool->dynamic = true; 36 pool->dynamic = true;
37 if ((block_info == 0) || (blocks == 0)) { 37 if ((block_info == nullptr) || (blocks == nullptr)) {
38 return false; 38 return false;
39 } 39 }
40 } else { 40 } else {
@@ -55,19 +55,20 @@ void mempool_del_(mempool* pool) {
55 if (pool->dynamic) { 55 if (pool->dynamic) {
56 if (pool->block_info) { 56 if (pool->block_info) {
57 free(pool->block_info); 57 free(pool->block_info);
58 pool->block_info = 0; 58 pool->block_info = nullptr;
59 } 59 }
60 if (pool->blocks) { 60 if (pool->blocks) {
61 free(pool->blocks); 61 free(pool->blocks);
62 pool->blocks = 0; 62 pool->blocks = nullptr;
63 } 63 }
64 } 64 }
65} 65}
66 66
67void mempool_clear_(mempool* pool) { 67void mempool_clear_(mempool* pool) {
68 assert(pool); 68 assert(pool);
69 pool->head = 0; 69 pool->head = 0;
70 pool->used = 0; 70 pool->used = 0;
71 pool->num_used_blocks = 0;
71 memset(pool->blocks, 0, pool->num_blocks * pool->block_size_bytes); 72 memset(pool->blocks, 0, pool->num_blocks * pool->block_size_bytes);
72 memset(pool->block_info, 0, pool->num_blocks * sizeof(BlockInfo)); 73 memset(pool->block_info, 0, pool->num_blocks * sizeof(BlockInfo));
73 init_free_list(pool); 74 init_free_list(pool);
@@ -81,7 +82,7 @@ void* mempool_alloc_(mempool* pool) {
81 if (pool->trap) { 82 if (pool->trap) {
82 FAIL("mempool allocation failed, increase the pool's capacity."); 83 FAIL("mempool allocation failed, increase the pool's capacity.");
83 } 84 }
84 return 0; // Pool is full. 85 return nullptr; // Pool is full.
85 } 86 }
86 87
87 // Allocate the block. 88 // Allocate the block.
@@ -124,7 +125,7 @@ void mempool_free_(mempool* pool, void** block_ptr) {
124 125
125 pool->num_used_blocks--; 126 pool->num_used_blocks--;
126 127
127 *block_ptr = 0; 128 *block_ptr = nullptr;
128} 129}
129 130
130void* mempool_get_block_(const mempool* pool, size_t block_index) { 131void* mempool_get_block_(const mempool* pool, size_t block_index) {