mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-09 01:16:55 +00:00
28 lines
443 B
Go
28 lines
443 B
Go
|
package policystatus
|
||
|
|
||
|
import "sync"
|
||
|
|
||
|
type keyToMutex struct {
|
||
|
mu sync.RWMutex
|
||
|
keyMu map[string]*sync.RWMutex
|
||
|
}
|
||
|
|
||
|
func newKeyToMutex() *keyToMutex {
|
||
|
return &keyToMutex{
|
||
|
mu: sync.RWMutex{},
|
||
|
keyMu: make(map[string]*sync.RWMutex),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (k *keyToMutex) Get(key string) *sync.RWMutex {
|
||
|
k.mu.Lock()
|
||
|
defer k.mu.Unlock()
|
||
|
mutex := k.keyMu[key]
|
||
|
if mutex == nil {
|
||
|
mutex = &sync.RWMutex{}
|
||
|
k.keyMu[key] = mutex
|
||
|
}
|
||
|
|
||
|
return mutex
|
||
|
}
|