File tree Expand file tree Collapse file tree 1 file changed +11
-9
lines changed
Expand file tree Collapse file tree 1 file changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -54,15 +54,15 @@ static int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrie
5454{
5555 (void ) attr ;
5656
57- if (count == 0 ) {
57+ if (count == 0 ) {
5858 errno = EINVAL ;
5959 return -1 ;
6060 }
6161
62- if (pthread_mutex_init (& barrier -> mutex , 0 ) < 0 ) {
62+ if (pthread_mutex_init (& barrier -> mutex , 0 ) < 0 ) {
6363 return -1 ;
6464 }
65- if (pthread_cond_init (& barrier -> cond , 0 ) < 0 ) {
65+ if (pthread_cond_init (& barrier -> cond , 0 ) < 0 ) {
6666 pthread_mutex_destroy (& barrier -> mutex );
6767 return -1 ;
6868 }
@@ -83,16 +83,18 @@ static int pthread_barrier_wait(pthread_barrier_t *barrier)
8383{
8484 pthread_mutex_lock (& barrier -> mutex );
8585 ++ (barrier -> count );
86- if (barrier -> count >= barrier -> trip_count )
87- {
86+ if (barrier -> count >= barrier -> trip_count ) {
8887 barrier -> count = 0 ;
89- pthread_cond_broadcast (& barrier -> cond );
9088 pthread_mutex_unlock (& barrier -> mutex );
89+ pthread_cond_broadcast (& barrier -> cond );
9190 return 1 ;
9291 }
93- else
94- {
95- pthread_cond_wait (& barrier -> cond , & (barrier -> mutex ));
92+ else {
93+ do {
94+ pthread_cond_wait (& barrier -> cond , & (barrier -> mutex ));
95+ }
96+ while (barrier -> count != 0 );
97+
9698 pthread_mutex_unlock (& barrier -> mutex );
9799 return 0 ;
98100 }
You can’t perform that action at this time.
0 commit comments