[#92] Embed policer's objectsInWork mutex

Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
This commit is contained in:
Alejandro Lopez 2023-06-30 10:08:36 +03:00
parent 95c32af491
commit 7fcc999c2b

View file

@ -11,28 +11,28 @@ import (
) )
type objectsInWork struct { type objectsInWork struct {
m sync.RWMutex sync.RWMutex
objs map[oid.Address]struct{} objs map[oid.Address]struct{}
} }
func (oiw *objectsInWork) inWork(addr oid.Address) bool { func (oiw *objectsInWork) inWork(addr oid.Address) bool {
oiw.m.RLock() oiw.RLock()
_, ok := oiw.objs[addr] _, ok := oiw.objs[addr]
oiw.m.RUnlock() oiw.RUnlock()
return ok return ok
} }
func (oiw *objectsInWork) remove(addr oid.Address) { func (oiw *objectsInWork) remove(addr oid.Address) {
oiw.m.Lock() oiw.Lock()
delete(oiw.objs, addr) delete(oiw.objs, addr)
oiw.m.Unlock() oiw.Unlock()
} }
func (oiw *objectsInWork) add(addr oid.Address) { func (oiw *objectsInWork) add(addr oid.Address) {
oiw.m.Lock() oiw.Lock()
oiw.objs[addr] = struct{}{} oiw.objs[addr] = struct{}{}
oiw.m.Unlock() oiw.Unlock()
} }
// Policer represents the utility that verifies // Policer represents the utility that verifies