From: Cuong Manh Le Date: Wed, 17 Aug 2022 10:25:33 +0000 (+0700) Subject: runtime/trace: convert tracing.enabled to atomic type X-Git-Tag: go1.20rc1~1585 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5e20f2e4dfdfea7deb9ad9e2a9909a32588334a0;p=gostls13.git 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 TryBot-Result: Gopher Robot Reviewed-by: Michael Pratt Reviewed-by: Keith Randall Auto-Submit: Cuong Manh Le --- diff --git a/src/runtime/trace/annotation.go b/src/runtime/trace/annotation.go index 9171633b07..d47cb8573c 100644 --- a/src/runtime/trace/annotation.go +++ b/src/runtime/trace/annotation.go @@ -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() } // diff --git a/src/runtime/trace/trace.go b/src/runtime/trace/trace.go index cf2b6440b2..86c97e2a11 100644 --- a/src/runtime/trace/trace.go +++ b/src/runtime/trace/trace.go @@ -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 }