Lines Matching refs:condition

38 int32_t HksConditionWait(HksCondition *condition)
40 HKS_IF_NULL_LOGE_RETURN(condition, -1, "HksConditionWait condition is NULL!")
42 int32_t ret = pthread_mutex_lock(&condition->mutex);
47 if (atomic_load(&condition->notified)) {
48 int unlockRet = pthread_mutex_unlock(&condition->mutex);
55 ret = pthread_cond_wait(&condition->cond, &condition->mutex);
59 int unlockRet = pthread_mutex_unlock(&condition->mutex);
67 int32_t HksConditionNotify(HksCondition *condition)
69 HKS_IF_NULL_LOGE_RETURN(condition, -1, "HksConditionNotify condition is NULL!")
71 int32_t ret = pthread_mutex_lock(&condition->mutex);
78 if (atomic_compare_exchange_strong(&condition->notified, &flag, true)) {
84 ret = pthread_cond_signal(&condition->cond);
88 int unlockRet = pthread_mutex_unlock(&condition->mutex);
95 int32_t HksConditionNotifyAll(HksCondition *condition)
97 HKS_IF_NULL_LOGE_RETURN(condition, -1, "HksConditionNotifyAll condition is NULL!")
99 int32_t ret = pthread_mutex_lock(&condition->mutex);
106 if (atomic_compare_exchange_strong(&condition->notified, &flag, true)) {
112 ret = pthread_cond_broadcast(&condition->cond);
116 int unlockRet = pthread_mutex_unlock(&condition->mutex);
125 HksCondition *condition = (HksCondition *)HksMalloc(sizeof(HksCondition));
126 HKS_IF_NULL_RETURN(condition, NULL)
127 atomic_store(&condition->notified, false);
128 int32_t ret = pthread_mutex_init(&condition->mutex, NULL);
131 HKS_FREE(condition);
140 ret = pthread_cond_init(&condition->cond, &attr);
147 pthread_mutex_destroy(&condition->mutex);
148 HKS_FREE(condition);
151 return condition;
154 void HksConditionDestroy(HksCondition* condition)
156 if (condition == NULL) {
157 HKS_LOG_E("HksConditionDestroy condition is NULL!");
160 int ret = pthread_mutex_destroy(&condition->mutex);
164 ret = pthread_cond_destroy(&condition->cond);
168 HKS_FREE(condition);