Merge pull request #115711 from sourcelliu/improve

Improve lock performance
This commit is contained in:
Kubernetes Prow Robot 2023-10-27 23:41:32 +02:00 committed by GitHub
commit 848de697d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -194,8 +194,8 @@ func (m *BiMultimap) delete(key Key) {
// Exists returns true if the labeled object is present in the map. // Exists returns true if the labeled object is present in the map.
func (m *BiMultimap) Exists(key Key) bool { func (m *BiMultimap) Exists(key Key) bool {
m.mux.Lock() m.mux.RLock()
defer m.mux.Unlock() defer m.mux.RUnlock()
_, exists := m.labeledObjects[key] _, exists := m.labeledObjects[key]
return exists return exists
@ -289,8 +289,8 @@ func (m *BiMultimap) deleteSelector(key Key) {
// SelectorExists returns true if the selecting object is present in the map. // SelectorExists returns true if the selecting object is present in the map.
func (m *BiMultimap) SelectorExists(key Key) bool { func (m *BiMultimap) SelectorExists(key Key) bool {
m.mux.Lock() m.mux.RLock()
defer m.mux.Unlock() defer m.mux.RUnlock()
_, exists := m.selectingObjects[key] _, exists := m.selectingObjects[key]
return exists return exists