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) TryLockWithContext ¶ added in v1.34.0
func (s *KeyLockerContext) TryLockWithContext(ID string, ctx context.Context) bool
TryLockWithContext tries to lock the mutex with a context. If the context is canceled while waiting for the lock, the lock attempt is aborted.
func (*KeyLockerContext) Unlock ¶ added in v1.34.0
func (s *KeyLockerContext) Unlock(ID string)
Unlock unlocks a specific item by it's ID
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()