Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Mutex.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
module type S = sig exception Locked val exclusively : (unit -> 'a) -> 'a val run : (unit -> 'a) -> 'a end module Make () = struct exception Locked let () = Printexc.register_printer @@ function | Locked -> Some "Mutex already locked" | _ -> None module S = State.Make(struct type state = bool end) let exclusively f = if S.get() then raise Locked else begin S.set true; match f () with | ans -> S.set false; ans | exception e -> S.set false; raise e end let run f = S.run ~init:false f end