Commit a380c1c9 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: Use ch for condition variable

Thanks @titanous I didnt know this worked.
parent 9b0c3b28
......@@ -34,8 +34,8 @@ type RemoteCmd struct {
ExitStatus int
// Internal locks and such used for safely setting some shared variables
l sync.Mutex
exitCond *sync.Cond
l sync.Mutex
exitCh chan struct{}
}
// A Communicator is the interface used to communicate with the machine
......@@ -134,33 +134,25 @@ OutputLoop:
// order to set that the command is done.
func (r *RemoteCmd) SetExited(status int) {
r.l.Lock()
if r.exitCond == nil {
r.exitCond = sync.NewCond(new(sync.Mutex))
}
r.l.Unlock()
defer r.l.Unlock()
r.exitCond.L.Lock()
defer r.exitCond.L.Unlock()
if r.exitCh == nil {
r.exitCh = make(chan struct{})
}
r.Exited = true
r.ExitStatus = status
r.exitCond.Broadcast()
close(r.exitCh)
}
// Wait waits for the remote command to complete.
func (r *RemoteCmd) Wait() {
// Make sure our condition variable is initialized.
r.l.Lock()
if r.exitCond == nil {
r.exitCond = sync.NewCond(new(sync.Mutex))
if r.exitCh == nil {
r.exitCh = make(chan struct{})
}
r.l.Unlock()
// Wait on the condition variable to notify we exited
r.exitCond.L.Lock()
defer r.exitCond.L.Unlock()
for !r.Exited {
r.exitCond.Wait()
}
<-r.exitCh
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment