Refactor to use atomic types (#15625)

* refactor to use atomic types

* added changlog fragment file

* update change log
This commit is contained in:
Sahil Sojitra
2025-08-27 01:27:14 +05:30
committed by GitHub
parent 4a1ab70929
commit e0aecb9c32
6 changed files with 17 additions and 13 deletions

View File

@@ -10,18 +10,18 @@ import (
// Arbitrary start time.
var start = time.Date(1990, 1, 2, 0, 0, 0, 0, time.UTC).Round(0)
var elapsed int64
var elapsed atomic.Int64
// We provide atomic access to elapsed to avoid data races between multiple
// concurrent goroutines during the tests.
func getElapsed() time.Duration {
return time.Duration(atomic.LoadInt64(&elapsed))
return time.Duration(elapsed.Load())
}
func setElapsed(v time.Duration) {
atomic.StoreInt64(&elapsed, int64(v))
elapsed.Store(int64(v))
}
func addToElapsed(v time.Duration) {
atomic.AddInt64(&elapsed, int64(v))
elapsed.Add(int64(v))
}
func reset(t *testing.T, c *Collector) {