Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cond ¶ added in v1.4.0
Cond is similar to a sync.Cond{}, but it encompasses the Mutex{} within itself.
type Mutex ¶
type Mutex interface {
// Lock performs a mutex lock, returning an unlock function
Lock() (unlock func())
}
Mutex defines a wrappable mutex. By forcing unlocks via returned function it makes wrapping much easier
func WithSafety ¶
WithSafety wrapps the supplied Mutex to protect unlock fns from being called multiple times
type MutexMap ¶
type MutexMap struct {
// contains filtered or unexported fields
}
MutexMap is a structure that allows read / write locking per key, performing as you'd expect a map[string]*RWMutex to perform, without you needing to worry about deadlocks between competing read / write locks and the map's own mutex. It uses memory pooling for the internal "mutex" (ish) types and performs self-eviction of keys.
Under the hood this is achieved using a single mutex for the map, state tracking for individual keys, and some sync.Cond{} like structures for sleeping / awaking awaiting goroutines.
type RWCond ¶ added in v1.4.0
RWCond is similar to a sync.Cond{}, but it encompasses the RWMutex{} within itself.
type RWMutex ¶
type RWMutex interface { Mutex // RLock performs a mutex read lock, returning an unlock function RLock() (runlock func()) }
RWMutex defines a wrappable read-write mutex. By forcing unlocks via returned functions it makes wrapping much easier
func WithFuncRW ¶
WithFuncRW wrapps the supplied RWMutex to call the provided hooks on lock / rlock / unlock/ runlock
func WithSafetyRW ¶
WithSafetyRW wrapps the supplied RWMutex to protect unlock fns from being called multiple times
type TimeoutMutex ¶
type TimeoutMutex interface { Mutex // LockFunc is functionally the same as Lock(), but allows setting a custom hook called on timeout LockFunc(func()) func() }
TimeoutMutex defines a Mutex with timeouts on locks
func WithTimeout ¶
func WithTimeout(mu Mutex, d time.Duration) TimeoutMutex
WithTimeout wraps the supplied Mutex to add a timeout
type TimeoutRWMutex ¶
type TimeoutRWMutex interface { RWMutex // LockFunc is functionally the same as Lock(), but allows setting a custom hook called on timeout LockFunc(func()) func() // RLockFunc is functionally the same as RLock(), but allows setting a custom hook called on timeout RLockFunc(func()) func() }
TimeoutRWMutex defines a RWMutex with timeouts on locks
func WithTimeoutRW ¶
func WithTimeoutRW(mu RWMutex, rd, wd time.Duration) TimeoutRWMutex
WithTimeoutRW wraps the supplied RWMutex to add read/write timeouts