64 ABTI_UB_ASSERT(ABTI_initialized());
65 ABTI_UB_ASSERT(newfuture);
68 ABTI_future *p_future;
69 size_t arg_num_compartments = num_compartments;
71 abt_errno =
ABTU_malloc(
sizeof(ABTI_future), (
void **)&p_future);
72 ABTI_CHECK_ERROR(abt_errno);
73 ABTD_spinlock_clear(&p_future->lock);
74 ABTD_atomic_relaxed_store_size(&p_future->counter, 0);
75 p_future->num_compartments = arg_num_compartments;
76 if (arg_num_compartments > 0) {
77 abt_errno =
ABTU_malloc(arg_num_compartments *
sizeof(
void *),
78 (
void **)&p_future->array);
79 if (ABTI_IS_ERROR_CHECK_ENABLED && abt_errno !=
ABT_SUCCESS) {
81 ABTI_HANDLE_ERROR(abt_errno);
84 p_future->array = NULL;
86 p_future->p_callback = cb_func;
87 ABTI_waitlist_init(&p_future->waitlist);
89 *newfuture = ABTI_future_get_handle(p_future);
121 ABTI_UB_ASSERT(ABTI_initialized());
122 ABTI_UB_ASSERT(future);
124 ABTI_future *p_future = ABTI_future_get_ptr(*future);
125 ABTI_CHECK_NULL_FUTURE_PTR(p_future);
130 ABTD_spinlock_acquire(&p_future->lock);
131 ABTI_UB_ASSERT(ABTI_waitlist_is_empty(&p_future->waitlist));
174 ABTI_UB_ASSERT(ABTI_initialized());
176 ABTI_local *p_local = ABTI_local_get_local();
177 ABTI_future *p_future = ABTI_future_get_ptr(future);
178 ABTI_CHECK_NULL_FUTURE_PTR(p_future);
180 #ifndef ABT_CONFIG_ENABLE_VER_20_API
182 if (ABTI_IS_ERROR_CHECK_ENABLED && p_local) {
183 ABTI_xstream *p_local_xstream = ABTI_local_get_xstream(p_local);
184 ABTI_CHECK_TRUE(p_local_xstream->p_thread->type &
185 ABTI_THREAD_TYPE_YIELDABLE,
190 ABTD_spinlock_acquire(&p_future->lock);
191 if (ABTD_atomic_relaxed_load_size(&p_future->counter) <
192 p_future->num_compartments) {
193 ABTI_waitlist_wait_and_unlock(&p_local, &p_future->waitlist,
198 ABTD_spinlock_release(&p_future->lock);
231 ABTI_UB_ASSERT(ABTI_initialized());
232 ABTI_UB_ASSERT(is_ready);
234 ABTI_future *p_future = ABTI_future_get_ptr(future);
235 ABTI_CHECK_NULL_FUTURE_PTR(p_future);
237 size_t counter = ABTD_atomic_acquire_load_size(&p_future->counter);
272 ABTI_UB_ASSERT(ABTI_initialized());
274 ABTI_local *p_local = ABTI_local_get_local();
275 ABTI_future *p_future = ABTI_future_get_ptr(future);
276 ABTI_CHECK_NULL_FUTURE_PTR(p_future);
278 ABTD_spinlock_acquire(&p_future->lock);
280 size_t counter = ABTD_atomic_relaxed_load_size(&p_future->counter);
281 size_t num_compartments = p_future->num_compartments;
282 #ifndef ABT_CONFIG_DISABLE_ERROR_CHECK
284 if (counter >= num_compartments) {
285 ABTD_spinlock_release(&p_future->lock);
289 p_future->array[counter] = value;
292 if (counter == num_compartments && p_future->p_callback != NULL) {
293 (*p_future->p_callback)(p_future->array);
296 ABTD_atomic_release_store_size(&p_future->counter, counter);
298 if (counter == num_compartments) {
299 ABTI_waitlist_broadcast(p_local, &p_future->waitlist);
302 ABTD_spinlock_release(&p_future->lock);
339 ABTI_UB_ASSERT(ABTI_initialized());
341 ABTI_future *p_future = ABTI_future_get_ptr(future);
342 ABTI_CHECK_NULL_FUTURE_PTR(p_future);
344 ABTD_spinlock_acquire(&p_future->lock);
345 ABTI_UB_ASSERT(ABTI_waitlist_is_empty(&p_future->waitlist));
346 ABTD_atomic_release_store_size(&p_future->counter, 0);
347 ABTD_spinlock_release(&p_future->lock);