diff options
Diffstat (limited to 'mempool')
| -rw-r--r-- | mempool/src/mempool.c | 5 | ||||
| -rw-r--r-- | mempool/test/mempool_test.c | 8 |
2 files changed, 8 insertions, 5 deletions
diff --git a/mempool/src/mempool.c b/mempool/src/mempool.c index 444d602..c398c4f 100644 --- a/mempool/src/mempool.c +++ b/mempool/src/mempool.c | |||
| @@ -66,8 +66,9 @@ void mempool_del_(mempool* pool) { | |||
| 66 | 66 | ||
| 67 | void mempool_clear_(mempool* pool) { | 67 | void 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); |
diff --git a/mempool/test/mempool_test.c b/mempool/test/mempool_test.c index 843f7e7..4c55e4b 100644 --- a/mempool/test/mempool_test.c +++ b/mempool/test/mempool_test.c | |||
| @@ -178,16 +178,18 @@ TEST_CASE(mem_clear_then_reuse) { | |||
| 178 | 178 | ||
| 179 | // Allocate chunks, contents not important. | 179 | // Allocate chunks, contents not important. |
| 180 | for (int i = 0; i < NUM_BLOCKS; ++i) { | 180 | for (int i = 0; i < NUM_BLOCKS; ++i) { |
| 181 | int* chunk = mempool_alloc(&mem); | 181 | const int* chunk = mempool_alloc(&mem); |
| 182 | TEST_TRUE(chunk != 0); | 182 | TEST_TRUE(chunk != nullptr); |
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | mempool_clear(&mem); | 185 | mempool_clear(&mem); |
| 186 | TEST_EQUAL(mempool_size(&mem), 0); | ||
| 187 | TEST_EQUAL(mempool_capacity(&mem), NUM_BLOCKS); | ||
| 186 | 188 | ||
| 187 | // Allocate chunks and assign values 0..N. | 189 | // Allocate chunks and assign values 0..N. |
| 188 | for (int i = 0; i < NUM_BLOCKS; ++i) { | 190 | for (int i = 0; i < NUM_BLOCKS; ++i) { |
| 189 | int* chunk = mempool_alloc(&mem); | 191 | int* chunk = mempool_alloc(&mem); |
| 190 | TEST_TRUE(chunk != 0); | 192 | TEST_TRUE(chunk != nullptr); |
| 191 | *chunk = i + 1; | 193 | *chunk = i + 1; |
| 192 | } | 194 | } |
| 193 | 195 | ||
