Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
a380c1c9
Commit
a380c1c9
authored
Jul 29, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Use ch for condition variable
Thanks @titanous I didnt know this worked.
parent
9b0c3b28
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
18 deletions
+10
-18
packer/communicator.go
packer/communicator.go
+10
-18
No files found.
packer/communicator.go
View file @
a380c1c9
...
...
@@ -34,8 +34,8 @@ type RemoteCmd struct {
ExitStatus
int
// Internal locks and such used for safely setting some shared variables
l
sync
.
Mutex
exitC
ond
*
sync
.
Cond
l
sync
.
Mutex
exitC
h
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
.
exitC
ond
==
nil
{
r
.
exitC
ond
=
sync
.
NewCond
(
new
(
sync
.
Mutex
)
)
if
r
.
exitC
h
==
nil
{
r
.
exitC
h
=
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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment