summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2018-10-11 13:47:08 -0700
committerGitHub <noreply@github.com>2018-10-11 13:47:08 -0700
commitdddea7bca90cffa5061ba38325574d669400a436 (patch)
treee8b99dc88071a5a3581baa28720f3825c4c33290 /cmd
parent5f6e4cc830e82a9453e4617d6b8dccab30700f3d (diff)
parente0c980925b6bcb7c26036c6ef435d9e1204aecb4 (diff)
downloadpodman-dddea7bca90cffa5061ba38325574d669400a436.tar.gz
podman-dddea7bca90cffa5061ba38325574d669400a436.tar.bz2
podman-dddea7bca90cffa5061ba38325574d669400a436.zip
Merge pull request #1632 from mheon/fix_map_sync
Swap from map to channels for podman stop workers
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/utils.go19
1 files changed, 16 insertions, 3 deletions
diff --git a/cmd/podman/utils.go b/cmd/podman/utils.go
index 1b767532e..b193cf889 100644
--- a/cmd/podman/utils.go
+++ b/cmd/podman/utils.go
@@ -224,11 +224,16 @@ type workerInput struct {
parallelFunc pFunc
}
+type containerError struct {
+ containerID string
+ err error
+}
+
// worker is a "threaded" worker that takes jobs from the channel "queue"
-func worker(wg *sync.WaitGroup, jobs <-chan workerInput, results map[string]error) {
+func worker(wg *sync.WaitGroup, jobs <-chan workerInput, results chan<- containerError) {
for j := range jobs {
err := j.parallelFunc()
- results[j.containerID] = err
+ results <- containerError{containerID: j.containerID, err: err}
wg.Done()
}
}
@@ -239,6 +244,8 @@ func parallelExecuteWorkerPool(workers int, functions []workerInput) map[string]
var (
wg sync.WaitGroup
)
+
+ resultChan := make(chan containerError, len(functions))
results := make(map[string]error)
paraJobs := make(chan workerInput, len(functions))
@@ -249,7 +256,7 @@ func parallelExecuteWorkerPool(workers int, functions []workerInput) map[string]
// Create the workers
for w := 1; w <= workers; w++ {
- go worker(&wg, paraJobs, results)
+ go worker(&wg, paraJobs, resultChan)
}
// Add jobs to the workers
@@ -261,5 +268,11 @@ func parallelExecuteWorkerPool(workers int, functions []workerInput) map[string]
close(paraJobs)
wg.Wait()
+
+ close(resultChan)
+ for ctrError := range resultChan {
+ results[ctrError.containerID] = ctrError.err
+ }
+
return results
}