Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 6617ed1

Browse files
author
James DeFelice
committed
meter: fixed another race reported by the race-detector
1 parent d605d8a commit 6617ed1

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

meter.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,7 @@ func newStandardMeter() *StandardMeter {
147147

148148
// Stop stops the meter, Mark() will be a no-op if you use it after being stopped.
149149
func (m *StandardMeter) Stop() {
150-
m.lock.Lock()
151-
stopped := m.stopped
152-
m.stopped = 1
153-
m.lock.Unlock()
150+
stopped := atomic.SwapUint32(&m.stopped, 1)
154151
if stopped != 1 {
155152
arbiter.Lock()
156153
defer arbiter.Unlock()
@@ -247,7 +244,7 @@ type meterArbiter struct {
247244
started bool
248245
meters map[*StandardMeter]struct{}
249246
ticker *time.Ticker
250-
cancel chan struct{}
247+
cancel chan struct{}
251248
}
252249

253250
var arbiter = meterArbiter{ticker: time.NewTicker(5e9), meters: make(map[*StandardMeter]struct{})}

0 commit comments

Comments
 (0)