* @brief Destroys a condition variable. * * This function destroys the condition variable pointed to by `cond`. After a condition * variable is destroyed, it must not be used until it is reinitialized with * `pthread_cond_init`. * * @param cond A pointer to the condition variable to be destroyed. * Must point to a valid, previously initialized condition variable. * * @return
| 159 | * @see pthread_cond_init, pthread_cond_wait, pthread_cond_signal, pthread_cond_broadcast |
| 160 | */ |
| 161 | int pthread_cond_destroy(pthread_cond_t *cond) |
| 162 | { |
| 163 | rt_err_t result; |
| 164 | if (cond == RT_NULL) |
| 165 | { |
| 166 | return EINVAL; |
| 167 | } |
| 168 | /* which is not initialized */ |
| 169 | if (cond->attr == -1) |
| 170 | { |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | if (!rt_list_isempty(&cond->sem.parent.suspend_thread)) |
| 175 | { |
| 176 | return EBUSY; |
| 177 | } |
| 178 | __retry: |
| 179 | result = rt_sem_trytake(&(cond->sem)); |
| 180 | if (result == EBUSY) |
| 181 | { |
| 182 | pthread_cond_broadcast(cond); |
| 183 | goto __retry; |
| 184 | } |
| 185 | |
| 186 | /* clean condition */ |
| 187 | rt_memset(cond, 0, sizeof(pthread_cond_t)); |
| 188 | cond->attr = -1; |
| 189 | |
| 190 | return 0; |
| 191 | } |
| 192 | RTM_EXPORT(pthread_cond_destroy); |
| 193 | |
| 194 | /** |
no test coverage detected