1
0
mirror of https://github.com/golang/go synced 2024-11-26 15:06:52 -07:00

cmd/go/internal/trace: convert traceStarted to atomic type

Change-Id: Ia4214a29775f1178273b9b7dc84c0420bfa968de
Reviewed-on: https://go-review.googlesource.com/c/go/+/425457
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
hopehook 2022-08-25 11:17:46 +08:00 committed by Gopher Robot
parent 297e3de7a1
commit 48ecc152e4

View File

@ -27,10 +27,10 @@ const (
bindEnclosingSlice = "e"
)
var traceStarted int32
var traceStarted atomic.Bool
func getTraceContext(ctx context.Context) (traceContext, bool) {
if atomic.LoadInt32(&traceStarted) == 0 {
if !traceStarted.Load() {
return traceContext{}, false
}
v := ctx.Value(traceKey{})
@ -179,7 +179,7 @@ type traceContext struct {
// Start starts a trace which writes to the given file.
func Start(ctx context.Context, file string) (context.Context, func() error, error) {
atomic.StoreInt32(&traceStarted, 1)
traceStarted.Store(true)
if file == "" {
return nil, nil, errors.New("no trace file supplied")
}