fix: in Lock, prevent flambda from reordering mutex-protected operations
Some checks failed
github pages / Deploy doc (push) Has been cancelled
Build and Test / build (push) Has been cancelled
Build and Test / build-compat (push) Has been cancelled
Build and Test / format (push) Has been cancelled

inspired by Mutex.protect in the stdlib, which is also `[@inline never]`
for this reason
This commit is contained in:
Simon Cruanes 2025-11-19 12:28:09 -05:00
parent 0959004b11
commit 189a95a514
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4

View file

@ -5,13 +5,13 @@ type 'a t = {
let create content : _ t = { mutex = Mutex.create (); content }
let with_ (self : _ t) f =
let[@inline never] with_ (self : _ t) f =
Mutex.lock self.mutex;
try
let x = f self.content in
match f self.content with
| x ->
Mutex.unlock self.mutex;
x
with e ->
| exception e ->
Mutex.unlock self.mutex;
raise e
@ -24,13 +24,13 @@ let[@inline] update_map l f =
l.content <- x';
y)
let get l =
let[@inline never] get l =
Mutex.lock l.mutex;
let x = l.content in
Mutex.unlock l.mutex;
x
let set l x =
let[@inline never] set l x =
Mutex.lock l.mutex;
l.content <- x;
Mutex.unlock l.mutex