b.mu.RLock()
finished := b.finished
b.mu.RUnlock()
- if atomic.LoadInt32(&b.hasSub) != 0 || finished {
+ if b.hasSub.Load() || finished {
tag := "BENCH"
if b.skipped {
tag = "SKIP"
func (b *B) Run(name string, f func(b *B)) bool {
// Since b has subbenchmarks, we will no longer run it as a benchmark itself.
// Release the lock and acquire it on exit to ensure locks stay paired.
- atomic.StoreInt32(&b.hasSub, 1)
+ b.hasSub.Store(true)
benchmarkLock.Unlock()
defer benchmarkLock.Lock()
if partial {
// Partial name match, like -bench=X/Y matching BenchmarkX.
// Only process sub-benchmarks, if any.
- atomic.StoreInt32(&sub.hasSub, 1)
+ sub.hasSub.Store(true)
}
if b.chatty != nil {
chatty *chattyPrinter // A copy of chattyPrinter, if the chatty flag is set.
bench bool // Whether the current test is a benchmark.
- hasSub int32 // Written atomically.
+ hasSub atomic.Bool // whether there are sub-benchmarks.
raceErrors int // Number of races detected during test.
runner string // Function name of tRunner running the test.
// Do not lock t.done to allow race detector to detect race in case
// the user does not appropriately synchronize a goroutine.
t.done = true
- if t.parent != nil && atomic.LoadInt32(&t.hasSub) == 0 {
+ if t.parent != nil && !t.hasSub.Load() {
t.setRan()
}
}()
// Run may be called simultaneously from multiple goroutines, but all such calls
// must return before the outer test function for t returns.
func (t *T) Run(name string, f func(t *T)) bool {
- atomic.StoreInt32(&t.hasSub, 1)
+ t.hasSub.Store(true)
testName, ok, _ := t.context.match.fullName(&t.common, name)
if !ok || shouldFailFast() {
return true