| 1 | external unlock: Mutex.t -> unit = "caml_mutex_unlock" |
| 2 | |
| 3 | (* Critical sections : |
| 4 | - Mutex.lock does not poll on leaving the blocking section |
| 5 | since 4.12. |
| 6 | - Never inline, to avoid theoretically-possible reorderings with |
| 7 | flambda. |
| 8 | - Inline the call to Mutex.unlock to avoid polling in bytecode. |
| 9 | (workaround to the lack of masking) *) |
| 10 | let[@inline never] with_lock m ~scope = |
| 11 | let () = Mutex.lock m (* BEGIN ATOMIC *) in |
| 12 | match (* END ATOMIC *) scope () with |
| 13 | | (* BEGIN ATOMIC *) x -> unlock m ; (* END ATOMIC *) x |
| 14 | | (* BEGIN ATOMIC *) exception e -> unlock m ; (* END ATOMIC *) raise e |