From f2aeb3b0d91cc9819b1733a4fdc9df693b0d5f29 Mon Sep 17 00:00:00 2001 From: mantuliu <240951888@qq.com> Date: Mon, 13 Feb 2023 00:43:30 +0800 Subject: [PATCH] Improve lock performance Signed-off-by: mantuliu <240951888@qq.com> --- pkg/controller/util/selectors/bimultimap.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/controller/util/selectors/bimultimap.go b/pkg/controller/util/selectors/bimultimap.go index f81b9adc7a8..ea8c5456ecd 100644 --- a/pkg/controller/util/selectors/bimultimap.go +++ b/pkg/controller/util/selectors/bimultimap.go @@ -194,8 +194,8 @@ func (m *BiMultimap) delete(key Key) { // Exists returns true if the labeled object is present in the map. func (m *BiMultimap) Exists(key Key) bool { - m.mux.Lock() - defer m.mux.Unlock() + m.mux.RLock() + defer m.mux.RUnlock() _, exists := m.labeledObjects[key] return exists @@ -289,8 +289,8 @@ func (m *BiMultimap) deleteSelector(key Key) { // SelectorExists returns true if the selecting object is present in the map. func (m *BiMultimap) SelectorExists(key Key) bool { - m.mux.Lock() - defer m.mux.Unlock() + m.mux.RLock() + defer m.mux.RUnlock() _, exists := m.selectingObjects[key] return exists