diff --git a/core/os/os2/heap_linux.odin b/core/os/os2/heap_linux.odin index 11cf5ab41..e80bb3dee 100644 --- a/core/os/os2/heap_linux.odin +++ b/core/os/os2/heap_linux.odin @@ -1,10 +1,17 @@ //+private package os2 +import "base:runtime" + import "core:sys/linux" import "core:sync" import "core:mem" +// Use the experimental custom heap allocator (over calling `malloc` etc.). +// This is a switch because there are thread-safety problems that need to be fixed. +// See: https://github.com/odin-lang/Odin/issues/4161 +USE_EXPERIMENTAL_ALLOCATOR :: #config(OS2_LINUX_USE_EXPERIMENTAL_ALLOCATOR, false) + // NOTEs // // All allocations below DIRECT_MMAP_THRESHOLD exist inside of memory "Regions." A region @@ -139,6 +146,8 @@ Region :: struct { memory: [BLOCKS_PER_REGION]Allocation_Header, } +when USE_EXPERIMENTAL_ALLOCATOR { + _heap_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode, size, alignment: int, old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, mem.Allocator_Error) { @@ -219,6 +228,10 @@ _heap_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode, return nil, nil } +} else { + _heap_allocator_proc :: runtime.heap_allocator_proc +} + heap_alloc :: proc(size: int) -> rawptr { if size >= DIRECT_MMAP_THRESHOLD { return _direct_mmap_alloc(size)