diff options
Diffstat (limited to 'code')
| -rw-r--r-- | code/runtime.odin | 38 | ||||
| -rw-r--r-- | code/win32.odin | 2 |
2 files changed, 24 insertions, 16 deletions
diff --git a/code/runtime.odin b/code/runtime.odin index 21a00c8b9..4e79039d1 100644 --- a/code/runtime.odin +++ b/code/runtime.odin @@ -87,6 +87,11 @@ heap_free :: proc(ptr: rawptr) { _ = HeapFree(GetProcessHeap(), 0, ptr) } +current_thread_id :: proc() -> int { + id := GetCurrentThreadId() + return id as int +} + memory_zero :: proc(data: rawptr, len: int) { llvm_memset_64bit :: proc(dst: rawptr, val: byte, len: int, align: i32, is_volatile: bool) #foreign "llvm.memset.p0i8.i64" llvm_memset_64bit(data, 0, len, 1, false) @@ -224,7 +229,7 @@ Allocator :: struct { Context :: struct { - thread_ptr: rawptr + thread_id: int allocator: Allocator @@ -235,45 +240,48 @@ Context :: struct { #thread_local __context: Context -DEFAULT_ALIGNMENT :: 2*size_of(int) +DEFAULT_ALIGNMENT :: align_of({4}f32) + +current_context :: proc() -> ^Context { + return ^__context +} -__check_context :: proc(c: ^Context) { +__check_context :: proc() { + c := current_context() assert(c != null) + if c.allocator.procedure == null { c.allocator = __default_allocator() } - if c.thread_ptr == null { - // TODO(bill): - // c.thread_ptr = current_thread_pointer() + if c.thread_id == 0 { + c.thread_id = current_thread_id() } } - alloc :: proc(size: int) -> rawptr #inline { return alloc_align(size, DEFAULT_ALIGNMENT) } alloc_align :: proc(size, alignment: int) -> rawptr #inline { - __check_context(^__context) - a := __context.allocator + __check_context() + a := current_context().allocator return a.procedure(a.data, Allocator.Mode.ALLOC, size, alignment, null, 0, 0) } free :: proc(ptr: rawptr) #inline { - __check_context(^__context) - a := __context.allocator + __check_context() + a := current_context().allocator _ = a.procedure(a.data, Allocator.Mode.FREE, 0, 0, ptr, 0, 0) } free_all :: proc() #inline { - __check_context(^__context) - a := __context.allocator + __check_context() + a := current_context().allocator _ = a.procedure(a.data, Allocator.Mode.FREE_ALL, 0, 0, null, 0, 0) } resize :: proc(ptr: rawptr, old_size, new_size: int) -> rawptr #inline { return resize_align(ptr, old_size, new_size, DEFAULT_ALIGNMENT) } resize_align :: proc(ptr: rawptr, old_size, new_size, alignment: int) -> rawptr #inline { - __check_context(^__context) - a := __context.allocator + a := current_context().allocator return a.procedure(a.data, Allocator.Mode.RESIZE, new_size, alignment, ptr, old_size, 0) } diff --git a/code/win32.odin b/code/win32.odin index f693a4def..5083d6d47 100644 --- a/code/win32.odin +++ b/code/win32.odin @@ -112,7 +112,7 @@ GetQueryPerformanceFrequency :: proc() -> i64 { GetCommandLineA :: proc() -> ^u8 #foreign - +GetCurrentThreadId :: proc() -> u32 #foreign // File Stuff |