Skip to content

Commit

Permalink
pthread_barrier_wait: properly check the wait condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Youw committed Nov 19, 2023
1 parent 4168d87 commit dae9e11
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions mac/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,18 @@ static int pthread_barrier_wait(pthread_barrier_t *barrier)
{
pthread_mutex_lock(&barrier->mutex);
++(barrier->count);
if(barrier->count >= barrier->trip_count)
{
if(barrier->count >= barrier->trip_count) {
barrier->count = 0;
pthread_cond_broadcast(&barrier->cond);
pthread_mutex_unlock(&barrier->mutex);
return 1;
}
else
{
pthread_cond_wait(&barrier->cond, &(barrier->mutex));
else {
do {
pthread_cond_wait(&barrier->cond, &(barrier->mutex));
}
while (!(barrier->count >= barrier->trip_count));

pthread_mutex_unlock(&barrier->mutex);
return 0;
}
Expand Down

0 comments on commit dae9e11

Please sign in to comment.