From 48ecc152e47db19255a3501d272b7ea3ed28915a Mon Sep 17 00:00:00 2001 From: hopehook Date: Thu, 25 Aug 2022 11:17:46 +0800 Subject: [PATCH] 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 Run-TryBot: Bryan Mills Auto-Submit: Bryan Mills Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot --- src/cmd/go/internal/trace/trace.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/go/internal/trace/trace.go b/src/cmd/go/internal/trace/trace.go index f108a2b6cae..d69dc4feac2 100644 --- a/src/cmd/go/internal/trace/trace.go +++ b/src/cmd/go/internal/trace/trace.go @@ -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") }