From 1b196988d49401d41c20d3445d141ce0e2857979 Mon Sep 17 00:00:00 2001 From: Abirdcfly Date: Wed, 7 Sep 2022 04:25:08 +0000 Subject: [PATCH] cmd/go/internal/modload: use atomic.Pointer for Requirements.graph Change-Id: Ie543e1b1df667cfaf3aafa4be727881461ee8b7d GitHub-Last-Rev: ed993dbe2445c4797303138b62f6c7e26050dcd4 GitHub-Pull-Request: golang/go#54888 Reviewed-on: https://go-review.googlesource.com/c/go/+/428716 Auto-Submit: Bryan Mills Run-TryBot: Bryan Mills Reviewed-by: Bryan Mills TryBot-Result: Gopher Robot Reviewed-by: Michael Knyszek --- src/cmd/go/internal/modload/buildlist.go | 10 +++++----- src/cmd/go/internal/modload/load.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cmd/go/internal/modload/buildlist.go b/src/cmd/go/internal/modload/buildlist.go index cde4953afa..aa59611e81 100644 --- a/src/cmd/go/internal/modload/buildlist.go +++ b/src/cmd/go/internal/modload/buildlist.go @@ -73,8 +73,8 @@ type Requirements struct { // nested module back into a parent module). direct map[string]bool - graphOnce sync.Once // guards writes to (but not reads from) graph - graph atomic.Value // cachedGraph + graphOnce sync.Once // guards writes to (but not reads from) graph + graph atomic.Pointer[cachedGraph] } // A cachedGraph is a non-nil *ModuleGraph, together with any error discovered @@ -199,7 +199,7 @@ func (rs *Requirements) initVendor(vendorList []module.Version) { mg.g.Require(vendorMod, vendorList) } - rs.graph.Store(cachedGraph{mg, nil}) + rs.graph.Store(&cachedGraph{mg, nil}) }) } @@ -240,9 +240,9 @@ func (rs *Requirements) hasRedundantRoot() bool { func (rs *Requirements) Graph(ctx context.Context) (*ModuleGraph, error) { rs.graphOnce.Do(func() { mg, mgErr := readModGraph(ctx, rs.pruning, rs.rootModules) - rs.graph.Store(cachedGraph{mg, mgErr}) + rs.graph.Store(&cachedGraph{mg, mgErr}) }) - cached := rs.graph.Load().(cachedGraph) + cached := rs.graph.Load() return cached.mg, cached.err } diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go index 69b0c30978..060d0cb21a 100644 --- a/src/cmd/go/internal/modload/load.go +++ b/src/cmd/go/internal/modload/load.go @@ -1837,7 +1837,7 @@ func (ld *loader) computePatternAll() (all []string) { func (ld *loader) checkMultiplePaths() { mods := ld.requirements.rootModules if cached := ld.requirements.graph.Load(); cached != nil { - if mg := cached.(cachedGraph).mg; mg != nil { + if mg := cached.mg; mg != nil { mods = mg.BuildList() } } -- 2.50.0