mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-05 19:00:33 -05:00
fix: in Lock, prevent flambda from reordering mutex-protected operations
inspired by Mutex.protect in the stdlib, which is also `[@inline never]` for this reason
This commit is contained in:
parent
0959004b11
commit
189a95a514
1 changed files with 6 additions and 6 deletions
|
|
@ -5,13 +5,13 @@ type 'a t = {
|
||||||
|
|
||||||
let create content : _ t = { mutex = Mutex.create (); content }
|
let create content : _ t = { mutex = Mutex.create (); content }
|
||||||
|
|
||||||
let with_ (self : _ t) f =
|
let[@inline never] with_ (self : _ t) f =
|
||||||
Mutex.lock self.mutex;
|
Mutex.lock self.mutex;
|
||||||
try
|
match f self.content with
|
||||||
let x = f self.content in
|
| x ->
|
||||||
Mutex.unlock self.mutex;
|
Mutex.unlock self.mutex;
|
||||||
x
|
x
|
||||||
with e ->
|
| exception e ->
|
||||||
Mutex.unlock self.mutex;
|
Mutex.unlock self.mutex;
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
|
@ -24,13 +24,13 @@ let[@inline] update_map l f =
|
||||||
l.content <- x';
|
l.content <- x';
|
||||||
y)
|
y)
|
||||||
|
|
||||||
let get l =
|
let[@inline never] get l =
|
||||||
Mutex.lock l.mutex;
|
Mutex.lock l.mutex;
|
||||||
let x = l.content in
|
let x = l.content in
|
||||||
Mutex.unlock l.mutex;
|
Mutex.unlock l.mutex;
|
||||||
x
|
x
|
||||||
|
|
||||||
let set l x =
|
let[@inline never] set l x =
|
||||||
Mutex.lock l.mutex;
|
Mutex.lock l.mutex;
|
||||||
l.content <- x;
|
l.content <- x;
|
||||||
Mutex.unlock l.mutex
|
Mutex.unlock l.mutex
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue