aboutsummaryrefslogtreecommitdiff
path: root/core/runtime
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2019-12-29 18:08:48 +0000
committergingerBill <bill@gingerbill.org>2019-12-29 18:08:48 +0000
commita8a4dc1eb1d70bf54dff983ec70ec5c63fd001a2 (patch)
tree2366eefd8ca19c463e7b2b9cef553440dd502e0b /core/runtime
parent9e9e905431a3c2841fc809f9addbff32b2288d4f (diff)
Make default `context.temp_allocator` thread safe when using `package thread`
Diffstat (limited to 'core/runtime')
-rw-r--r--core/runtime/core.odin9
1 files changed, 6 insertions, 3 deletions
diff --git a/core/runtime/core.odin b/core/runtime/core.odin
index e70f2a52f..d09dfd72b 100644
--- a/core/runtime/core.odin
+++ b/core/runtime/core.odin
@@ -253,7 +253,10 @@ Context :: struct {
derived: any, // May be used for derived data types
}
-global_scratch_allocator_data: mem.Scratch_Allocator;
+@thread_local global_scratch_allocator_data: mem.Scratch_Allocator;
+global_scratch_allocator_proc :: mem.scratch_allocator_proc;
+global_scratch_allocator_init :: mem.scratch_allocator_init;
+global_scratch_allocator_destroy :: mem.scratch_allocator_destroy;
@@ -392,7 +395,7 @@ __init_context :: proc "contextless" (c: ^Context) {
c.allocator.procedure = os.heap_allocator_proc;
c.allocator.data = nil;
- c.temp_allocator.procedure = mem.scratch_allocator_proc;
+ c.temp_allocator.procedure = global_scratch_allocator_proc;
c.temp_allocator.data = &global_scratch_allocator_data;
c.thread_id = os.current_thread_id(); // NOTE(bill): This is "contextless" so it is okay to call
@@ -408,7 +411,7 @@ __init_context :: proc "contextless" (c: ^Context) {
@builtin
init_global_temporary_allocator :: proc(data: []byte, backup_allocator := context.allocator) {
- mem.scratch_allocator_init(&global_scratch_allocator_data, data, backup_allocator);
+ global_scratch_allocator_init(&global_scratch_allocator_data, data, backup_allocator);
}
default_assertion_failure_proc :: proc(prefix, message: string, loc: Source_Code_Location) {