[mem]: Document mutex, rollback stack and tracking allocators

This commit is contained in:
flysand7
2024-09-14 10:46:35 +11:00
parent 3ed2ab6e2c
commit 016d1a84d4
4 changed files with 197 additions and 113 deletions
+15
View File
@@ -3,16 +3,31 @@ package mem
import "core:sync"
/*
The data for mutex allocator.
*/
Mutex_Allocator :: struct {
backing: Allocator,
mutex: sync.Mutex,
}
/*
Initialize the mutex allocator.
This procedure initializes the mutex allocator using `backin_allocator` as the
allocator that will be used to pass all allocation requests through.
*/
mutex_allocator_init :: proc(m: ^Mutex_Allocator, backing_allocator: Allocator) {
m.backing = backing_allocator
m.mutex = {}
}
/*
Mutex allocator.
The mutex allocator is a wrapper for allocators that is used to serialize all
allocator requests across multiple threads.
*/
@(require_results)
mutex_allocator :: proc(m: ^Mutex_Allocator) -> Allocator {
return Allocator{