Browse Source

Merge pull request #4162 from laytan/os2-disable-custom-heap-allocator

os2: disable custom heap allocator
Laytan 11 months ago
parent
commit
eb6e5ee3a1
1 changed files with 13 additions and 0 deletions
  1. 13 0
      core/os/os2/heap_linux.odin

+ 13 - 0
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)