Documentation ¶
Overview ¶
Package gmlock implements a concurrent-safe memory-based locker.
Index ¶
- func Lock(key string)
- func LockFunc(key string, f func())
- func RLock(key string)
- func RLockFunc(key string, f func())
- func RUnlock(key string)
- func Remove(key string)
- func TryLock(key string) bool
- func TryLockFunc(key string, f func()) bool
- func TryRLock(key string) bool
- func TryRLockFunc(key string, f func()) bool
- func Unlock(key string)
- type Locker
- func (l *Locker) Clear()
- func (l *Locker) Lock(key string)
- func (l *Locker) LockFunc(key string, f func())
- func (l *Locker) RLock(key string)
- func (l *Locker) RLockFunc(key string, f func())
- func (l *Locker) RUnlock(key string)
- func (l *Locker) Remove(key string)
- func (l *Locker) TryLock(key string) bool
- func (l *Locker) TryLockFunc(key string, f func()) bool
- func (l *Locker) TryRLock(key string) bool
- func (l *Locker) TryRLockFunc(key string, f func()) bool
- func (l *Locker) Unlock(key string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Lock ¶
func Lock(key string)
Lock locks the `key` with writing lock. If there's a write/reading lock the `key`, it will blocks until the lock is released.
func LockFunc ¶
func LockFunc(key string, f func())
LockFunc locks the `key` with writing lock and callback function `f`. If there's a write/reading lock the `key`, it will blocks until the lock is released.
It releases the lock after `f` is executed.
func RLock ¶
func RLock(key string)
RLock locks the `key` with reading lock. If there's a writing lock on `key`, it will blocks until the writing lock is released.
func RLockFunc ¶
func RLockFunc(key string, f func())
RLockFunc locks the `key` with reading lock and callback function `f`. If there's a writing lock the `key`, it will blocks until the lock is released.
It releases the lock after `f` is executed.
func TryLock ¶
TryLock tries locking the `key` with writing lock, it returns true if success, or if there's a write/reading lock the `key`, it returns false.
func TryLockFunc ¶
TryLockFunc locks the `key` with writing lock and callback function `f`. It returns true if success, or else if there's a write/reading lock the `key`, it return false.
It releases the lock after `f` is executed.
func TryRLock ¶
TryRLock tries locking the `key` with reading lock. It returns true if success, or if there's a writing lock on `key`, it returns false.
func TryRLockFunc ¶
TryRLockFunc locks the `key` with reading lock and callback function `f`. It returns true if success, or else if there's a writing lock the `key`, it returns false.
It releases the lock after `f` is executed.
Types ¶
type Locker ¶
type Locker struct {
// contains filtered or unexported fields
}
Locker is a memory based locker. Note that there's no cache expire mechanism for mutex in locker. You need remove certain mutex manually when you do not want use it anymore.
func New ¶
func New() *Locker
New creates and returns a new memory locker. A memory locker can lock/unlock with dynamic string key.
func (*Locker) Lock ¶
Lock locks the `key` with writing lock. If there's a write/reading lock the `key`, it will block until the lock is released.
func (*Locker) LockFunc ¶
LockFunc locks the `key` with writing lock and callback function `f`. If there's a write/reading lock the `key`, it will block until the lock is released.
It releases the lock after `f` is executed.
func (*Locker) RLock ¶
RLock locks the `key` with reading lock. If there's a writing lock on `key`, it will blocks until the writing lock is released.
func (*Locker) RLockFunc ¶
RLockFunc locks the `key` with reading lock and callback function `f`. If there's a writing lock the `key`, it will block until the lock is released.
It releases the lock after `f` is executed.
func (*Locker) TryLock ¶
TryLock tries locking the `key` with writing lock, it returns true if success, or it returns false if there's a writing/reading lock the `key`.
func (*Locker) TryLockFunc ¶
TryLockFunc locks the `key` with writing lock and callback function `f`. It returns true if success, or else if there's a write/reading lock the `key`, it return false.
It releases the lock after `f` is executed.
func (*Locker) TryRLock ¶
TryRLock tries locking the `key` with reading lock. It returns true if success, or if there's a writing lock on `key`, it returns false.
func (*Locker) TryRLockFunc ¶
TryRLockFunc locks the `key` with reading lock and callback function `f`. It returns true if success, or else if there's a writing lock the `key`, it returns false.
It releases the lock after `f` is executed.