6 #ifndef ABTI_COND_H_INCLUDED 7 #define ABTI_COND_H_INCLUDED 13 static inline void ABTI_cond_init(ABTI_cond *p_cond)
15 ABTI_spinlock_clear(&p_cond->lock);
16 p_cond->p_waiter_mutex = NULL;
17 p_cond->num_waiters = 0;
18 p_cond->p_head = NULL;
19 p_cond->p_tail = NULL;
22 static inline void ABTI_cond_fini(ABTI_cond *p_cond)
27 ABTI_spinlock_acquire(&p_cond->lock);
30 static inline ABTI_cond *ABTI_cond_get_ptr(
ABT_cond cond)
32 #ifndef ABT_CONFIG_DISABLE_ERROR_CHECK 37 p_cond = (ABTI_cond *)cond;
41 return (ABTI_cond *)cond;
45 static inline ABT_cond ABTI_cond_get_handle(ABTI_cond *p_cond)
47 #ifndef ABT_CONFIG_DISABLE_ERROR_CHECK 60 static inline int ABTI_cond_wait(ABTI_local **pp_local, ABTI_cond *p_cond,
65 ABTI_local *p_local = *pp_local;
66 ABTI_thread *p_thread;
69 ABTD_atomic_int32 ext_signal = ABTD_ATOMIC_INT32_STATIC_INITIALIZER(0);
71 if (p_local != NULL) {
72 p_thread = p_local->p_thread;
76 p_unit = &p_thread->unit_def;
77 p_unit->handle.thread = ABTI_thread_get_handle(p_thread);
82 p_unit = (ABTI_unit *)
ABTU_calloc(1,
sizeof(ABTI_unit));
84 ABTI_STATIC_ASSERT(
sizeof(ext_signal) <=
sizeof(p_unit->handle.thread));
85 p_unit->handle.thread = (
ABT_thread)&ext_signal;
89 ABTI_spinlock_acquire(&p_cond->lock);
91 if (p_cond->p_waiter_mutex == NULL) {
92 p_cond->p_waiter_mutex = p_mutex;
94 ABT_bool result = ABTI_mutex_equal(p_cond->p_waiter_mutex, p_mutex);
96 ABTI_spinlock_release(&p_cond->lock);
104 if (p_cond->num_waiters == 0) {
105 p_unit->p_prev = p_unit;
106 p_unit->p_next = p_unit;
107 p_cond->p_head = p_unit;
108 p_cond->p_tail = p_unit;
110 p_cond->p_tail->p_next = p_unit;
111 p_cond->p_head->p_prev = p_unit;
112 p_unit->p_prev = p_cond->p_tail;
113 p_unit->p_next = p_cond->p_head;
114 p_cond->p_tail = p_unit;
117 p_cond->num_waiters++;
121 ABTI_thread_set_blocked(p_thread);
123 ABTI_spinlock_release(&p_cond->lock);
127 ABTI_mutex_unlock(p_local, p_mutex);
130 ABTI_thread_suspend(pp_local, p_thread);
133 ABTI_spinlock_release(&p_cond->lock);
134 ABTI_mutex_unlock(p_local, p_mutex);
138 while (!ABTD_atomic_acquire_load_int32(&ext_signal))
144 ABTI_mutex_lock(pp_local, p_mutex);
154 static inline void ABTI_cond_broadcast(ABTI_local *p_local, ABTI_cond *p_cond)
156 ABTI_spinlock_acquire(&p_cond->lock);
158 if (p_cond->num_waiters == 0) {
159 ABTI_spinlock_release(&p_cond->lock);
164 ABTI_unit *p_head = p_cond->p_head;
165 ABTI_unit *p_unit = p_head;
167 ABTI_unit *p_next = p_unit->p_next;
169 p_unit->p_prev = NULL;
170 p_unit->p_next = NULL;
173 ABTI_thread *p_thread = ABTI_thread_get_ptr(p_unit->handle.thread);
174 ABTI_thread_set_ready(p_local, p_thread);
177 ABTD_atomic_int32 *p_ext_signal =
178 (ABTD_atomic_int32 *)p_unit->handle.thread;
179 ABTD_atomic_release_store_int32(p_ext_signal, 1);
183 if (p_next != p_head) {
190 p_cond->p_waiter_mutex = NULL;
191 p_cond->num_waiters = 0;
192 p_cond->p_head = NULL;
193 p_cond->p_tail = NULL;
195 ABTI_spinlock_release(&p_cond->lock);
#define ABT_ERR_INV_MUTEX
struct ABT_thread_opaque * ABT_thread
#define HANDLE_ERROR_FUNC_WITH_CODE(n)
static void ABTU_free(void *ptr)
static void * ABTU_calloc(size_t num, size_t size)
struct ABT_cond_opaque * ABT_cond