1
0
mirror of https://github.com/golang/go synced 2024-11-18 14:24:44 -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" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"sync"
) )
// traverseLink is a sentinel error for fastWalk, similar to filepath.SkipDir. // 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 { if n := runtime.NumCPU(); n > numWorkers {
numWorkers = n 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{ w := &walker{
fn: walkFn, fn: walkFn,
enqueuec: make(chan walkItem, numWorkers), // buffered for performance 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) defer close(w.donec)
// TODO(bradfitz): start the workers as needed? maybe not worth it. // TODO(bradfitz): start the workers as needed? maybe not worth it.
for i := 0; i < numWorkers; i++ { for i := 0; i < numWorkers; i++ {
wg.Add(1) go w.doWork()
go w.doWork(&wg)
} }
todo := []walkItem{{dir: root}} todo := []walkItem{{dir: root}}
out := 0 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 // doWork reads directories as instructed (via workc) and runs the
// user's callback function. // user's callback function.
func (w *walker) doWork(wg *sync.WaitGroup) { func (w *walker) doWork() {
defer wg.Done()
for { for {
select { select {
case <-w.donec: case <-w.donec: