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