* @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
| 216 | * @see pthread_cond_signal, pthread_cond_wait, pthread_cond_init, pthread_cond_destroy |
| 217 | */ |
| 218 | int 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 | } |
| 250 | RTM_EXPORT(pthread_cond_broadcast); |
| 251 | |
| 252 | /** |
no test coverage detected