mirror of https://github.com/golang/go.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 <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:
parent
dea67a9b34
commit
5e20f2e4df
|
|
@ -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()
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue