Documentation
¶
Overview ¶
package mutex provides a named machine level mutex shareable between processes. [godoc-link-here]
Mutexes have names. Each each name, only one mutex for that name can be acquired at the same time, within and across process boundaries. If a process dies while the mutex is held, the mutex is automatically released.
The Linux/MacOS implementation uses flock, while the Windows implementation uses a named mutex. On Linux, we also acquire an abstract domain socket for compatibility with older implementations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrTimeout = errors.New("timeout acquiring mutex") ErrCancelled = errors.New("cancelled acquiring mutex") )
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock interface {
// After waits for the duration to elapse and then sends the
// current time on the returned channel.
After(time.Duration) <-chan time.Time
// Now returns the current clock time.
Now() time.Time
}
Clock provides an interface for dealing with clocks.
type Environment ¶
type Environment interface {
// LookupEnv retrieves the value of the environment variable named
// by the key.
LookupEnv(string) (string, bool)
// Getenv retrieves the value of the environment variable named by the key.
Getenv(string) string
}
Environment defines a simple interface with interacting with environmental variables.
type Releaser ¶
type Releaser interface {
// Release releases the mutex. Release may be called multiple times, but
// only the first call will release this instance of the mutex. Release is
// unable to release the mutex successfully it will call panic to forcibly
// release the mutex.
Release()
}
Releaser defines the Release method that is the only thing that can be done to a acquired mutex.
type Spec ¶
type Spec struct {
// Name is required, and must start with a letter and contain at most
// 40 letters, numbers or dashes.
Name string
// Clock must be provided and is exposed for testing purposes.
Clock Clock
// Delay defines how often to check for lock acquisition, for
// compatibility code that requires polling.
Delay time.Duration
// Timeout allows the caller to specify how long to wait. If Timeout
// is zero, then the call will block forever.
Timeout time.Duration
// Cancel if signalled will cause the Acquire method to return with ErrCancelled.
Cancel <-chan struct{}
}
Spec defines the name of the mutex and behaviour of the Acquire function.