summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOmniscient <omniscient.oce@gmail.com>2024-06-07 12:10:32 +1000
committerOmniscient <omniscient.oce@gmail.com>2024-06-07 12:10:32 +1000
commitf553d66891e6f77b0fa78c279f51a44d1c51ff9f (patch)
tree4e0019b694e86ebde52bf88a883b0d3666fbcdc5 /src
parent34cfaac69eda7eae258d004e4cafd5a816cf9b67 (diff)
add assert back that pool entry is at least as big as a pointer. add debug name for pools
Diffstat (limited to 'src')
-rw-r--r--src/std/mem.c9
-rw-r--r--src/std/mem.h5
2 files changed, 9 insertions, 5 deletions
diff --git a/src/std/mem.c b/src/std/mem.c
index a5321fb..a5a0b88 100644
--- a/src/std/mem.c
+++ b/src/std/mem.c
@@ -46,15 +46,18 @@ void arena_rewind(arena_save savepoint) { savepoint.arena->curr = savepoint.save
// --- Pool
-void_pool void_pool_create(arena* a, u64 capacity, u64 entry_size) {
+void_pool void_pool_create(arena* a, const char* debug_label, u64 capacity, u64 entry_size) {
size_t memory_requirements = capacity * entry_size;
void* backing_buf = arena_alloc(a, memory_requirements);
+ assert(entry_size >= sizeof(void_pool_header)); // TODO: create my own assert with error message
+
void_pool pool = { .capacity = capacity,
.entry_size = entry_size,
.count = 0,
.backing_buffer = backing_buf,
- .free_list_head = NULL };
+ .free_list_head = NULL,
+ .debug_label = debug_label };
void_pool_free_all(&pool);
@@ -99,7 +102,7 @@ void* void_pool_alloc(void_pool* pool, u32* out_raw_handle) {
uintptr_t start = (uintptr_t)pool->backing_buffer;
uintptr_t cur = (uintptr_t)free_node;
TRACE("%ld %ld ", start, cur);
- /* assert(cur > start); */
+ assert(cur > start);
u32 index = (u32)((cur - start) / pool->entry_size);
printf("Index %d\n", index);
if (out_raw_handle != NULL) {
diff --git a/src/std/mem.h b/src/std/mem.h
index 1d508ce..b256e27 100644
--- a/src/std/mem.h
+++ b/src/std/mem.h
@@ -48,9 +48,10 @@ typedef struct void_pool {
u64 count;
void* backing_buffer;
void_pool_header* free_list_head;
+ const char* debug_label;
} void_pool;
-void_pool void_pool_create(arena* a, u64 capacity, u64 entry_size);
+void_pool void_pool_create(arena* a, const char* debug_label, u64 capacity, u64 entry_size);
void void_pool_free_all(void_pool* pool);
bool void_pool_is_empty(void_pool* pool);
bool void_pool_is_full(void_pool* pool);
@@ -68,7 +69,7 @@ void void_pool_dealloc(void_pool* pool, u32 raw_handle);
} Name##_pool; \
\
static Name##_pool Name##_pool_create(arena* a, u64 cap, u64 entry_size) { \
- void_pool p = void_pool_create(a, cap, entry_size); \
+ void_pool p = void_pool_create(a, "\""#Name"\"", cap, entry_size); \
return (Name##_pool){ .inner = p }; \
} \
static inline T* Name##_pool_get(Name##_pool* pool, Name##_handle handle) { \