Documentation ¶
Overview ¶
Package flock has helper code for managing inter-processes locks through temporary files.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReleaseAllLocks ¶
func ReleaseAllLocks() error
ReleaseAllLocks releases all the FLocks by removing all the underlying files.
Types ¶
type Mutex ¶
type Mutex struct {
// contains filtered or unexported fields
}
Mutex is a file based inter-process mutex. Mutex should only be created by New, Lock or TryLock.
func Lock ¶
Lock creates a Mutex by using a file named with the given strings, and acquires the inter-process lock, then returns the created Mutex. This is a blocking call and the returned Mutex is guaranteed to hold the lock.
func New ¶
New creates a new file based inter-process mutex which uses the given string as the name of the underlying file. The Mutex created by New does not hold any lock.
func TryLock ¶
TryLock creates a Mutex by using a file named with the given string, and tries to acquire the inter-process lock, then returns the created Mutex. This is a non-blocking call. The returned Mutex may not hold the lock, and should be checked with Locked() to tell if the locked is held by the Mutex.
func (*Mutex) Lock ¶
func (m *Mutex) Lock()
Lock acquires the inter-process lock in a blocking way, it only returns when it has acquired the lock. Panic if the Mutex already holds the lock when calling this function.
func (*Mutex) Locked ¶
Locked returns true if the Mutex holds the lock and valid to call Unlock, false if the Mutex does not hold the lock and valid to call TryLock or Lock. The state of locked/unlocked can only be changed by calling Lock, TryLock and Unlock functions, removing/modifing the underlying files does not change this state.