Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrHeld indicates the lock is currently held by an exclusive holder. ErrHeld = errors.New("lock held") // ErrBusy indicates the lock could not be acquired because only shared askers were present. // It is distinct from ErrHeld and does not wrap it. ErrBusy = errors.New("lock busy") // ErrTimeout indicates waiting for the lock timed out. ErrTimeout = errors.New("lock timeout") // ErrNotSupported indicates that filelock is not supported on the current platform. ErrNotSupported = errors.New("filelock: locking is not supported on this platform") )
Functions ¶
Types ¶
type FileLock ¶
type FileLock struct {
// contains filtered or unexported fields
}
FileLock represents an acquired, open file lock.
func Lock ¶
Lock acquires the exclusive file lock on path, waiting up to timeout with jittered backoff.
The lockfile path must be dedicated to filelock: taking an exclusive lock on an existing regular file truncates it when writing the holder stamp. The file is created if absent and is never removed.
func TryLock ¶
TryLock attempts to acquire the exclusive file lock on path without waiting.
The lockfile path must be dedicated to filelock: taking an exclusive lock on an existing regular file truncates it when writing the holder stamp. The file is created if absent and is never removed.
func (*FileLock) Previous ¶
Previous returns the stamp of the previous unreleased holder (e.g. killed/crashed), or nil.
type HeldError ¶
HeldError describes a refusal because another process holds the lock, or a timeout occurred while waiting for the lock.
func AsHeldError ¶
AsHeldError reports whether err is a *HeldError.
type Stamp ¶
Stamp records diagnostic details of who holds the lock: PID, host, start time, and label.
func ReadStamp ¶
ReadStamp reads and parses the Stamp from path without acquiring the lock. It opens with O_RDONLY and does not block on FIFOs.