Sfoglia il codice sorgente

Merge pull request #43245 from thaJeztah/info_counters_rwmutex

daemon: use RWMutex for stateCounter
Akihiro Suda 3 anni fa
parent
commit
bdaf94c28a
1 ha cambiato i file con 3 aggiunte e 3 eliminazioni
  1. 3 3
      daemon/metrics.go

+ 3 - 3
daemon/metrics.go

@@ -65,7 +65,7 @@ func init() {
 }
 
 type stateCounter struct {
-	mu     sync.Mutex
+	mu     sync.RWMutex
 	states map[string]string
 	desc   *prometheus.Desc
 }
@@ -78,8 +78,8 @@ func newStateCounter(desc *prometheus.Desc) *stateCounter {
 }
 
 func (ctr *stateCounter) get() (running int, paused int, stopped int) {
-	ctr.mu.Lock()
-	defer ctr.mu.Unlock()
+	ctr.mu.RLock()
+	defer ctr.mu.RUnlock()
 
 	states := map[string]int{
 		"running": 0,