1
0
mirror of https://github.com/golang/go synced 2024-11-18 09:04:49 -07:00

cmd/go/internal/modload: use atomic.Pointer for Requirements.graph

Change-Id: Ie543e1b1df667cfaf3aafa4be727881461ee8b7d
GitHub-Last-Rev: ed993dbe24
GitHub-Pull-Request: golang/go#54888
Reviewed-on: https://go-review.googlesource.com/c/go/+/428716
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
Abirdcfly 2022-09-07 04:25:08 +00:00 committed by Gopher Robot
parent 9a5574afe6
commit 1b196988d4
2 changed files with 6 additions and 6 deletions

View File

@ -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
}

View File

@ -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()
}
}