1
0
mirror of https://github.com/golang/go synced 2024-11-18 10:14:45 -07:00

Revert "imports: wait for fastWalk workers to finish before returning"

This reverts commit 4436e54754.

Reason for revert: Breaks goimports. See:
https://github.com/golang/go/issues/16399#issuecomment-293248363

Change-Id: I3bda8f0fd32380d19d7daecf3489a24e51abfbe7
Reviewed-on: https://go-review.googlesource.com/40296
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Brad Fitzpatrick 2017-04-11 14:41:39 +00:00
parent ef3dcd5937
commit 7ee420f17d

View File

@ -19,7 +19,6 @@ import (
"os"
"path/filepath"
"runtime"
"sync"
)
// traverseLink is a sentinel error for fastWalk, similar to filepath.SkipDir.
@ -49,12 +48,6 @@ func fastWalk(root string, walkFn func(path string, typ os.FileMode) error) erro
if n := runtime.NumCPU(); n > numWorkers {
numWorkers = n
}
// Make sure to wait for all workers to finish, otherwise walkFn could
// still be called after returning.
var wg sync.WaitGroup
defer wg.Wait()
w := &walker{
fn: walkFn,
enqueuec: make(chan walkItem, numWorkers), // buffered for performance
@ -67,8 +60,7 @@ func fastWalk(root string, walkFn func(path string, typ os.FileMode) error) erro
defer close(w.donec)
// TODO(bradfitz): start the workers as needed? maybe not worth it.
for i := 0; i < numWorkers; i++ {
wg.Add(1)
go w.doWork(&wg)
go w.doWork()
}
todo := []walkItem{{dir: root}}
out := 0
@ -111,8 +103,7 @@ func fastWalk(root string, walkFn func(path string, typ os.FileMode) error) erro
// doWork reads directories as instructed (via workc) and runs the
// user's callback function.
func (w *walker) doWork(wg *sync.WaitGroup) {
defer wg.Done()
func (w *walker) doWork() {
for {
select {
case <-w.donec: