mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
add Remove/Clear functions for gmlock
This commit is contained in:
@ -82,3 +82,8 @@ func TryLockFunc(key string, f func()) bool {
|
||||
func TryRLockFunc(key string, f func()) bool {
|
||||
return locker.TryRLockFunc(key, f)
|
||||
}
|
||||
|
||||
// Remove removes mutex with given <key>.
|
||||
func Remove(key string) {
|
||||
locker.Remove(key)
|
||||
}
|
||||
|
||||
@ -12,7 +12,8 @@ import (
|
||||
)
|
||||
|
||||
// Memory locker.
|
||||
// Note that there's no cache expire mechanism for attribute map <m>.
|
||||
// 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 any more.
|
||||
type Locker struct {
|
||||
m *gmap.StrAnyMap
|
||||
}
|
||||
@ -113,6 +114,16 @@ func (l *Locker) TryRLockFunc(key string, f func()) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Remove removes mutex with given <key> from locker.
|
||||
func (l *Locker) Remove(key string) {
|
||||
l.m.Remove(key)
|
||||
}
|
||||
|
||||
// Clear removes all mutexes from locker.
|
||||
func (l *Locker) Clear() {
|
||||
l.m.Clear()
|
||||
}
|
||||
|
||||
// getOrNewMutex returns the mutex of given <key> if it exists,
|
||||
// or else creates and returns a new one.
|
||||
func (l *Locker) getOrNewMutex(key string) *gmutex.Mutex {
|
||||
|
||||
Reference in New Issue
Block a user