29 ABTI_barrier *p_newbarrier;
31 p_newbarrier = (ABTI_barrier *)
ABTU_malloc(
sizeof(ABTI_barrier));
33 ABTI_spinlock_clear(&p_newbarrier->lock);
34 p_newbarrier->num_waiters = num_waiters;
35 p_newbarrier->counter = 0;
36 p_newbarrier->waiters =
37 (ABTI_thread **)
ABTU_malloc(num_waiters *
sizeof(ABTI_thread *));
38 p_newbarrier->waiter_type =
42 *newbarrier = ABTI_barrier_get_handle(p_newbarrier);
63 ABTI_barrier *p_barrier = ABTI_barrier_get_ptr(barrier);
64 ABTI_CHECK_NULL_BARRIER_PTR(p_barrier);
66 ABTI_ASSERT(p_barrier->counter == 0);
70 if (num_waiters < p_barrier->num_waiters) {
72 p_barrier->num_waiters = num_waiters;
73 }
else if (num_waiters > p_barrier->num_waiters) {
75 p_barrier->num_waiters = num_waiters;
79 (ABTI_thread **)
ABTU_malloc(num_waiters *
sizeof(ABTI_thread *));
80 p_barrier->waiter_type =
108 ABTI_barrier *p_barrier = ABTI_barrier_get_ptr(h_barrier);
109 ABTI_CHECK_NULL_BARRIER_PTR(p_barrier);
111 ABTI_ASSERT(p_barrier->counter == 0);
116 ABTI_spinlock_acquire(&p_barrier->lock);
147 ABTI_local *p_local = ABTI_local_get_local();
148 ABTI_barrier *p_barrier = ABTI_barrier_get_ptr(barrier);
149 ABTI_CHECK_NULL_BARRIER_PTR(p_barrier);
152 ABTI_spinlock_acquire(&p_barrier->lock);
154 ABTI_ASSERT(p_barrier->counter < p_barrier->num_waiters);
155 pos = p_barrier->counter++;
158 if (p_barrier->counter < p_barrier->num_waiters) {
159 ABTI_thread *p_thread;
161 ABTD_atomic_int32 ext_signal = ABTD_ATOMIC_INT32_STATIC_INITIALIZER(0);
163 if (p_local != NULL) {
164 p_thread = p_local->p_thread;
165 if (p_thread == NULL) {
173 ABTI_STATIC_ASSERT(
sizeof(ext_signal) <=
sizeof(p_thread));
174 p_thread = (ABTI_thread *)&ext_signal;
179 p_barrier->waiters[pos] = p_thread;
180 p_barrier->waiter_type[pos] = type;
184 ABTI_thread_set_blocked(p_thread);
187 ABTI_spinlock_release(&p_barrier->lock);
191 ABTI_thread_suspend(&p_local, p_thread);
195 while (!ABTD_atomic_acquire_load_int32(&ext_signal))
201 for (i = 0; i < p_barrier->num_waiters - 1; i++) {
202 ABTI_thread *p_thread = p_barrier->waiters[i];
204 ABTI_thread_set_ready(p_local, p_thread);
207 ABTD_atomic_int32 *p_ext_signal = (ABTD_atomic_int32 *)p_thread;
208 ABTD_atomic_release_store_int32(p_ext_signal, 1);
211 p_barrier->waiters[i] = NULL;
215 p_barrier->counter = 0;
217 ABTI_spinlock_release(&p_barrier->lock);
244 ABTI_barrier *p_barrier = ABTI_barrier_get_ptr(barrier);
245 ABTI_CHECK_NULL_BARRIER_PTR(p_barrier);
247 *num_waiters = p_barrier->num_waiters;
struct ABT_barrier_opaque * ABT_barrier
int ABT_barrier_free(ABT_barrier *barrier)
Free the barrier.
int ABT_barrier_create(uint32_t num_waiters, ABT_barrier *newbarrier)
Create a new barrier.
static void * ABTU_malloc(size_t size)
#define HANDLE_ERROR_WITH_CODE(msg, n)
#define HANDLE_ERROR_FUNC_WITH_CODE(n)
int ABT_barrier_reinit(ABT_barrier barrier, uint32_t num_waiters)
Reinitialize the barrier.
int ABT_barrier_wait(ABT_barrier barrier)
Wait on the barrier.
int ABT_barrier_get_num_waiters(ABT_barrier barrier, uint32_t *num_waiters)
Get the number of waiters for the barrier.
static void ABTU_free(void *ptr)