mutex
import "github.com/juju/mutex"
package mutex provides a named machine level mutex shareable between processes.
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.
doc.go errors.go legacy_mutex_linux.go mutex.go mutex_flock.go
var (
ErrTimeout = errors.New("timeout acquiring mutex")
ErrCancelled = errors.New("cancelled acquiring mutex")
)
type Clock interface {
After(time.Duration) <-chan time.Time
Now() time.Time
}
Clock provides an interface for dealing with clocks.
type Releaser interface {
Release()
}
Releaser defines the Release method that is the only thing that can be done
to a acquired mutex.
func Acquire(spec Spec) (Releaser, error)
Acquire will attempt to acquire the named mutex. If the Timout value
is hit, ErrTimeout is returned. If the Cancel channel is signalled,
ErrCancelled is returned.
type Spec struct {
Name string
Clock Clock
Delay time.Duration
Timeout time.Duration
Cancel <-chan struct{}
}
Spec defines the name of the mutex and behaviour of the Acquire function.
func (s *Spec) Validate() error
Validate checks the attributes of Spec for validity.
Generated by godoc2md