daemon: use RWMutex for stateCounter

Use an RWMutex to allow concurrent reads of these counters

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit 699174347c)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-02-15 18:04:18 +01:00
parent 1881be2de5
commit 32fe0bbb91
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 3 additions and 3 deletions

View File

@ -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,