Documentation
¶
Index ¶
- func Exclusive(ctx context.Context, path string) (func(), error)
- func Explain(lock *flock.T, timeout time.Duration, err error) error
- func Func(lockPath string, timeout time.Duration, intent string, f func() error) error
- func Lock(lockPath string, timeout time.Duration, intent string) (func(), error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Exclusive ¶
Exclusive takes an exclusive lock on the file at path, creating it and its directory, and returns the function releasing it. It waits for the lock until ctx is done.
It is for the short sections that must not interleave with the same section run by another process or another goroutine: the lock is held by the open file description, which every call opens anew, so it excludes the goroutines of this process as it excludes the other processes. A lock held by the process, as a fcntl lock is, would let every goroutine of the daemon in at once.
A holder dying releases the lock with its descriptors, so a crash leaves nothing to clean up and nobody to wait for.
The file is never removed. Removing a lock file on release lets a waiter that opened it before the removal and a newcomer that creates it after both hold the lock, on two files of the same name.
func Explain ¶
Explain returns err, the failure to take lock within timeout, with what holds the lock: the pid of the holder and its command line while it runs, its intent, its session and since when, as the holder wrote them in the lock file.
A lock released in the meantime, or taken by a holder that has not written who it is yet, is told as such.
Types ¶
This section is empty.