HTL_thread_cond_wait
Waits for the condition variable signal.
Interface Definition
int HTL_thread_cond_wait(HTL_thread_cond_t *thread_cond, HTL_thread_mutex_t *thread_mutex);
Description
HTL_thread_cond_wait() is used by the caller to wait for the condition variable thread_cond until the signal is sent. Users must call this function when the mutex thread_mutex is locked. The mutex is automatically released when waiting. When the caller is woken up, the mutex is automatically locked by the caller. Users need to unlock the mutex later.
This function associates thread_mutex with thread_cond. Users cannot associate multiple mutexes for the same condition variable.
Even if an error occurs, the mutex is still locked after this function returns a value.
If the mutex is recursive, the caller can lock the mutex only once.
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
thread_cond |
HTL_thread_cond_t * |
Address of the handle to the condition variable. |
Input |
thread_mutex |
HTL_thread_mutex_t * |
Address of the handle to the mutex. |
Input |
Return Value
- HTL_THREAD_SUCCESS: success.
- Other values: failure. For details, see the error code descriptions.
Example
HTL_thread_mutex_t mutex = HTL_THREAD_MUTEX_NULL;
HTL_thread_cond_t cond = HTL_THREAD_COND_NULL;
ret = HTL_thread_mutex_init(&mutex, NULL);
ret = HTL_thread_cond_init(&cond, NULL);
ret = HTL_thread_mutex_lock(&mutex);
ret = HTL_thread_cond_wait(&cond, &mutex);
// do something
HTL_thread_mutex_unlock(&mutex);