From 2b4bbf1ef208ea2fc12e269b7822c9512efd4540 Mon Sep 17 00:00:00 2001 From: Anton Tiurin Date: Wed, 8 Apr 2015 22:30:23 +0300 Subject: [PATCH] [SwarmCluster] Add RLock to Cluster.Pull Use sync.WaitGroup (go-way) to wait for a collection of pulling goroutines. Signed-off-by: Anton Tiurin --- cluster/swarm/cluster.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cluster/swarm/cluster.go b/cluster/swarm/cluster.go index d683f6285c..368f834e83 100644 --- a/cluster/swarm/cluster.go +++ b/cluster/swarm/cluster.go @@ -199,10 +199,15 @@ func (c *Cluster) RemoveImage(image *cluster.Image) ([]*dockerclient.ImageDelete // Pull is exported func (c *Cluster) Pull(name string, callback func(what, status string)) { - size := len(c.engines) - done := make(chan bool, size) + var wg sync.WaitGroup + + c.RLock() for _, n := range c.engines { + wg.Add(1) + go func(nn *cluster.Engine) { + defer wg.Done() + if callback != nil { callback(nn.Name, "") } @@ -214,12 +219,11 @@ func (c *Cluster) Pull(name string, callback func(what, status string)) { callback(nn.Name, "downloaded") } } - done <- true }(n) } - for i := 0; i < size; i++ { - <-done - } + c.RUnlock() + + wg.Wait() } // Containers returns all the containers in the cluster.