mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-09 20:33:36 -04:00
12 lines
432 B
OCaml
12 lines
432 B
OCaml
(* Mutex.protect was added in OCaml 5.1, but we want support back to 4.08 *)
|
|
(* cannot inline, otherwise flambda might move code around. (as per Stdlib) *)
|
|
let[@inline never] protect m f =
|
|
Mutex.lock m;
|
|
match f () with
|
|
| x ->
|
|
Mutex.unlock m;
|
|
x
|
|
| exception e ->
|
|
(* NOTE: [unlock] does not poll for asynchronous exceptions *)
|
|
Mutex.unlock m;
|
|
Printexc.raise_with_backtrace e (Printexc.get_raw_backtrace ())
|