Skip to content

Commit 8f87f58

Browse files
committed
scheduler: tweak scheduler factory mutex
1 parent 9600555 commit 8f87f58

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

pkg/scheduler/factory/plugins.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type PriorityConfigFactory struct {
7777
}
7878

7979
var (
80-
schedulerFactoryMutex sync.Mutex
80+
schedulerFactoryMutex sync.RWMutex
8181

8282
// maps that hold registered algorithm types
8383
fitPredicateMap = make(map[string]FitPredicateFactory)
@@ -139,7 +139,6 @@ func RemovePredicateKeyFromAlgorithmProviderMap(key string) {
139139
for _, provider := range algorithmProviderMap {
140140
provider.FitPredicateKeys.Delete(key)
141141
}
142-
return
143142
}
144143

145144
// InsertPredicateKeyToAlgoProvider insert a fit predicate key to algorithmProvider.
@@ -376,8 +375,8 @@ func buildScoringFunctionShapeFromRequestedToCapacityRatioArguments(arguments *s
376375

377376
// IsPriorityFunctionRegistered is useful for testing providers.
378377
func IsPriorityFunctionRegistered(name string) bool {
379-
schedulerFactoryMutex.Lock()
380-
defer schedulerFactoryMutex.Unlock()
378+
schedulerFactoryMutex.RLock()
379+
defer schedulerFactoryMutex.RUnlock()
381380
_, ok := priorityFunctionMap[name]
382381
return ok
383382
}
@@ -397,8 +396,8 @@ func RegisterAlgorithmProvider(name string, predicateKeys, priorityKeys sets.Str
397396

398397
// GetAlgorithmProvider should not be used to modify providers. It is publicly visible for testing.
399398
func GetAlgorithmProvider(name string) (*AlgorithmProviderConfig, error) {
400-
schedulerFactoryMutex.Lock()
401-
defer schedulerFactoryMutex.Unlock()
399+
schedulerFactoryMutex.RLock()
400+
defer schedulerFactoryMutex.RUnlock()
402401

403402
provider, ok := algorithmProviderMap[name]
404403
if !ok {

0 commit comments

Comments
 (0)