From David Fries, "Comparing the win32 barrier to the pthread barrier, win32 puts the

while in an else clause.  When if is true the phase changes and the
while condition will always by false, so might as well put the while
in the else to skip the check.  There's also a benefit to having the
code logic similar between platforms.
"
This commit is contained in:
Robert Osfield
2009-07-13 16:14:43 +00:00
parent 3983f38f18
commit 9aa6d33980

View File

@@ -170,18 +170,20 @@ void Barrier::block(unsigned int numThreads) {
++pd->cnt;
if (pd->cnt == pd->maxcnt) { // I am the last one
pd->cnt = 0; // reset for next use
pd->phase = 1 - my_phase; // toggle phase
pthread_cond_broadcast(&(pd->cond));
}
pd->cnt = 0; // reset for next use
pd->phase = 1 - my_phase; // toggle phase
pthread_cond_broadcast(&(pd->cond));
}
else
{
while (pd->phase == my_phase)
{
pthread_cleanup_push(barrier_cleanup_handler, &(pd->lock));
while (pd->phase == my_phase) {
pthread_cond_wait(&(pd->cond), &(pd->lock));
pthread_cleanup_push(barrier_cleanup_handler, &(pd->lock));
pthread_cond_wait(&(pd->cond), &(pd->lock));
pthread_cleanup_pop(0);
pthread_cleanup_pop(0);
}
}
}