mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Merge pull request #4162 from laytan/os2-disable-custom-heap-allocator
os2: disable custom heap allocator
This commit is contained in:
@@ -1,10 +1,17 @@
|
|||||||
//+private
|
//+private
|
||||||
package os2
|
package os2
|
||||||
|
|
||||||
|
import "base:runtime"
|
||||||
|
|
||||||
import "core:sys/linux"
|
import "core:sys/linux"
|
||||||
import "core:sync"
|
import "core:sync"
|
||||||
import "core:mem"
|
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
|
// NOTEs
|
||||||
//
|
//
|
||||||
// All allocations below DIRECT_MMAP_THRESHOLD exist inside of memory "Regions." A region
|
// 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,
|
memory: [BLOCKS_PER_REGION]Allocation_Header,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
when USE_EXPERIMENTAL_ALLOCATOR {
|
||||||
|
|
||||||
_heap_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode,
|
_heap_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode,
|
||||||
size, alignment: int,
|
size, alignment: int,
|
||||||
old_memory: rawptr, old_size: int, loc := #caller_location) -> ([]byte, mem.Allocator_Error) {
|
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
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
_heap_allocator_proc :: runtime.heap_allocator_proc
|
||||||
|
}
|
||||||
|
|
||||||
heap_alloc :: proc(size: int) -> rawptr {
|
heap_alloc :: proc(size: int) -> rawptr {
|
||||||
if size >= DIRECT_MMAP_THRESHOLD {
|
if size >= DIRECT_MMAP_THRESHOLD {
|
||||||
return _direct_mmap_alloc(size)
|
return _direct_mmap_alloc(size)
|
||||||
|
|||||||
Reference in New Issue
Block a user