Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ func (NilMeter) Stop() {}

// StandardMeter is the standard implementation of a Meter.
type StandardMeter struct {
// Only used on stop.
lock sync.Mutex
snapshot *MeterSnapshot
a1, a5, a15 EWMA
startTime time.Time
Expand All @@ -146,11 +144,7 @@ func newStandardMeter() *StandardMeter {

// Stop stops the meter, Mark() will be a no-op if you use it after being stopped.
func (m *StandardMeter) Stop() {
m.lock.Lock()
stopped := m.stopped
m.stopped = 1
m.lock.Unlock()
if stopped != 1 {
if atomic.CompareAndSwapUint32(&m.stopped, 0, 1) {
arbiter.Lock()
delete(arbiter.meters, m)
arbiter.Unlock()
Expand Down
5 changes: 5 additions & 0 deletions meter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func TestMeterConcurrency(t *testing.T) {
m.Mark(1)
wg.Done()
}(m, wg)
wg.Add(1)
go func(m Meter, wg *sync.WaitGroup) {
m.Stop()
wg.Done()
}(m, wg)
}
wg.Wait()
}
Expand Down