aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/utils.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-10-11 15:24:05 -0400
committerMatthew Heon <matthew.heon@gmail.com>2018-10-11 16:16:29 -0400
commite0c980925b6bcb7c26036c6ef435d9e1204aecb4 (patch)
treee8b99dc88071a5a3581baa28720f3825c4c33290 /cmd/podman/utils.go
parent5f6e4cc830e82a9453e4617d6b8dccab30700f3d (diff)
downloadpodman-e0c980925b6bcb7c26036c6ef435d9e1204aecb4.tar.gz
podman-e0c980925b6bcb7c26036c6ef435d9e1204aecb4.tar.bz2
podman-e0c980925b6bcb7c26036c6ef435d9e1204aecb4.zip
Swap from map to channels for podman stop workers
We were encountering sync issues with the map, so swap to a thread-safe channel and convert into a map when we output Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Diffstat (limited to 'cmd/podman/utils.go')
-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
}