44 ABTI_UB_ASSERT(ABTI_initialized());
45 ABTI_UB_ASSERT(newcond);
50 #ifndef ABT_CONFIG_ENABLE_VER_20_API
55 int abt_errno =
ABTU_malloc(
sizeof(ABTI_cond), (
void **)&p_newcond);
56 ABTI_CHECK_ERROR(abt_errno);
58 ABTI_cond_init(p_newcond);
60 *newcond = ABTI_cond_get_handle(p_newcond);
94 ABTI_UB_ASSERT(ABTI_initialized());
98 ABTI_cond *p_cond = ABTI_cond_get_ptr(h_cond);
99 ABTI_CHECK_NULL_COND_PTR(p_cond);
100 #ifndef ABT_CONFIG_ENABLE_VER_20_API
102 ABTI_CHECK_TRUE(ABTI_waitlist_is_empty(&p_cond->waitlist),
ABT_ERR_COND);
104 ABTI_UB_ASSERT(ABTI_waitlist_is_empty(&p_cond->waitlist));
107 ABTI_cond_fini(p_cond);
161 ABTI_local *p_local = ABTI_local_get_local();
162 #ifndef ABT_CONFIG_ENABLE_VER_20_API
164 if (ABTI_IS_ERROR_CHECK_ENABLED && p_local) {
165 ABTI_xstream *p_local_xstream = ABTI_local_get_xstream(p_local);
166 ABTI_CHECK_TRUE(p_local_xstream->p_thread->type &
167 ABTI_THREAD_TYPE_YIELDABLE,
171 ABTI_cond *p_cond = ABTI_cond_get_ptr(cond);
172 ABTI_CHECK_NULL_COND_PTR(p_cond);
173 ABTI_mutex *p_mutex = ABTI_mutex_get_ptr(mutex);
174 ABTI_CHECK_NULL_MUTEX_PTR(p_mutex);
178 ABTI_UB_ASSERT(ABTI_mutex_is_locked(p_mutex));
180 ABTI_UB_ASSERT(!((p_mutex->attrs & ABTI_MUTEX_ATTR_RECURSIVE) &&
181 p_mutex->owner_id != ABTI_self_get_thread_id(p_local)));
183 ABTI_UB_ASSERT(!((p_mutex->attrs & ABTI_MUTEX_ATTR_RECURSIVE) &&
184 p_mutex->nesting_cnt > 1));
186 int abt_errno = ABTI_cond_wait(&p_local, p_cond, p_mutex);
187 ABTI_CHECK_ERROR(abt_errno);
246 const struct timespec *abstime)
248 ABTI_UB_ASSERT(abstime);
250 ABTI_local *p_local = ABTI_local_get_local();
251 ABTI_cond *p_cond = ABTI_cond_get_ptr(cond);
252 ABTI_CHECK_NULL_COND_PTR(p_cond);
253 ABTI_mutex *p_mutex = ABTI_mutex_get_ptr(mutex);
254 ABTI_CHECK_NULL_MUTEX_PTR(p_mutex);
258 ABTI_UB_ASSERT(ABTI_mutex_is_locked(p_mutex));
260 ABTI_UB_ASSERT(!((p_mutex->attrs & ABTI_MUTEX_ATTR_RECURSIVE) &&
261 p_mutex->owner_id != ABTI_self_get_thread_id(p_local)));
263 ABTI_UB_ASSERT(!((p_mutex->attrs & ABTI_MUTEX_ATTR_RECURSIVE) &&
264 p_mutex->nesting_cnt > 1));
269 thread.type = ABTI_THREAD_TYPE_EXT;
272 ABTD_spinlock_acquire(&p_cond->lock);
274 if (p_cond->p_waiter_mutex == NULL) {
275 p_cond->p_waiter_mutex = p_mutex;
277 if (p_cond->p_waiter_mutex != p_mutex) {
278 ABTD_spinlock_release(&p_cond->lock);
284 ABTI_mutex_unlock(p_local, p_mutex);
286 ABTI_waitlist_wait_timedout_and_unlock(&p_local, &p_cond->waitlist,
287 &p_cond->lock, tar_time,
291 ABTI_mutex_lock(&p_local, p_mutex);
316 ABTI_local *p_local = ABTI_local_get_local();
317 ABTI_cond *p_cond = ABTI_cond_get_ptr(cond);
318 ABTI_CHECK_NULL_COND_PTR(p_cond);
320 ABTD_spinlock_acquire(&p_cond->lock);
321 ABTI_waitlist_signal(p_local, &p_cond->waitlist);
322 ABTD_spinlock_release(&p_cond->lock);
348 ABTI_local *p_local = ABTI_local_get_local();
349 ABTI_cond *p_cond = ABTI_cond_get_ptr(cond);
350 ABTI_CHECK_NULL_COND_PTR(p_cond);
352 ABTI_cond_broadcast(p_local, p_cond);
363 secs = ((double)p_ts->tv_sec) + 1.0e-9 * ((double)p_ts->tv_nsec);