diff options
author | Danny Holman <dholman@gymli.org> | 2025-08-04 12:32:39 -0500 |
---|---|---|
committer | Danny Holman <dholman@gymli.org> | 2025-08-04 12:32:39 -0500 |
commit | 7a268ae92d44a9f27f4874e1e50413ee33b86dd3 (patch) | |
tree | 47574f2a1d6c6d469e19627aacbcae03ae615dee /core/alloc.c | |
parent | render: vulkan: add check for null pointer for debug (diff) | |
download | rune-engine-7a268ae92d44a9f27f4874e1e50413ee33b86dd3.tar.gz rune-engine-7a268ae92d44a9f27f4874e1e50413ee33b86dd3.tar.zst rune-engine-7a268ae92d44a9f27f4874e1e50413ee33b86dd3.zip |
root: restructuring
Restructure the root of the project such that the engine is siloed from
the rest of the toolchain. Add two new subdirectories that contain an
editor and an offline profiling data analyzer.
Signed-off-by: Danny Holman <dholman@gymli.org>
Diffstat (limited to '')
-rw-r--r-- | engine/core/alloc.c (renamed from core/alloc.c) | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/core/alloc.c b/engine/core/alloc.c index 0ed705c..b75f1d3 100644 --- a/core/alloc.c +++ b/engine/core/alloc.c @@ -21,6 +21,7 @@ #include <rune/core/alloc.h> #include <rune/core/logging.h> +#include <rune/core/profiling.h> #include <stdlib.h> #include <string.h> @@ -55,19 +56,22 @@ static mem_block_t* _find_block(void *ptr) { } static mem_block_t* _alloc_block(size_t sz) { + RUNE_PROFILE_SCOPE("Block allocation"); if (first_block.ptr == NULL) { - first_block.ptr == DEADBLOCK; + first_block.ptr = DEADBLOCK; first_block.sz = 0; } mem_block_t *ret = _find_free_block(sz); if (ret != NULL) { ret->free = 0; + RUNE_PROFILE_END(); return ret->ptr; } ret = malloc(sizeof(mem_block_t)); if (ret == NULL) { + RUNE_PROFILE_END(); log_output(LOG_ERROR, "Cannot allocate block of size %d", sz); return NULL; } @@ -76,15 +80,18 @@ static mem_block_t* _alloc_block(size_t sz) { ret->sz = sz; ret->free = 0; list_add(&ret->list, &first_block.list); + RUNE_PROFILE_END(); log_output(LOG_DEBUG, "Alloc'd block of size %d", sz); return ret; } static void _free_block(mem_block_t *block, int hard) { + RUNE_PROFILE_SCOPE("Block free"); if (hard == 1) { list_del(&block->list); - log_output(LOG_DEBUG, "Freed block of size %d", block->sz); + RUNE_PROFILE_END(); free(block); + log_output(LOG_DEBUG, "Freed block of size %d", block->sz); return; } block->free = 1; @@ -94,13 +101,16 @@ void* rune_alloc(size_t sz) { if (sz == 0) return NULL; + RUNE_PROFILE_SCOPE("Pool allocation"); mem_block_t *block = _find_free_block(sz); if (block != NULL) { block->free = 0; + RUNE_PROFILE_END(); return block->ptr; } block = _alloc_block(sz); + RUNE_PROFILE_END(); return block->ptr; } @@ -108,14 +118,17 @@ void* rune_calloc(size_t nmemb, size_t sz) { if (sz == 0) return NULL; + RUNE_PROFILE_SCOPE("Zero array pool allocation"); mem_block_t *block = _find_free_block(sz); if (block != NULL) { block->free = 0; + RUNE_PROFILE_END(); return block->ptr; } block = _alloc_block(sz); memset(block->ptr, 0, sz); + RUNE_PROFILE_END(); return block->ptr; } @@ -123,10 +136,12 @@ void* rune_realloc(void *ptr, size_t sz) { if (ptr == NULL || sz == 0) return rune_alloc(sz); + RUNE_PROFILE_SCOPE("Pool reallocation"); mem_block_t *old = _find_block(ptr); mem_block_t *new = _alloc_block(sz); memcpy(new->ptr, old->ptr, old->sz); old->free = 1; + RUNE_PROFILE_END(); return new->ptr; } @@ -134,13 +149,18 @@ void rune_free(void *ptr) { if (ptr == NULL) return; + RUNE_PROFILE_SCOPE("Pool free"); mem_block_t *block = _find_block(ptr); - if (block->free == 1) + if (block->free == 1) { + RUNE_PROFILE_END(); return; + } block->free = 1; + RUNE_PROFILE_END(); } void rune_free_all(void) { + RUNE_PROFILE_SCOPE("Pool free all"); list_head_t *temp = &first_block.list; mem_block_t *block; while (temp != NULL) { @@ -154,4 +174,5 @@ void rune_free_all(void) { if (block->ptr != NULL) _free_block(block, 1); } + RUNE_PROFILE_END(); } |