aboutsummaryrefslogtreecommitdiff
path: root/core/mem/mutex_allocator.odin
diff options
context:
space:
mode:
authorKarl Zylinski <karl@zylinski.se>2024-09-17 19:36:17 +0200
committerKarl Zylinski <karl@zylinski.se>2024-09-17 19:36:17 +0200
commit093ade050445b3e348177e30fb1fc9d726f7b289 (patch)
tree5122cfefa5fefbab9d27d5d8adacd8739eeeb5de /core/mem/mutex_allocator.odin
parent3d7b92426081cd9f3197b13f7384a52dbac5379a (diff)
parent6ef779cd5c8260b2e6979e676d28489fd53dd599 (diff)
Merge branch 'master' into file-tags-without-comments
Diffstat (limited to 'core/mem/mutex_allocator.odin')
-rw-r--r--core/mem/mutex_allocator.odin27
1 files changed, 23 insertions, 4 deletions
diff --git a/core/mem/mutex_allocator.odin b/core/mem/mutex_allocator.odin
index 6ede219ac..b8062bca1 100644
--- a/core/mem/mutex_allocator.odin
+++ b/core/mem/mutex_allocator.odin
@@ -3,17 +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{
@@ -22,11 +36,16 @@ mutex_allocator :: proc(m: ^Mutex_Allocator) -> Allocator {
}
}
-mutex_allocator_proc :: proc(allocator_data: rawptr, mode: Allocator_Mode,
- size, alignment: int,
- old_memory: rawptr, old_size: int, loc := #caller_location) -> (result: []byte, err: Allocator_Error) {
+mutex_allocator_proc :: proc(
+ allocator_data: rawptr,
+ mode: Allocator_Mode,
+ size: int,
+ alignment: int,
+ old_memory: rawptr,
+ old_size: int,
+ loc := #caller_location,
+) -> (result: []byte, err: Allocator_Error) {
m := (^Mutex_Allocator)(allocator_data)
-
sync.mutex_guard(&m.mutex)
return m.backing.procedure(m.backing.data, mode, size, alignment, old_memory, old_size, loc)
}