go/ssa: use sync.Once instead of sync.atomic

This adds a missing memory barrier at the end of Package.Build.

Change-Id: Ife35d5ad5a48ba121f35656fef682863d4f2aef6
Reviewed-on: https://go-review.googlesource.com/14761
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Alan Donovan 2015-09-18 11:01:08 -04:00
parent 1d593709ec
commit 8049553ca8
2 changed files with 7 additions and 9 deletions

View File

@ -35,7 +35,6 @@ import (
"go/token" "go/token"
"os" "os"
"sync" "sync"
"sync/atomic"
"golang.org/x/tools/go/exact" "golang.org/x/tools/go/exact"
"golang.org/x/tools/go/types" "golang.org/x/tools/go/types"
@ -2241,10 +2240,9 @@ func (prog *Program) Build() {
// //
// Build is idempotent and thread-safe. // Build is idempotent and thread-safe.
// //
func (p *Package) Build() { func (p *Package) Build() { p.buildOnce.Do(p.build) }
if !atomic.CompareAndSwapInt32(&p.started, 0, 1) {
return // already started func (p *Package) build() {
}
if p.info == nil { if p.info == nil {
return // synthetic package, e.g. "testmain" return // synthetic package, e.g. "testmain"
} }

View File

@ -53,7 +53,7 @@ type Package struct {
// The following fields are set transiently, then cleared // The following fields are set transiently, then cleared
// after building. // after building.
started int32 // atomically tested and set at start of build phase buildOnce sync.Once // ensures package building occurs once
ninit int32 // number of init functions ninit int32 // number of init functions
info *types.Info // package type information info *types.Info // package type information
files []*ast.File // package ASTs files []*ast.File // package ASTs