runtime/trace: convert tracing.enabled to atomic type

Updates #53821

Change-Id: I8a063ae94568cd2ea65c2e891618069a96139891
Reviewed-on: https://go-review.googlesource.com/c/go/+/423884
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
Cuong Manh Le 2022-08-17 17:25:33 +07:00
parent dea67a9b34
commit 5e20f2e4df
2 changed files with 5 additions and 6 deletions

View File

@ -178,8 +178,7 @@ func (r *Region) End() {
// The information is advisory only. The tracing status
// may have changed by the time this function returns.
func IsEnabled() bool {
enabled := atomic.LoadInt32(&tracing.enabled)
return enabled == 1
return tracing.enabled.Load()
}
//

View File

@ -134,7 +134,7 @@ func Start(w io.Writer) error {
w.Write(data)
}
}()
atomic.StoreInt32(&tracing.enabled, 1)
tracing.enabled.Store(true)
return nil
}
@ -143,12 +143,12 @@ func Start(w io.Writer) error {
func Stop() {
tracing.Lock()
defer tracing.Unlock()
atomic.StoreInt32(&tracing.enabled, 0)
tracing.enabled.Store(false)
runtime.StopTrace()
}
var tracing struct {
sync.Mutex // gate mutators (Start, Stop)
enabled int32 // accessed via atomic
sync.Mutex // gate mutators (Start, Stop)
enabled atomic.Bool
}