Module Eio_fs_unix.Held

A lock held for as long as its holder says, restated as it goes.

type t

The type for a lock this process holds.

val take : sw:Eio.Switch.t -> ?block:block -> ?create:create -> ?contents:string -> ?on_wait:(unit -> unit) -> _ Eio.Path.t -> t

take ~sw path is with_lock over path, held from when it returns until release or the end of sw, whichever comes first. block, create, contents and on_wait are as with_lock's.

val restate : t -> string -> unit

restate h contents replaces the lock file's contents with contents through the held descriptor, so no reader finds the file unlocked between the writes and the hold is kept. It first takes the record lock again on that descriptor, which restores a hold a close of the file elsewhere in this process dropped.

  • raises Lock_unavailable

    when another process took the lock after such a close; nothing is written.

val release : ?contents:string -> t -> unit

release ~contents h writes contents, when present, through the held descriptor and lets the lock go, returning once it is free. Releasing a released lock, or one whose switch has ended, does nothing.