Lines Matching defs:cond

45 STATIC INLINE INT32 CondInitCheck(const pthread_cond_t *cond)
47 if ((cond->event.stEventList.pstPrev == NULL) &&
48 (cond->event.stEventList.pstNext == NULL)) {
97 int pthread_cond_destroy(pthread_cond_t *cond)
99 if (cond == NULL) {
103 if (CondInitCheck(cond)) {
107 if (LOS_EventDestroy(&cond->event) != LOS_OK) {
110 if (pthread_mutex_destroy(cond->mutex) != ENOERR) {
114 free(cond->mutex);
115 cond->mutex = NULL;
119 int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
123 if (cond == NULL) {
127 (VOID)LOS_EventInit(&(cond->event));
129 cond->mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
130 if (cond->mutex == NULL) {
134 (VOID)pthread_mutex_init(cond->mutex, NULL);
136 cond->value = 0;
137 (VOID)pthread_mutex_lock(cond->mutex);
138 cond->count = 0;
139 (VOID)pthread_mutex_unlock(cond->mutex);
144 STATIC VOID PthreadCondValueModify(pthread_cond_t *cond)
146 UINT32 flags = ((UINT32)cond->value & COND_FLAGS_MASK);
150 oldVal = cond->value;
152 if (LOS_AtomicCmpXchg32bits(&cond->value, newVal, oldVal) == 0) {
158 int pthread_cond_broadcast(pthread_cond_t *cond)
162 if (cond == NULL) {
166 (VOID)pthread_mutex_lock(cond->mutex);
167 if (cond->count > 0) {
168 cond->count = 0;
169 (VOID)pthread_mutex_unlock(cond->mutex);
171 PthreadCondValueModify(cond);
173 (VOID)LOS_EventWrite(&(cond->event), BROADCAST_EVENT);
176 (VOID)pthread_mutex_unlock(cond->mutex);
181 int pthread_cond_signal(pthread_cond_t *cond)
185 if (cond == NULL) {
189 (VOID)pthread_mutex_lock(cond->mutex);
190 if (cond->count > 0) {
191 cond->count--;
192 (VOID)pthread_mutex_unlock(cond->mutex);
193 PthreadCondValueModify(cond);
194 (VOID)OsEventWriteOnce(&(cond->event), 0x01);
198 (VOID)pthread_mutex_unlock(cond->mutex);
203 STATIC INT32 PthreadCondWaitSub(pthread_cond_t *cond, INT32 value, UINT32 ticks)
205 EventCond eventCond = { &cond->value, value, ~0x01U };
208 * (1) value is not equal to cond->value, clear the event message and
210 * pthread_cond_signal to modify cond->value and wake up the current thread,
213 * (2) value is equal to cond->value, block the current thread
216 return (int)OsEventReadWithCond(&eventCond, &(cond->event), 0x0fU,
219 STATIC VOID PthreadCountSub(pthread_cond_t *cond)
221 (VOID)pthread_mutex_lock(cond->mutex);
222 if (cond->count > 0) {
223 cond->count--;
225 (VOID)pthread_mutex_unlock(cond->mutex);
228 STATIC INT32 ProcessReturnVal(pthread_cond_t *cond, INT32 val)
238 PthreadCountSub(cond);
242 PthreadCountSub(cond);
249 int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
257 if ((cond == NULL) || (mutex == NULL) || (absTime == NULL)) {
261 if (CondInitCheck(cond)) {
262 ret = pthread_cond_init(cond, NULL);
267 oldValue = cond->value;
269 (VOID)pthread_mutex_lock(cond->mutex);
270 cond->count++;
271 (VOID)pthread_mutex_unlock(cond->mutex);
287 ret = PthreadCondWaitSub(cond, oldValue, absTicks);
289 ret = (INT32)LOS_EventRead(&(cond->event), 0x0f, LOS_WAITMODE_OR | LOS_WAITMODE_CLR, absTicks);
295 ret = ProcessReturnVal(cond, ret);
300 int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
305 if ((cond == NULL) || (mutex == NULL)) {
309 if (CondInitCheck(cond)) {
310 ret = pthread_cond_init(cond, NULL);
315 oldValue = cond->value;
317 (VOID)pthread_mutex_lock(cond->mutex);
318 cond->count++;
319 (VOID)pthread_mutex_unlock(cond->mutex);
326 ret = PthreadCondWaitSub(cond, oldValue, LOS_WAIT_FOREVER);
328 ret = (INT32)LOS_EventRead(&(cond->event), 0x0f, LOS_WAITMODE_OR | LOS_WAITMODE_CLR, LOS_WAIT_FOREVER);
341 PthreadCountSub(cond);