Tezos_stdlib_unix.Lwt_lock_file
Simple abstraction over Unix lockfiles
val lock :
when_locked:[ `Block | `Fail of Tezos_error_monad.Error_monad.error ] ->
filename:string ->
Lwt_unix.file_descr Tezos_error_monad.Error_monad.tzresult Lwt.t
lock ~when_locked ~filename
acquires a lock on the file path
and returns the opened file descriptor (for unlocking). If there is already a lock on path
, this function call is blocking until the previous lock is released. If there is already a lock on filename
, the call will block if when_locked
is `Block
, and will fail if when_locke = `Fail e
.
unlock fd
releases the lock on the opened file descriptor fd
. If there is no lock or if it is already released, this function does nothing.
val with_lock :
when_locked:[ `Block | `Fail of Tezos_error_monad.Error_monad.error ] ->
filename:string ->
(unit -> 'a Tezos_error_monad.Error_monad.tzresult Lwt.t) ->
'a Tezos_error_monad.Error_monad.tzresult Lwt.t
with_lock ~when_locked ~filename f
tries to take a lock on file filename
and calls f
if the lock was successfully taken. If there is already a lock on filename
, the call to f
is blocked until the previous lock is released if when_lock
is `Block
, and will fail with e
if when_lock =
`Fail e
instead. This function may fail with an I/O exception wrapped in the error monad if something unexpected happened.