Cauldron2D.Ledger.Lock (Cauldron2D v0.2.6)

Copy Markdown View Source

The lock that keeps a ledger file to one operating system process: <path>.lock, holding the process id of the holder. A lock whose process is gone, or is no longer an Erlang VM (its id since reused by another program), counts as free; a file a DETS table of this process already has open is held. The process is looked up with ps on Unix and tasklist on Windows.

Summary

Functions

The operating system process holding the file's lock, or nil.

Give the file's lock up, when this process holds it.

Take the file's lock for this process: :ok, or {:error, {:held, pid}} when another live process holds it.

Functions

holder(path)

@spec holder(Path.t()) :: pos_integer() | nil

The operating system process holding the file's lock, or nil.

release(path)

@spec release(Path.t()) :: :ok

Give the file's lock up, when this process holds it.

take(path)

@spec take(Path.t()) :: :ok | {:error, {:held, pos_integer()}}

Take the file's lock for this process: :ok, or {:error, {:held, pid}} when another live process holds it.