From: hopehook Date: Thu, 25 Aug 2022 03:17:46 +0000 (+0800) Subject: cmd/go/internal/trace: convert traceStarted to atomic type X-Git-Tag: go1.20rc1~1391 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=48ecc152e47db19255a3501d272b7ea3ed28915a;p=gostls13.git 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 --- diff --git a/src/cmd/go/internal/trace/trace.go b/src/cmd/go/internal/trace/trace.go index f108a2b6ca..d69dc4feac 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") }