optimize mutex lock fn
This commit is contained in:
parent
568ab15a34
commit
12b75b9d82
5
cache/locks.go
vendored
5
cache/locks.go
vendored
|
@ -43,13 +43,16 @@ func (l *Locks[K]) GetLock(ctx context.Context, gMut *sync.Mutex, keys ...K) *sy
|
|||
if ok {
|
||||
return lo
|
||||
}
|
||||
num := l.numFn()
|
||||
if num == 1 {
|
||||
return gMut
|
||||
}
|
||||
gMut.Lock()
|
||||
defer gMut.Unlock()
|
||||
lo, ok = l.m.Load(k)
|
||||
if ok {
|
||||
return lo
|
||||
}
|
||||
num := l.numFn()
|
||||
if num <= 0 {
|
||||
lo = &sync.Mutex{}
|
||||
l.m.Store(k, lo)
|
||||
|
|
Loading…
Reference in New Issue
Block a user