aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorLaytan <laytanlaats@hotmail.com>2024-08-28 19:51:22 +0200
committerGitHub <noreply@github.com>2024-08-28 19:51:22 +0200
commiteb6e5ee3a1ebfec58f2b1bb3a361d329f8d2c9ab (patch)
tree3fa7d14e87f603754d137327639a928967515e19 /core
parent17d10b72d597d0a7c251ba4e716739dd8e93b6f7 (diff)
parent5e850e24d6c4adffc5688f6b2f73556d727f1b86 (diff)
Merge pull request #4162 from laytan/os2-disable-custom-heap-allocator
os2: disable custom heap allocator
Diffstat (limited to 'core')
-rw-r--r--core/os/os2/heap_linux.odin13
1 files changed, 13 insertions, 0 deletions
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)