Attempting to fix deadlock

This commit is contained in:
Alex Yatskov 2015-11-10 13:00:24 +09:00
parent c727a21239
commit b9ffe6bc66

View File

@ -26,6 +26,7 @@ import (
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"sync"
) )
const ( const (
@ -144,20 +145,43 @@ func (gs *goldsmith) makeStage() stage {
} }
func (gs *goldsmith) chain(s stage, c Chainer) { func (gs *goldsmith) chain(s stage, c Chainer) {
f, _ := c.(Filterer) var (
wg sync.WaitGroup
output = make(chan *File)
input = make(chan *File)
)
allowed := make(chan *File) defer func() {
defer close(allowed) wg.Wait()
close(s.output)
}()
go c.Chain(gs, allowed, s.output) wg.Add(1)
go func() {
for file := range s.input { defer wg.Done()
if file.flags&FileFlagStatic != 0 || (f != nil && f.Filter(file.Path)) { for file := range output {
s.output <- file s.output <- file
} else {
allowed <- file
} }
} }()
wg.Add(1)
go func() {
defer func() {
close(input)
wg.Done()
}()
f, _ := c.(Filterer)
for file := range s.input {
if file.flags&FileFlagStatic != 0 || (f != nil && f.Filter(file.Path)) {
s.output <- file
} else {
input <- file
}
}
}()
go c.Chain(gs, input, output)
} }
func (gs *goldsmith) NewFile(path string) *File { func (gs *goldsmith) NewFile(path string) *File {