File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
components/libc/posix/pthreads Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,30 @@ int pthread_barrier_destroy(pthread_barrier_t *barrier)
8686 if (!barrier )
8787 return EINVAL ;
8888
89+ /* Lock the internal mutex to safely check the barrier's state*/
90+ result = pthread_mutex_lock (& (barrier -> mutex ));
91+ if (result != 0 )
92+ return result ;
93+
94+ /* Check if any threads are currently waiting on the barrier*/
95+ if (barrier -> count != 0 )
96+ {
97+ pthread_mutex_unlock (& (barrier -> mutex ));
98+ return EBUSY ; /* Threads are still waiting*/
99+ }
100+
101+ /* Free resources associated with the barrier*/
102+ result = pthread_mutex_unlock (& (barrier -> mutex ));
103+ if (result != 0 )
104+ {
105+ return result ; /* Return mutex unlock error*/
106+ }
107+
108+ result = pthread_mutex_destroy (& (barrier -> mutex ));
109+ if (result != 0 )
110+ {
111+ return result ; /* Return mutex destroy error*/
112+ }
89113 result = pthread_cond_destroy (& (barrier -> cond ));
90114
91115 return result ;
You can’t perform that action at this time.
0 commit comments