add Remove/Clear functions for gmlock

This commit is contained in:
John
2019-06-22 11:45:58 +08:00
parent c88f516759
commit 9a507b54d7
2 changed files with 17 additions and 1 deletions

View File

@ -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)
}

View File

@ -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 {