Cauldron2D.Ledger.Lock (Cauldron2D v0.1.4)

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 counts as free; a file a DETS table of this process already has open is held.

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.