6 #ifndef ABTI_RWLOCK_H_INCLUDED 7 #define ABTI_RWLOCK_H_INCLUDED 14 static inline ABTI_rwlock *ABTI_rwlock_get_ptr(
ABT_rwlock rwlock)
16 #ifndef ABT_CONFIG_DISABLE_ERROR_CHECK 17 ABTI_rwlock *p_rwlock;
21 p_rwlock = (ABTI_rwlock *)rwlock;
25 return (ABTI_rwlock *)rwlock;
29 static inline ABT_rwlock ABTI_rwlock_get_handle(ABTI_rwlock *p_rwlock)
31 #ifndef ABT_CONFIG_DISABLE_ERROR_CHECK 33 if (p_rwlock == NULL) {
44 static inline void ABTI_rwlock_init(ABTI_rwlock *p_rwlock)
46 ABTI_mutex_init(&p_rwlock->mutex);
47 ABTI_cond_init(&p_rwlock->cond);
48 p_rwlock->reader_count = 0;
49 p_rwlock->write_flag = 0;
52 static inline void ABTI_rwlock_fini(ABTI_rwlock *p_rwlock)
54 ABTI_mutex_fini(&p_rwlock->mutex);
55 ABTI_cond_fini(&p_rwlock->cond);
58 static inline int ABTI_rwlock_rdlock(ABTI_local **pp_local,
59 ABTI_rwlock *p_rwlock)
63 ABTI_mutex_lock(pp_local, &p_rwlock->mutex);
65 while (p_rwlock->write_flag && abt_errno ==
ABT_SUCCESS) {
66 abt_errno = ABTI_cond_wait(pp_local, &p_rwlock->cond, &p_rwlock->mutex);
70 p_rwlock->reader_count++;
73 ABTI_mutex_unlock(*pp_local, &p_rwlock->mutex);
77 static inline int ABTI_rwlock_wrlock(ABTI_local **pp_local,
78 ABTI_rwlock *p_rwlock)
81 ABTI_mutex_lock(pp_local, &p_rwlock->mutex);
83 while ((p_rwlock->write_flag || p_rwlock->reader_count) &&
85 abt_errno = ABTI_cond_wait(pp_local, &p_rwlock->cond, &p_rwlock->mutex);
89 p_rwlock->write_flag = 1;
92 ABTI_mutex_unlock(*pp_local, &p_rwlock->mutex);
96 static inline void ABTI_rwlock_unlock(ABTI_local **pp_local,
97 ABTI_rwlock *p_rwlock)
99 ABTI_mutex_lock(pp_local, &p_rwlock->mutex);
101 if (p_rwlock->write_flag) {
102 p_rwlock->write_flag = 0;
104 p_rwlock->reader_count--;
108 ABTI_local *p_local = *pp_local;
109 ABTI_cond_broadcast(p_local, &p_rwlock->cond);
111 ABTI_mutex_unlock(p_local, &p_rwlock->mutex);
struct ABT_rwlock_opaque * ABT_rwlock