Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type KeyLocker ¶
type KeyLocker struct {
// contains filtered or unexported fields
}
KeyLocker it is a thread safe wrapper of sync.Map Usage: it's used in order to lock specific key in a map to synchronize concurrent access to a code block.
locker.Lock(id) defer locker.Unlock(id)
type KeyLockerContext ¶ added in v1.34.0
type KeyLockerContext struct {
// contains filtered or unexported fields
}
KeyLockerContext is a thread safe wrapper of sync.Map Usage: it's used in order to lock specific key in a map to synchronize concurrent access to a code block. It supports locking with a context. Note KeyLockerContext has almost identical code to KeyLocker but wasn't combined for performance reasons (eg don't want to slow down KeyLocker by adding context support). Feel free to explore DRYing them up if you want to. I looked into using generics for the underlying mutex type, but the performance hit was ~20% in benchmarks.
func NewKeyLockerContext ¶ added in v1.34.0
func NewKeyLockerContext() *KeyLockerContext
NewKeyLockerContext creates KeyLockerContext
func (*KeyLockerContext) Lock ¶ added in v1.34.0
func (s *KeyLockerContext) Lock(ID string)
Lock locks a specific bucket by it's ID to hold any concurrent access to that specific item
do not forget to call Unlock() after locking it.
func (*KeyLockerContext) LockWithContext ¶ added in v1.34.1
func (s *KeyLockerContext) LockWithContext(ID string, ctx context.Context) error
LockWithContext tries to lock the mutex with a context. If the context is canceled while waiting for the lock, the lock attempt is aborted. If the context is done before the lock is acquired, the lock is not acquired and an error is returned. Importantly, LockWithContext does not immediately return an error if the lock is not currently available, rather it will block until the lock is available or the context is done. This behavior "differs" from sync.Mutex.TryLock and sync.Mutex.Lock due to the context/error return value. You must call Unlock if the returned error is nil to release the lock. Do not call Unlock if the returned error is not nil.
func (*KeyLockerContext) Unlock ¶ added in v1.34.0
func (s *KeyLockerContext) Unlock(ID string)
Unlock unlocks a specific item by it's ID. It panics if the item does not exist or exists but is not locked.
type KeyRWLocker ¶ added in v1.25.1
type KeyRWLocker struct {
// contains filtered or unexported fields
}
KeyRWLocker it is a thread safe wrapper of sync.Map Usage: it's used in order to lock/rlock specific key in a map to synchronize concurrent access to a code block.
locker.Lock(id) defer locker.Unlock(id)
or
locker.RLock(id) defer locker.RUnlock(id)
func NewKeyRWLocker ¶ added in v1.25.1
func NewKeyRWLocker() *KeyRWLocker
NewKeyLocker creates Keylocker
func (*KeyRWLocker) Lock ¶ added in v1.25.1
func (s *KeyRWLocker) Lock(ID string)
Lock it locks a specific bucket by it's ID to hold ant concurrent access to that specific item
do not forget calling Unlock() after locking it.
func (*KeyRWLocker) RLock ¶ added in v1.25.1
func (s *KeyRWLocker) RLock(ID string)
RLock it rlocks a specific bucket by it's ID to hold ant concurrent access to that specific item
do not forget calling RUnlock() after rlocking it.
func (*KeyRWLocker) RUnlock ¶ added in v1.25.1
func (s *KeyRWLocker) RUnlock(ID string)
RUnlock it runlocks a specific item by it's ID
func (*KeyRWLocker) Unlock ¶ added in v1.25.1
func (s *KeyRWLocker) Unlock(ID string)
Unlock it unlocks a specific item by it's ID
type ReadPreferringRWMutex ¶ added in v1.31.18
type ReadPreferringRWMutex struct {
// contains filtered or unexported fields
}
func NewReadPreferringRWMutex ¶ added in v1.31.18
func NewReadPreferringRWMutex() *ReadPreferringRWMutex
func (*ReadPreferringRWMutex) Lock ¶ added in v1.31.18
func (m *ReadPreferringRWMutex) Lock()
func (*ReadPreferringRWMutex) RLock ¶ added in v1.31.18
func (m *ReadPreferringRWMutex) RLock()
func (*ReadPreferringRWMutex) RUnlock ¶ added in v1.31.18
func (m *ReadPreferringRWMutex) RUnlock()
func (*ReadPreferringRWMutex) TryLock ¶ added in v1.31.18
func (m *ReadPreferringRWMutex) TryLock() bool
func (*ReadPreferringRWMutex) TryRLock ¶ added in v1.31.18
func (m *ReadPreferringRWMutex) TryRLock() bool
func (*ReadPreferringRWMutex) Unlock ¶ added in v1.31.18
func (m *ReadPreferringRWMutex) Unlock()