From ed8a6f872dbcd8b195940dec40a0d86d59f11eaa Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 10 Jul 2021 21:29:49 +0100 Subject: Move things around for sanity checking for multithread preparation --- src/common.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/common.cpp') diff --git a/src/common.cpp b/src/common.cpp index 2591ca068..b0b1c3353 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -399,6 +399,7 @@ gb_global Arena permanent_arena = {}; void arena_init(Arena *arena, gbAllocator backing, isize block_size=ARENA_DEFAULT_BLOCK_SIZE) { arena->backing = backing; arena->block_size = block_size; + arena->use_mutex = true; array_init(&arena->blocks, backing, 0, 2); gb_mutex_init(&arena->mutex); } @@ -521,6 +522,7 @@ struct Temp_Allocator { isize curr_offset; gbAllocator backup_allocator; Array leaked_allocations; + gbMutex mutex; }; gb_global Temp_Allocator temporary_allocator_data = {}; @@ -531,6 +533,7 @@ void temp_allocator_init(Temp_Allocator *s, isize size) { s->len = size; s->curr_offset = 0; s->leaked_allocations.allocator = s->backup_allocator; + gb_mutex_init(&s->mutex); } void *temp_allocator_alloc(Temp_Allocator *s, isize size, isize alignment) { @@ -573,6 +576,9 @@ GB_ALLOCATOR_PROC(temp_allocator_proc) { Temp_Allocator *s = cast(Temp_Allocator *)allocator_data; GB_ASSERT_NOT_NULL(s); + gb_mutex_lock(&s->mutex); + defer (gb_mutex_unlock(&s->mutex)); + switch (type) { case gbAllocation_Alloc: return temp_allocator_alloc(s, size, alignment); -- cgit v1.2.3