Created
June 8, 2016 16:03
-
-
Save petermattis/551ffa845196f142e1db2377e6012b7d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go | |
index 5327fb9..ac92970 100644 | |
--- a/src/cmd/go/build.go | |
+++ b/src/cmd/go/build.go | |
@@ -700,6 +700,8 @@ type builder struct { | |
exec sync.Mutex | |
readySema chan bool | |
ready actionQueue | |
+ | |
+ tasks chan func() | |
} | |
// An action represents a single action in the action graph. | |
@@ -1243,6 +1245,7 @@ func (b *builder) do(root *action) { | |
} | |
b.readySema = make(chan bool, len(all)) | |
+ b.tasks = make(chan func(), buildP) | |
// Initialize per-action execution state. | |
for _, a := range all { | |
@@ -1319,6 +1322,8 @@ func (b *builder) do(root *action) { | |
a := b.ready.pop() | |
b.exec.Unlock() | |
handle(a) | |
+ case task := <-b.tasks: | |
+ task() | |
case <-interrupted: | |
setExitStatus(1) | |
return | |
@@ -3282,12 +3287,16 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, pcCFLAGS, pcLDFLAGS, cgofi | |
staticLibs = []string{"-Wl,--start-group", "-lmingwex", "-lmingw32", "-Wl,--end-group"} | |
} | |
+ var tasks []func() | |
+ var results chan error | |
+ | |
cflags := stringList(cgoCPPFLAGS, cgoCFLAGS) | |
for _, cfile := range cfiles { | |
+ cfile := cfile | |
ofile := obj + cfile[:len(cfile)-1] + "o" | |
- if err := b.gcc(p, ofile, cflags, obj+cfile); err != nil { | |
- return nil, nil, err | |
- } | |
+ tasks = append(tasks, func() { | |
+ results <- b.gcc(p, ofile, cflags, obj+cfile) | |
+ }) | |
linkobj = append(linkobj, ofile) | |
if !strings.HasSuffix(ofile, "_cgo_main.o") { | |
outObj = append(outObj, ofile) | |
@@ -3295,31 +3304,34 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, pcCFLAGS, pcLDFLAGS, cgofi | |
} | |
for _, file := range gccfiles { | |
+ file := file | |
ofile := obj + cgoRe.ReplaceAllString(file[:len(file)-1], "_") + "o" | |
- if err := b.gcc(p, ofile, cflags, file); err != nil { | |
- return nil, nil, err | |
- } | |
+ tasks = append(tasks, func() { | |
+ results <- b.gcc(p, ofile, cflags, file) | |
+ }) | |
linkobj = append(linkobj, ofile) | |
outObj = append(outObj, ofile) | |
} | |
cxxflags := stringList(cgoCPPFLAGS, cgoCXXFLAGS) | |
for _, file := range gxxfiles { | |
+ file := file | |
// Append .o to the file, just in case the pkg has file.c and file.cpp | |
ofile := obj + cgoRe.ReplaceAllString(file, "_") + ".o" | |
- if err := b.gxx(p, ofile, cxxflags, file); err != nil { | |
- return nil, nil, err | |
- } | |
+ tasks = append(tasks, func() { | |
+ results <- b.gxx(p, ofile, cxxflags, file) | |
+ }) | |
linkobj = append(linkobj, ofile) | |
outObj = append(outObj, ofile) | |
} | |
for _, file := range mfiles { | |
+ file := file | |
// Append .o to the file, just in case the pkg has file.c and file.m | |
ofile := obj + cgoRe.ReplaceAllString(file, "_") + ".o" | |
- if err := b.gcc(p, ofile, cflags, file); err != nil { | |
- return nil, nil, err | |
- } | |
+ tasks = append(tasks, func() { | |
+ results <- b.gcc(p, ofile, cflags, file) | |
+ }) | |
linkobj = append(linkobj, ofile) | |
outObj = append(outObj, ofile) | |
} | |
@@ -3335,6 +3347,33 @@ func (b *builder) cgo(p *Package, cgoExe, obj string, pcCFLAGS, pcLDFLAGS, cgofi | |
outObj = append(outObj, ofile) | |
} | |
+ // Give the results channel enough capacity so that sending the | |
+ // result is guaranteed not to block. | |
+ results = make(chan error, len(tasks)) | |
+ | |
+ // Feed the tasks into the b.tasks channel on a separate goroutine | |
+ // because the b.tasks channel's limited capacity might cause | |
+ // sending the task to block. | |
+ go func() { | |
+ for _, task := range tasks { | |
+ b.tasks <- task | |
+ } | |
+ }() | |
+ | |
+ // Loop until we've received results from all of our tasks or an | |
+ // error occurs. | |
+ for count := 0; count < len(tasks); { | |
+ select { | |
+ case err := <-results: | |
+ if err != nil { | |
+ return nil, nil, err | |
+ } | |
+ count++ | |
+ case task := <-b.tasks: | |
+ task() | |
+ } | |
+ } | |
+ | |
linkobj = append(linkobj, p.SysoFiles...) | |
dynobj := obj + "_cgo_.o" | |
pie := (goarch == "arm" && goos == "linux") || goos == "android" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment