1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-10 09:56:55 +00:00
kyverno/pkg/policyreport/mapper.go
Charles-Edouard Brétéché e516fb868e
fix: lock in policy report mapper (#4601)
Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>

Signed-off-by: Charles-Edouard Brétéché <charled.breteche@gmail.com>
2022-09-13 16:30:14 +08:00

28 lines
539 B
Go

package policyreport
import cmap "github.com/orcaman/concurrent-map"
type concurrentMap struct{ cmap.ConcurrentMap }
func (m concurrentMap) increase(ns string) {
count, ok := m.Get(ns)
if ok && count != -1 {
m.Set(ns, count.(int)+1)
} else {
m.Set(ns, 1)
}
}
func (m concurrentMap) decrease(keyHash string) {
_, ns := parseKeyHash(keyHash)
count, ok := m.Get(ns)
if ok && count.(int) > 0 {
m.Set(ns, count.(int)-1)
} else {
m.Set(ns, 0)
}
}
func newConcurrentMap() concurrentMap {
return concurrentMap{cmap.New()}
}