47 ABTI_UB_ASSERT(ABTI_initialized());
48 ABTI_UB_ASSERT(newbarrier);
50 #ifndef ABT_CONFIG_ENABLE_VER_20_API
55 ABTI_xstream_barrier *p_newbarrier;
59 ABTU_malloc(
sizeof(ABTI_xstream_barrier), (
void **)&p_newbarrier);
60 ABTI_CHECK_ERROR(abt_errno);
62 p_newbarrier->num_waiters = num_waiters;
63 #ifdef HAVE_PTHREAD_BARRIER_INIT
64 abt_errno = ABTD_xstream_barrier_init(num_waiters, &p_newbarrier->bar);
65 if (ABTI_IS_ERROR_CHECK_ENABLED && abt_errno !=
ABT_SUCCESS) {
67 ABTI_HANDLE_ERROR(abt_errno);
70 ABTD_spinlock_clear(&p_newbarrier->lock);
71 p_newbarrier->counter = 0;
72 ABTD_atomic_relaxed_store_uint64(&p_newbarrier->tag, 0);
76 *newbarrier = ABTI_xstream_barrier_get_handle(p_newbarrier);
106 ABTI_UB_ASSERT(ABTI_initialized());
107 ABTI_UB_ASSERT(barrier);
110 ABTI_xstream_barrier *p_barrier = ABTI_xstream_barrier_get_ptr(h_barrier);
111 ABTI_CHECK_NULL_XSTREAM_BARRIER_PTR(p_barrier);
113 #ifdef HAVE_PTHREAD_BARRIER_INIT
114 ABTD_xstream_barrier_destroy(&p_barrier->bar);
148 ABTI_UB_ASSERT(ABTI_initialized());
150 ABTI_xstream_barrier *p_barrier = ABTI_xstream_barrier_get_ptr(barrier);
151 ABTI_CHECK_NULL_XSTREAM_BARRIER_PTR(p_barrier);
153 if (p_barrier->num_waiters > 1) {
154 #ifdef HAVE_PTHREAD_BARRIER_INIT
155 ABTD_xstream_barrier_wait(&p_barrier->bar);
160 ABTD_spinlock_acquire(&p_barrier->lock);
161 p_barrier->counter++;
162 if (p_barrier->counter == p_barrier->num_waiters) {
164 p_barrier->counter = 0;
167 uint64_t cur_tag = ABTD_atomic_relaxed_load_uint64(&p_barrier->tag);
168 uint64_t new_tag = (cur_tag + 1) & (UINT64_MAX >> 1);
169 ABTD_atomic_release_store_uint64(&p_barrier->tag, new_tag);
170 ABTD_spinlock_release(&p_barrier->lock);
173 uint64_t cur_tag = ABTD_atomic_relaxed_load_uint64(&p_barrier->tag);
174 ABTD_spinlock_release(&p_barrier->lock);
175 while (cur_tag == ABTD_atomic_acquire_load_uint64(&p_barrier->tag))