aboutsummaryrefslogtreecommitdiff
path: root/mempool/src/mempool.c
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2024-03-09 08:36:02 -0800
committer3gg <3gg@shellblade.net>2024-03-09 08:36:02 -0800
commitafe1e1d12e42a0881aff63c766c14e48319b560c (patch)
treea17d08200e0046eb8929812fd2d9116a364ca04f /mempool/src/mempool.c
parent3b3c2c14a1eda5894d5db27bbaf4dd5f9a8c67db (diff)
Define functions to get the number of used blocks.
Diffstat (limited to 'mempool/src/mempool.c')
-rw-r--r--mempool/src/mempool.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/mempool/src/mempool.c b/mempool/src/mempool.c
index b09038b..46f1053 100644
--- a/mempool/src/mempool.c
+++ b/mempool/src/mempool.c
@@ -24,6 +24,7 @@ bool mempool_make_(
24 24
25 pool->block_size_bytes = block_size_bytes; 25 pool->block_size_bytes = block_size_bytes;
26 pool->num_blocks = num_blocks; 26 pool->num_blocks = num_blocks;
27 pool->num_used_blocks = 0;
27 pool->head = 0; 28 pool->head = 0;
28 pool->used = 0; 29 pool->used = 0;
29 pool->trap = true; 30 pool->trap = true;
@@ -91,6 +92,8 @@ void* mempool_alloc_(mempool* pool) {
91 pool->head = head->next_free; 92 pool->head = head->next_free;
92 head->next_free = 0; 93 head->next_free = 0;
93 94
95 pool->num_used_blocks++;
96
94 return block; 97 return block;
95} 98}
96 99
@@ -119,6 +122,8 @@ void mempool_free_(mempool* pool, void** block_ptr) {
119 pool->used = 0; 122 pool->used = 0;
120 } 123 }
121 124
125 pool->num_used_blocks--;
126
122 *block_ptr = 0; 127 *block_ptr = 0;
123} 128}
124 129
@@ -136,9 +141,19 @@ size_t mempool_get_block_index_(const mempool* pool, const void* block) {
136 return block_byte_index / pool->block_size_bytes; 141 return block_byte_index / pool->block_size_bytes;
137} 142}
138 143
144size_t mempool_block_size_bytes_(const mempool* pool) {
145 assert(pool);
146 return pool->block_size_bytes;
147}
148
139size_t mempool_capacity_(const mempool* pool) { 149size_t mempool_capacity_(const mempool* pool) {
140 assert(pool); 150 assert(pool);
141 return pool->num_blocks * pool->block_size_bytes; 151 return pool->num_blocks;
152}
153
154size_t mempool_size_(const mempool* pool) {
155 assert(pool);
156 return pool->num_used_blocks;
142} 157}
143 158
144void mempool_enable_traps_(mempool* pool, bool enable) { 159void mempool_enable_traps_(mempool* pool, bool enable) {