Documentation ¶
Overview ¶
On-disk mutex protecting a resource
A lock is represented on disk by a directory of a particular name, containing an information file. Taking a lock is done by renaming a temporary directory into place. We use temporary directories because for all filesystems we believe that exactly one attempt to claim the lock will succeed and the others will fail.
Index ¶
- Constants
- Variables
- type Lock
- func (lock *Lock) BreakLock() error
- func (lock *Lock) IsLockHeld() bool
- func (lock *Lock) IsLocked() bool
- func (lock *Lock) Lock(message string) error
- func (lock *Lock) LockWithFunc(message string, continueFunc func() error) error
- func (lock *Lock) LockWithTimeout(duration time.Duration, message string) error
- func (lock *Lock) Message() string
- func (lock *Lock) Unlock() error
Constants ¶
const (
// NameRegexp specifies the regular expression used to identify valid lock names.
NameRegexp = "^[a-z]+[a-z0-9.-]*$"
)
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
func NewLock ¶
NewLock returns a new lock with the given name within the given lock directory, without acquiring it. The lock name must match the regular expression defined by NameRegexp.
func (*Lock) IsLockHeld ¶
IsLockHeld returns whether the lock is currently held by the receiver.
func (*Lock) Lock ¶
Lock blocks until it is able to acquire the lock. Since we are dealing with sharing and locking using the filesystem, it is good behaviour to provide a message that is saved with the lock. This is output in debugging information, and can be queried by any other Lock dealing with the same lock name and lock directory.
func (*Lock) LockWithFunc ¶
LockWithFunc blocks until it is able to acquire the lock. If the lock is failed to be acquired, the continueFunc is called prior to the sleeping. If the continueFunc returns an error, that error is returned from LockWithFunc.
func (*Lock) LockWithTimeout ¶
LockWithTimeout tries to acquire the lock. If it cannot acquire the lock within the given duration, it returns ErrTimeout. See `Lock` for information about the message.