aboutsummaryrefslogtreecommitdiff
path: root/mempool/src
diff options
context:
space:
mode:
Diffstat (limited to 'mempool/src')
-rw-r--r--mempool/src/mempool.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/mempool/src/mempool.c b/mempool/src/mempool.c
index 1100dad..b09038b 100644
--- a/mempool/src/mempool.c
+++ b/mempool/src/mempool.c
@@ -1,5 +1,7 @@
1#include "mempool.h" 1#include "mempool.h"
2 2
3#include <cassert.h>
4
3#include <stdlib.h> 5#include <stdlib.h>
4#include <string.h> 6#include <string.h>
5 7
@@ -24,6 +26,7 @@ bool mempool_make_(
24 pool->num_blocks = num_blocks; 26 pool->num_blocks = num_blocks;
25 pool->head = 0; 27 pool->head = 0;
26 pool->used = 0; 28 pool->used = 0;
29 pool->trap = true;
27 30
28 // Initialize blocks and block info. 31 // Initialize blocks and block info.
29 if (!block_info) { 32 if (!block_info) {
@@ -74,6 +77,9 @@ void* mempool_alloc_(mempool* pool) {
74 77
75 BlockInfo* head = &pool->block_info[pool->head]; 78 BlockInfo* head = &pool->block_info[pool->head];
76 if (head->used) { 79 if (head->used) {
80 if (pool->trap) {
81 FAIL("mempool allocation failed, increase the pool's capacity.");
82 }
77 return 0; // Pool is full. 83 return 0; // Pool is full.
78 } 84 }
79 85
@@ -134,3 +140,8 @@ size_t mempool_capacity_(const mempool* pool) {
134 assert(pool); 140 assert(pool);
135 return pool->num_blocks * pool->block_size_bytes; 141 return pool->num_blocks * pool->block_size_bytes;
136} 142}
143
144void mempool_enable_traps_(mempool* pool, bool enable) {
145 assert(pool);
146 pool->trap = enable;
147}