MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / pthread_cond_broadcast

Function pthread_cond_broadcast

components/libc/posix/pthreads/pthread_cond.c:218–249  ·  view source on GitHub ↗

* @brief Unblocks all threads waiting on the specified condition variable. * * This function wakes up all threads that are currently blocked on the condition variable * pointed to by `cond`. The condition variable must be associated with a mutex, and * threads waiting on the condition variable should recheck the condition after being * unblocked. * * @param cond A pointer to the condition v

Source from the content-addressed store, hash-verified

216 * @see pthread_cond_signal, pthread_cond_wait, pthread_cond_init, pthread_cond_destroy
217 */
218int pthread_cond_broadcast(pthread_cond_t *cond)
219{
220 rt_err_t result;
221
222 if (cond == RT_NULL)
223 return EINVAL;
224 if (cond->attr == -1)
225 pthread_cond_init(cond, RT_NULL);
226
227 while (1)
228 {
229 /* try to take condition semaphore */
230 result = rt_sem_trytake(&(cond->sem));
231 if (result == -RT_ETIMEOUT)
232 {
233 /* it's timeout, release this semaphore */
234 rt_sem_release(&(cond->sem));
235 }
236 else if (result == RT_EOK)
237 {
238 /* has taken this semaphore, release it */
239 rt_sem_release(&(cond->sem));
240 break;
241 }
242 else
243 {
244 return EINVAL;
245 }
246 }
247
248 return 0;
249}
250RTM_EXPORT(pthread_cond_broadcast);
251
252/**

Callers 3

pthread_barrier_waitFunction · 0.85
pthread_cond_destroyFunction · 0.85
pthread_rwlock_unlockFunction · 0.85

Calls 3

pthread_cond_initFunction · 0.85
rt_sem_trytakeFunction · 0.85
rt_sem_releaseFunction · 0.85

Tested by

no test coverage detected