aboutsummaryrefslogtreecommitdiff
path: root/src/common.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-07-10 21:29:49 +0100
committergingerBill <bill@gingerbill.org>2021-07-10 21:29:49 +0100
commited8a6f872dbcd8b195940dec40a0d86d59f11eaa (patch)
treebbf4d7fc301a432583f8f2121742a83c1d4cc6af /src/common.cpp
parent0a61d4bf2b2d6e8c8d0c92410f6dcfd2b6046f86 (diff)
Move things around for sanity checking for multithread preparation
Diffstat (limited to 'src/common.cpp')
-rw-r--r--src/common.cpp6
1 files changed, 6 insertions, 0 deletions
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<void *> 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);