Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SWIFT
SWIFTsim
Commits
b6392d82
Commit
b6392d82
authored
Jul 30, 2017
by
Pedro Gonnet
Committed by
Matthieu Schaller
Aug 03, 2017
Browse files
grossly simplify the engine_barrier function using pthread_barriers.
parent
49c6a402
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/engine.c
View file @
b6392d82
...
...
@@ -2930,35 +2930,12 @@ void engine_prepare(struct engine *e) {
*/
void
engine_barrier
(
struct
engine
*
e
,
int
tid
)
{
/* First, get the barrier mutex. */
if
(
pthread_mutex_lock
(
&
e
->
barrier_mutex
)
!=
0
)
error
(
"Failed to get barrier mutex."
);
/* This thread is no longer running. */
e
->
barrier_running
-=
1
;
/* If all threads are in, send a signal... */
if
(
e
->
barrier_running
==
0
)
if
(
pthread_cond_broadcast
(
&
e
->
barrier_cond
)
!=
0
)
error
(
"Failed to broadcast barrier full condition."
);
/* Wait for the barrier to open. */
while
(
e
->
barrier_launch
==
0
||
tid
>=
e
->
barrier_launchcount
)
if
(
pthread_cond_wait
(
&
e
->
barrier_cond
,
&
e
->
barrier_mutex
)
!=
0
)
error
(
"Error waiting for barrier to close."
);
/* This thread has been launched. */
e
->
barrier_running
+=
1
;
e
->
barrier_launch
-=
1
;
/* If I'm the last one out, signal the condition again. */
if
(
e
->
barrier_launch
==
0
)
if
(
pthread_cond_broadcast
(
&
e
->
barrier_cond
)
!=
0
)
error
(
"Failed to broadcast empty barrier condition."
);
/* Wait at the wait barrier. */
pthread_barrier_wait
(
&
e
->
wait_barrier
);
/* Wait at the run barrier. */
pthread_barrier_wait
(
&
e
->
run_barrier
);
/* Last but not least, release the mutex. */
if
(
pthread_mutex_unlock
(
&
e
->
barrier_mutex
)
!=
0
)
error
(
"Failed to get unlock the barrier mutex."
);
}
/**
...
...
Write
Preview
Supports
Markdown
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