Further repair parallelism

main
Mari 3 years ago
parent c4c2746ff7
commit ec47b8d63a
  1. 134
      drive-demuxer.go

@ -13,14 +13,15 @@ import (
) )
type TopLevel struct { type TopLevel struct {
LeftInput string LeftInput string
RightInput string RightInput string
LeftOutput string LeftOutput string
CombinedOutput string CombinedOutput string
RightOutput string RightOutput string
OpenHandles chan int OpenHandles chan int
DryRun bool OpenDirectories chan int
Bar *pb.ProgressBar DryRun bool
Bar *pb.ProgressBar
} }
type Step struct { type Step struct {
@ -297,111 +298,77 @@ func (s *Step) Walk() {
rightPath := s.InputPath(child, RIGHT) rightPath := s.InputPath(child, RIGHT)
rightState, err := s.CheckState(rightPath) rightState, err := s.CheckState(rightPath)
if err != nil { if err != nil {
wg.Add(1) log.Printf("Error statting path %s: %s\n", rightPath, err)
go func(rightPath string) { s.Bar.Increment()
defer func() {
wg.Done()
}()
log.Printf("Error statting path %s: %s\n", rightPath, err)
s.Bar.Increment()
}(rightPath)
continue continue
} else if rightState == UNKNOWN { } else if rightState == UNKNOWN {
wg.Add(1) log.Printf("Unknown stat value for path %s\n", rightPath)
go func(rightPath string) { s.Bar.Increment()
defer func() {
wg.Done()
}()
log.Printf("Unknown stat value for path %s\n", rightPath)
s.Bar.Increment()
}(rightPath)
continue continue
} else if rightState == MISSING { } else if rightState == MISSING {
wg.Add(1) s.SeparateLeft(child)
go func(child string) { s.Bar.Increment()
defer func() {
wg.Done()
}()
s.SeparateLeft(child)
s.Bar.Increment()
}(child)
continue continue
} }
leftPath := s.InputPath(child, LEFT) leftPath := s.InputPath(child, LEFT)
leftState, err := s.CheckState(leftPath) leftState, err := s.CheckState(leftPath)
if err != nil { if err != nil {
wg.Add(1) log.Printf("Error statting path %s: %s\n", leftPath, err)
go func(leftPath string) { s.Bar.Increment()
defer func() {
wg.Done()
}()
log.Printf("Error statting path %s: %s\n", leftPath, err)
s.Bar.Increment()
}(leftPath)
continue continue
} else if leftState == UNKNOWN { } else if leftState == UNKNOWN {
wg.Add(1) log.Printf("Unknown stat value for path %s\n", leftPath)
go func(leftPath string) { s.Bar.Increment()
defer func() {
wg.Done()
}()
log.Printf("Unknown stat value for path %s\n", leftPath)
s.Bar.Increment()
}(leftPath)
continue continue
} else if leftState == MISSING { } else if leftState == MISSING {
wg.Add(1) s.SeparateRight(child)
go func(child string) { s.Bar.Increment()
defer func() {
wg.Done()
}()
s.SeparateRight(child)
s.Bar.Increment()
}(child)
continue continue
} }
switch rightState { switch rightState {
case FILE: case FILE:
wg.Add(1) wg.Add(1)
go func(child string) { if leftState == FILE {
defer func() { go func(child string) {
wg.Done() defer func() {
}() wg.Done()
if leftState == FILE && s.AreFilesIdentical(child) { }()
s.Combine(child) if s.AreFilesIdentical(child) {
s.Bar.Increment() s.Combine(child)
} else { s.Bar.Increment()
s.Separate(child) } else {
s.Bar.Increment() s.Separate(child)
} s.Bar.Increment()
}(child) }
}(child)
} else {
s.Separate(child)
s.Bar.Increment()
}
case DIRECTORY: case DIRECTORY:
if leftState == DIRECTORY { if leftState == DIRECTORY {
substep := Step{ s.OpenDirectories <- 1
TopLevel: s.TopLevel,
Subpath: path.Join(s.Subpath, child),
}
wg.Add(1) wg.Add(1)
go func(child string, substep *Step) { go func(child string) {
defer func() { defer func() {
wg.Done() wg.Done()
<-s.OpenDirectories
}() }()
substep := Step{
TopLevel: s.TopLevel,
Subpath: path.Join(s.Subpath, child),
}
s.MakeCombinedDir(child) s.MakeCombinedDir(child)
substep.Walk() substep.Walk()
s.RemoveInputDirs(child) s.RemoveInputDirs(child)
s.Bar.Increment() s.Bar.Increment()
}(child, &substep) }(child)
} else { } else {
wg.Add(1) wg.Add(1)
go func(child string) { s.Separate(child)
defer func() { s.Bar.Increment()
wg.Done()
}()
s.Separate(child)
s.Bar.Increment()
}(child)
} }
default: default:
panic("Unexpected state") panic("Unexpected state")
@ -413,8 +380,9 @@ func (s *Step) Walk() {
func main() { func main() {
settings := TopLevel{ settings := TopLevel{
OpenHandles: make(chan int, 450), OpenHandles: make(chan int, 450),
Bar: pb.StartNew(1), OpenDirectories: make(chan int, 1000),
Bar: pb.StartNew(1),
} }
flag.StringVar(&settings.LeftInput, flag.StringVar(&settings.LeftInput,
"left-input", "./input/left", "The name of the left side of the input.") "left-input", "./input/left", "The name of the left side of the input.")

Loading…
Cancel
Save