In ListenerCounter a sync.Mutex was replaced by a sync.RWMutex.
This commit is contained in:
parent
da4e97f1aa
commit
d84d985962
@ -10,7 +10,7 @@ import (
|
||||
|
||||
// ListenerCounter stores the current and peak numbers of listeners.
|
||||
type ListenerCounter struct {
|
||||
sync.Mutex
|
||||
sync.RWMutex
|
||||
current, peak int
|
||||
}
|
||||
|
||||
@ -21,15 +21,15 @@ func NewListenerCounter() *ListenerCounter {
|
||||
|
||||
// Current returns a number of current listeners.
|
||||
func (l *ListenerCounter) Current() int {
|
||||
l.Lock()
|
||||
defer l.Unlock()
|
||||
l.RLock()
|
||||
defer l.RUnlock()
|
||||
return l.current
|
||||
}
|
||||
|
||||
// Current returns a number of peak listeners.
|
||||
func (l *ListenerCounter) Peak() int {
|
||||
l.Lock()
|
||||
defer l.Unlock()
|
||||
l.RLock()
|
||||
defer l.RUnlock()
|
||||
return l.peak
|
||||
}
|
||||
|
||||
@ -61,8 +61,8 @@ func (l *ListenerCounter) Dec() (int, error) {
|
||||
}
|
||||
|
||||
func (l *ListenerCounter) MarshalJSON() ([]byte, error) {
|
||||
l.Lock()
|
||||
defer l.Unlock()
|
||||
l.RLock()
|
||||
defer l.RUnlock()
|
||||
return json.Marshal(&struct {
|
||||
Current int `json:"current"`
|
||||
Peak int `json:"peak"`
|
||||
|
Loading…
Reference in New Issue
Block a user