Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TimedLocker ¶
type TimedLocker interface { Lock(string) LockWithTimeout(name string, timeout time.Duration) (gotLock bool, holder string) Unlock() }
A TimedLocker represents an object that can be locked and unlocked.
type TimedMutex ¶
type TimedMutex struct {
// contains filtered or unexported fields
}
A TimedMutex is a mutual exclusion lock that provides an additional Lock method that will time out if it cannot acquire the lock.
func NewTimedMutex ¶
func NewTimedMutex() *TimedMutex
NewTimedMutex initializes a new TimedMutex. Its initial state is unlocked.
func (*TimedMutex) Lock ¶
func (m *TimedMutex) Lock(name string)
Lock locks the TimedMutex. name is a string to identify you to callers who fail to acquire the lock.
If the mutex is already in use, the calling goroutine blocks until the mutex is available.
func (*TimedMutex) LockWithTimeout ¶
func (m *TimedMutex) LockWithTimeout(name string, timeout time.Duration) (gotLock bool, holder string)
LockWithTimeout attempts to lock the TimedMutex but returns if it cannot acquire the lock within the time specified. name is a string to identify you to callers who fail to acquire the lock.
The bool returned indicates whether you acquired the lock. The string is the name of the current holder of the lock.
func (*TimedMutex) Unlock ¶
func (m *TimedMutex) Unlock()
Unlock unlocks the TimedMutex. It is a run-time error if the mutex is not locked on entry to Unlock.
A locked TimedMutex is not associated with a particular goroutine. It is allowed for one goroutine to lock a TimedMutex and then arrange for another goroutine to unlock it.