42 ABTI_UB_ASSERT(ABTI_initialized());
43 ABTI_UB_ASSERT(newrwlock);
45 #ifndef ABT_CONFIG_ENABLE_VER_20_API
49 ABTI_rwlock *p_newrwlock;
51 int abt_errno =
ABTU_malloc(
sizeof(ABTI_rwlock), (
void **)&p_newrwlock);
52 ABTI_CHECK_ERROR(abt_errno);
54 ABTI_mutex_init(&p_newrwlock->mutex);
55 ABTI_cond_init(&p_newrwlock->cond);
56 p_newrwlock->reader_count = 0;
57 p_newrwlock->write_flag = 0;
60 *newrwlock = ABTI_rwlock_get_handle(p_newrwlock);
92 ABTI_UB_ASSERT(ABTI_initialized());
93 ABTI_UB_ASSERT(rwlock);
96 ABTI_rwlock *p_rwlock = ABTI_rwlock_get_ptr(h_rwlock);
97 ABTI_CHECK_NULL_RWLOCK_PTR(p_rwlock);
99 ABTI_cond_fini(&p_rwlock->cond);
146 ABTI_UB_ASSERT(ABTI_initialized());
148 ABTI_local *p_local = ABTI_local_get_local();
149 ABTI_rwlock *p_rwlock = ABTI_rwlock_get_ptr(rwlock);
150 ABTI_CHECK_NULL_RWLOCK_PTR(p_rwlock);
152 #ifndef ABT_CONFIG_ENABLE_VER_20_API
154 if (ABTI_IS_ERROR_CHECK_ENABLED && p_local) {
155 ABTI_xstream *p_local_xstream = ABTI_local_get_xstream(p_local);
156 ABTI_CHECK_TRUE(p_local_xstream->p_thread->type &
157 ABTI_THREAD_TYPE_YIELDABLE,
162 ABTI_mutex_lock(&p_local, &p_rwlock->mutex);
164 while (p_rwlock->write_flag && abt_errno ==
ABT_SUCCESS) {
165 abt_errno = ABTI_cond_wait(&p_local, &p_rwlock->cond, &p_rwlock->mutex);
168 p_rwlock->reader_count++;
170 ABTI_mutex_unlock(p_local, &p_rwlock->mutex);
171 ABTI_CHECK_ERROR(abt_errno);
209 ABTI_UB_ASSERT(ABTI_initialized());
211 ABTI_local *p_local = ABTI_local_get_local();
212 ABTI_rwlock *p_rwlock = ABTI_rwlock_get_ptr(rwlock);
213 ABTI_CHECK_NULL_RWLOCK_PTR(p_rwlock);
215 #ifndef ABT_CONFIG_ENABLE_VER_20_API
217 if (ABTI_IS_ERROR_CHECK_ENABLED && p_local) {
218 ABTI_xstream *p_local_xstream = ABTI_local_get_xstream(p_local);
219 ABTI_CHECK_TRUE(p_local_xstream->p_thread->type &
220 ABTI_THREAD_TYPE_YIELDABLE,
225 ABTI_mutex_lock(&p_local, &p_rwlock->mutex);
227 while ((p_rwlock->write_flag || p_rwlock->reader_count) &&
229 abt_errno = ABTI_cond_wait(&p_local, &p_rwlock->cond, &p_rwlock->mutex);
232 p_rwlock->write_flag = 1;
234 ABTI_mutex_unlock(p_local, &p_rwlock->mutex);
235 ABTI_CHECK_ERROR(abt_errno);
265 ABTI_UB_ASSERT(ABTI_initialized());
267 ABTI_local *p_local = ABTI_local_get_local();
268 ABTI_rwlock *p_rwlock = ABTI_rwlock_get_ptr(rwlock);
269 ABTI_CHECK_NULL_RWLOCK_PTR(p_rwlock);
271 ABTI_mutex_lock(&p_local, &p_rwlock->mutex);
272 if (p_rwlock->write_flag) {
273 p_rwlock->write_flag = 0;
275 ABTI_UB_ASSERT(p_rwlock->reader_count > 0);
276 p_rwlock->reader_count--;
278 ABTI_cond_broadcast(p_local, &p_rwlock->cond);
279 ABTI_mutex_unlock(p_local, &p_rwlock->mutex);