]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/trace: convert traceStarted to atomic type
authorhopehook <hopehook@qq.com>
Thu, 25 Aug 2022 03:17:46 +0000 (11:17 +0800)
committerGopher Robot <gobot@golang.org>
Fri, 26 Aug 2022 17:44:58 +0000 (17:44 +0000)
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>

src/cmd/go/internal/trace/trace.go

index f108a2b6cae19b8e22aa64e69b35855bf743e1c6..d69dc4feac2b40893bb0eb4063deaab28e578f99 100644 (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")
        }