14 ythread_create(ABTI_global *p_global, ABTI_local *p_local, ABTI_pool *p_pool,
15 void (*thread_func)(
void *),
void *arg, ABTI_thread_attr *p_attr,
16 ABTI_thread_type thread_type, ABTI_sched *p_sched,
19 thread_revive(ABTI_global *p_global, ABTI_local *p_local, ABTI_pool *p_pool,
20 void (*thread_func)(
void *),
void *arg,
22 static inline void thread_join(ABTI_local **pp_local, ABTI_thread *p_thread);
23 static inline void thread_free(ABTI_global *p_global, ABTI_local *p_local,
24 ABTI_thread *p_thread,
ABT_bool free_unit);
27 #ifndef ABT_CONFIG_DISABLE_MIGRATION
30 ABTI_thread *p_thread,
38 ABTI_KEY_ID_STACKABLE_SCHED);
42 ABTI_KEY_ID_MIGRATION);
100 ABTI_UB_ASSERT(ABTI_initialized());
101 ABTI_UB_ASSERT(thread_func);
103 #ifndef ABT_CONFIG_ENABLE_VER_20_API
108 ABTI_global *p_global;
109 ABTI_SETUP_GLOBAL(&p_global);
110 ABTI_local *p_local = ABTI_local_get_local();
111 ABTI_ythread *p_newthread;
113 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
114 ABTI_CHECK_NULL_POOL_PTR(p_pool);
116 ABTI_thread_type unit_type =
118 ? (ABTI_THREAD_TYPE_YIELDABLE | ABTI_THREAD_TYPE_NAMED)
119 : ABTI_THREAD_TYPE_YIELDABLE;
120 int abt_errno =
ythread_create(p_global, p_local, p_pool, thread_func, arg,
121 ABTI_thread_attr_get_ptr(attr), unit_type,
123 ABTI_CHECK_ERROR(abt_errno);
127 *newthread = ABTI_ythread_get_handle(p_newthread);
182 ABTI_UB_ASSERT(ABTI_initialized());
183 ABTI_UB_ASSERT(thread_func);
185 ABTI_global *p_global;
186 ABTI_SETUP_GLOBAL(&p_global);
187 ABTI_xstream *p_local_xstream;
188 ABTI_ythread *p_cur_ythread, *p_newthread;
189 ABTI_SETUP_LOCAL_YTHREAD(&p_local_xstream, &p_cur_ythread);
190 ABTI_CHECK_TRUE(!(p_cur_ythread->thread.type & ABTI_THREAD_TYPE_MAIN_SCHED),
193 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
194 ABTI_CHECK_NULL_POOL_PTR(p_pool);
196 ABTI_thread_type unit_type =
198 ? (ABTI_THREAD_TYPE_YIELDABLE | ABTI_THREAD_TYPE_NAMED)
199 : ABTI_THREAD_TYPE_YIELDABLE;
202 p_pool, thread_func, arg, ABTI_thread_attr_get_ptr(attr),
204 ABTI_CHECK_ERROR(abt_errno);
208 *newthread = ABTI_ythread_get_handle(p_newthread);
211 ABTI_ythread_yield_to(&p_local_xstream, p_cur_ythread, p_newthread,
212 ABTI_YTHREAD_YIELD_TO_KIND_CREATE_TO,
267 void (*thread_func)(
void *),
void *arg,
270 ABTI_UB_ASSERT(ABTI_initialized());
271 ABTI_UB_ASSERT(thread_func);
273 #ifndef ABT_CONFIG_ENABLE_VER_20_API
278 ABTI_global *p_global;
279 ABTI_SETUP_GLOBAL(&p_global);
280 ABTI_local *p_local = ABTI_local_get_local();
281 ABTI_ythread *p_newthread;
283 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
284 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
287 ABTI_pool *p_pool = ABTI_xstream_get_main_pool(p_xstream);
288 ABTI_thread_type unit_type =
290 ? (ABTI_THREAD_TYPE_YIELDABLE | ABTI_THREAD_TYPE_NAMED)
291 : ABTI_THREAD_TYPE_YIELDABLE;
292 int abt_errno =
ythread_create(p_global, p_local, p_pool, thread_func, arg,
293 ABTI_thread_attr_get_ptr(attr), unit_type,
295 ABTI_CHECK_ERROR(abt_errno);
299 *newthread = ABTI_ythread_get_handle(p_newthread);
353 void (**thread_func_list)(
void *),
void **arg_list,
356 ABTI_global *p_global;
357 ABTI_SETUP_GLOBAL(&p_global);
358 ABTI_local *p_local = ABTI_local_get_local();
364 ABTI_CHECK_TRUE(ABTI_thread_attr_get_ptr(attr)->p_stack == NULL,
368 if (newthread_list == NULL) {
369 for (i = 0; i < num_threads; i++) {
370 ABTI_ythread *p_newthread;
372 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
373 ABTI_CHECK_NULL_POOL_PTR(p_pool);
375 void (*thread_f)(
void *) = thread_func_list[i];
376 void *arg = arg_list ? arg_list[i] : NULL;
377 int abt_errno =
ythread_create(p_global, p_local, p_pool, thread_f,
378 arg, ABTI_thread_attr_get_ptr(attr),
379 ABTI_THREAD_TYPE_YIELDABLE, NULL,
381 ABTI_CHECK_ERROR(abt_errno);
384 for (i = 0; i < num_threads; i++) {
385 ABTI_ythread *p_newthread;
387 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
388 ABTI_CHECK_NULL_POOL_PTR(p_pool);
390 void (*thread_f)(
void *) = thread_func_list[i];
391 void *arg = arg_list ? arg_list[i] : NULL;
394 ABTI_thread_attr_get_ptr(attr),
395 ABTI_THREAD_TYPE_YIELDABLE |
396 ABTI_THREAD_TYPE_NAMED,
398 newthread_list[i] = ABTI_ythread_get_handle(p_newthread);
400 ABTI_CHECK_ERROR(abt_errno);
459 ABTI_UB_ASSERT(ABTI_initialized());
460 ABTI_UB_ASSERT(thread_func);
461 ABTI_UB_ASSERT(thread);
463 ABTI_global *p_global = ABTI_global_get_global();
464 ABTI_local *p_local = ABTI_local_get_local();
466 ABTI_thread *p_thread = ABTI_thread_get_ptr(*thread);
467 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
469 ABTI_CHECK_TRUE(ABTD_atomic_relaxed_load_int(&p_thread->state) ==
473 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
474 ABTI_CHECK_NULL_POOL_PTR(p_pool);
476 int abt_errno =
thread_revive(p_global, p_local, p_pool, thread_func, arg,
478 ABTI_CHECK_ERROR(abt_errno);
536 ABTI_UB_ASSERT(ABTI_initialized());
537 ABTI_UB_ASSERT(thread_func);
538 ABTI_UB_ASSERT(thread);
540 ABTI_global *p_global = ABTI_global_get_global();
541 ABTI_xstream *p_local_xstream;
542 ABTI_ythread *p_self, *p_target;
543 ABTI_SETUP_LOCAL_YTHREAD(&p_local_xstream, &p_self);
544 ABTI_CHECK_TRUE(!(p_self->thread.type & ABTI_THREAD_TYPE_MAIN_SCHED),
547 ABTI_thread *p_thread = ABTI_thread_get_ptr(*thread);
548 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
549 ABTI_CHECK_TRUE(ABTD_atomic_relaxed_load_int(&p_thread->state) ==
555 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
556 ABTI_CHECK_NULL_POOL_PTR(p_pool);
559 thread_revive(p_global, ABTI_xstream_get_local(p_local_xstream), p_pool,
561 ABTI_CHECK_ERROR(abt_errno);
564 ABTI_ythread_yield_to(&p_local_xstream, p_self, p_target,
565 ABTI_YTHREAD_YIELD_TO_KIND_REVIVE_TO,
612 ABTI_UB_ASSERT(ABTI_initialized());
613 ABTI_UB_ASSERT(thread);
615 ABTI_global *p_global;
616 ABTI_SETUP_GLOBAL(&p_global);
617 ABTI_local *p_local = ABTI_local_get_local();
620 ABTI_thread *p_thread = ABTI_thread_get_ptr(h_thread);
621 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
622 ABTI_CHECK_TRUE(!ABTI_local_get_xstream_or_null(p_local) ||
623 p_thread != ABTI_local_get_xstream(p_local)->p_thread,
625 ABTI_CHECK_TRUE(!(p_thread->type &
626 (ABTI_THREAD_TYPE_PRIMARY | ABTI_THREAD_TYPE_MAIN_SCHED)),
632 ABTI_thread_free(p_global, p_local, p_thread);
675 ABTI_global *p_global;
676 ABTI_SETUP_GLOBAL(&p_global);
677 ABTI_local *p_local = ABTI_local_get_local();
680 for (i = 0; i < num_threads; i++) {
681 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread_list[i]);
687 ABTI_thread_free(p_global, p_local, p_thread);
733 ABTI_UB_ASSERT(ABTI_initialized());
735 ABTI_local *p_local = ABTI_local_get_local();
736 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
737 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
738 ABTI_CHECK_TRUE(!ABTI_local_get_xstream_or_null(p_local) ||
739 p_thread != ABTI_local_get_xstream(p_local)->p_thread,
741 ABTI_CHECK_TRUE(!(p_thread->type &
742 (ABTI_THREAD_TYPE_PRIMARY | ABTI_THREAD_TYPE_MAIN_SCHED)),
782 ABTI_local *p_local = ABTI_local_get_local();
784 for (i = 0; i < num_threads; i++) {
785 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread_list[i]);
824 ABTI_xstream *p_local_xstream;
825 ABTI_ythread *p_ythread;
826 #ifndef ABT_CONFIG_ENABLE_VER_20_API
827 ABTI_SETUP_GLOBAL(NULL);
829 ABTI_UB_ASSERT(ABTI_initialized());
831 ABTI_SETUP_LOCAL_YTHREAD(&p_local_xstream, &p_ythread);
832 ABTI_CHECK_TRUE(!(p_ythread->thread.type & ABTI_THREAD_TYPE_PRIMARY),
835 ABTI_ythread_exit(p_local_xstream, p_ythread);
873 ABTI_UB_ASSERT(ABTI_initialized());
875 #ifdef ABT_CONFIG_DISABLE_CANCELLATION
878 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
879 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
880 ABTI_CHECK_TRUE(!(p_thread->type & ABTI_THREAD_TYPE_PRIMARY),
884 ABTI_thread_set_request(p_thread, ABTI_THREAD_REQ_CANCEL);
926 ABTI_UB_ASSERT(thread);
928 #ifndef ABT_CONFIG_ENABLE_VER_20_API
930 ABTI_SETUP_GLOBAL(NULL);
931 ABTI_ythread *p_self;
932 ABTI_SETUP_LOCAL_YTHREAD(NULL, &p_self);
933 *thread = ABTI_thread_get_handle(&p_self->thread);
935 ABTI_UB_ASSERT(ABTI_initialized());
936 ABTI_xstream *p_local_xstream;
937 ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
938 *thread = ABTI_thread_get_handle(p_local_xstream->p_thread);
980 #ifndef ABT_CONFIG_ENABLE_VER_20_API
981 ABTI_SETUP_GLOBAL(NULL);
982 ABTI_ythread *p_self;
983 ABTI_SETUP_LOCAL_YTHREAD(NULL, &p_self);
984 *
id = ABTI_thread_get_id(&p_self->thread);
986 ABTI_UB_ASSERT(ABTI_initialized());
987 ABTI_xstream *p_local_xstream;
988 ABTI_SETUP_LOCAL_XSTREAM(&p_local_xstream);
989 *
id = ABTI_thread_get_id(p_local_xstream->p_thread);
1024 ABTI_UB_ASSERT(ABTI_initialized());
1025 ABTI_UB_ASSERT(xstream);
1027 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1028 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
1030 *xstream = ABTI_xstream_get_handle(p_thread->p_last_xstream);
1068 ABTI_UB_ASSERT(ABTI_initialized());
1069 ABTI_UB_ASSERT(state);
1071 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1072 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
1111 ABTI_UB_ASSERT(ABTI_initialized());
1112 ABTI_UB_ASSERT(pool);
1114 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1115 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
1117 *pool = ABTI_pool_get_handle(p_thread->p_pool);
1154 ABTI_UB_ASSERT(ABTI_initialized());
1157 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1158 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
1159 *
id = (int)p_thread->p_pool->id;
1187 ABTI_UB_ASSERT(ABTI_initialized());
1188 ABTI_UB_ASSERT(unit);
1190 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1191 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
1192 *unit = p_thread->unit;
1231 ABTI_UB_ASSERT(ABTI_initialized());
1233 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1234 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
1235 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1236 ABTI_CHECK_NULL_POOL_PTR(p_pool);
1237 ABTI_global *p_global = ABTI_global_get_global();
1239 int abt_errno = ABTI_thread_set_associated_pool(p_global, p_thread, p_pool);
1240 ABTI_CHECK_ERROR(abt_errno);
1281 ABTI_UB_ASSERT(ABTI_initialized());
1283 ABTI_xstream *p_local_xstream;
1284 ABTI_ythread *p_cur_ythread;
1285 p_local_xstream = ABTI_local_get_xstream_or_null(ABTI_local_get_local());
1286 if (ABTI_IS_EXT_THREAD_ENABLED && p_local_xstream == NULL) {
1290 ABTI_thread_get_ythread_or_null(p_local_xstream->p_thread);
1295 ABTI_thread *p_tar_thread = ABTI_thread_get_ptr(thread);
1296 ABTI_CHECK_NULL_THREAD_PTR(p_tar_thread);
1297 ABTI_ythread *p_tar_ythread = ABTI_thread_get_ythread_or_null(p_tar_thread);
1298 ABTI_CHECK_NULL_YTHREAD_PTR(p_tar_ythread);
1300 ABTI_CHECK_TRUE(!(p_cur_ythread->thread.type & ABTI_THREAD_TYPE_MAIN_SCHED),
1302 ABTI_CHECK_TRUE(p_tar_ythread->thread.p_pool->deprecated_def.u_is_in_pool,
1304 ABTI_CHECK_TRUE(p_tar_ythread->thread.p_pool->deprecated_def.p_remove,
1312 if (!(p_tar_ythread->thread.p_pool->deprecated_def.u_is_in_pool(
1313 p_tar_ythread->thread.unit) ==
ABT_TRUE &&
1314 ABTD_atomic_acquire_load_int(&p_tar_ythread->thread.state) ==
1322 ABTI_pool_inc_num_blocked(p_cur_ythread->thread.p_pool);
1323 int abt_errno = ABTI_pool_remove(p_tar_ythread->thread.p_pool,
1324 p_tar_ythread->thread.unit);
1325 if (ABTI_IS_ERROR_CHECK_ENABLED && abt_errno !=
ABT_SUCCESS) {
1326 ABTI_pool_dec_num_blocked(p_cur_ythread->thread.p_pool);
1327 ABTI_HANDLE_ERROR(abt_errno);
1331 p_tar_ythread->thread.p_last_xstream = p_local_xstream;
1334 ABTI_ythread_thread_yield_to(&p_local_xstream, p_cur_ythread, p_tar_ythread,
1372 ABTI_UB_ASSERT(ABTI_initialized());
1374 ABTI_xstream *p_local_xstream;
1375 ABTI_ythread *p_ythread;
1376 #ifndef ABT_CONFIG_ENABLE_VER_20_API
1377 p_local_xstream = ABTI_local_get_xstream_or_null(ABTI_local_get_local());
1378 if (ABTI_IS_EXT_THREAD_ENABLED &&
ABTU_unlikely(p_local_xstream == NULL)) {
1381 p_ythread = ABTI_thread_get_ythread_or_null(p_local_xstream->p_thread);
1387 ABTI_SETUP_LOCAL_YTHREAD(&p_local_xstream, &p_ythread);
1390 ABTI_ythread_yield(&p_local_xstream, p_ythread,
1427 ABTI_UB_ASSERT(ABTI_initialized());
1429 ABTI_local *p_local = ABTI_local_get_local();
1431 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1432 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
1433 ABTI_ythread *p_ythread;
1436 #ifndef ABT_CONFIG_ENABLE_VER_20_API
1438 ABTI_CHECK_TRUE(ABTD_atomic_acquire_load_int(&p_ythread->thread.state) ==
1442 ABTI_UB_ASSERT(ABTD_atomic_acquire_load_int(&p_ythread->thread.state) ==
1446 ABTI_ythread_resume_and_push(p_local, p_ythread);
1503 ABTI_UB_ASSERT(ABTI_initialized());
1505 #ifndef ABT_CONFIG_DISABLE_MIGRATION
1506 ABTI_global *p_global;
1507 ABTI_SETUP_GLOBAL(&p_global);
1508 ABTI_local *p_local = ABTI_local_get_local();
1510 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1511 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
1512 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
1513 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
1514 ABTI_CHECK_TRUE(p_thread->type & ABTI_THREAD_TYPE_MIGRATABLE,
1516 ABTI_CHECK_TRUE(!(p_thread->type & ABTI_THREAD_TYPE_MAIN_SCHED),
1519 ABTI_sched *p_sched = p_xstream->p_main_sched;
1520 if (ABTI_IS_ERROR_CHECK_ENABLED) {
1522 for (p = 0; p < p_sched->num_pools; p++)
1523 ABTI_CHECK_TRUE(ABTI_pool_get_ptr(p_sched->pools[p]) !=
1528 ABTI_pool *p_pool = NULL;
1531 ABTI_sched_get_migration_pool(p_sched, p_thread->p_pool, &p_pool);
1532 ABTI_CHECK_ERROR(abt_errno);
1535 ABTI_CHECK_ERROR(abt_errno);
1591 ABTI_UB_ASSERT(ABTI_initialized());
1593 #ifndef ABT_CONFIG_DISABLE_MIGRATION
1594 ABTI_global *p_global;
1595 ABTI_SETUP_GLOBAL(&p_global);
1596 ABTI_local *p_local = ABTI_local_get_local();
1598 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1599 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
1600 ABTI_sched *p_sched = ABTI_sched_get_ptr(sched);
1601 ABTI_CHECK_NULL_SCHED_PTR(p_sched);
1602 ABTI_CHECK_TRUE(p_thread->type & ABTI_THREAD_TYPE_MIGRATABLE,
1604 ABTI_CHECK_TRUE(!(p_thread->type & ABTI_THREAD_TYPE_MAIN_SCHED),
1607 if (ABTI_IS_ERROR_CHECK_ENABLED) {
1609 for (p = 0; p < p_sched->num_pools; p++)
1610 ABTI_CHECK_TRUE(ABTI_pool_get_ptr(p_sched->pools[p]) !=
1618 ABTI_sched_get_migration_pool(p_sched, p_thread->p_pool, &p_pool);
1619 ABTI_CHECK_ERROR(abt_errno);
1622 ABTI_CHECK_ERROR(abt_errno);
1676 ABTI_UB_ASSERT(ABTI_initialized());
1678 #ifndef ABT_CONFIG_DISABLE_MIGRATION
1679 ABTI_global *p_global;
1680 ABTI_SETUP_GLOBAL(&p_global);
1681 ABTI_local *p_local = ABTI_local_get_local();
1683 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1684 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
1685 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1686 ABTI_CHECK_NULL_POOL_PTR(p_pool);
1687 ABTI_CHECK_TRUE(p_thread->type & ABTI_THREAD_TYPE_MIGRATABLE,
1689 ABTI_CHECK_TRUE(!(p_thread->type & ABTI_THREAD_TYPE_MAIN_SCHED),
1694 ABTI_CHECK_ERROR(abt_errno);
1755 ABTI_UB_ASSERT(ABTI_initialized());
1757 #ifndef ABT_CONFIG_DISABLE_MIGRATION
1759 ABTI_global *p_global;
1760 ABTI_SETUP_GLOBAL(&p_global);
1762 ABTI_local *p_local = ABTI_local_get_local();
1763 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1764 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
1765 ABTI_CHECK_TRUE(p_thread->type & ABTI_THREAD_TYPE_MIGRATABLE,
1767 ABTI_CHECK_TRUE(!(p_thread->type & ABTI_THREAD_TYPE_MAIN_SCHED),
1771 int i, num_xstreams, abt_errno;
1772 ABTI_xstream **xstreams;
1773 ABTD_spinlock_acquire(&p_global->xstream_list_lock);
1774 num_xstreams = p_global->num_xstreams;
1776 ABTU_malloc(
sizeof(ABTI_xstream *) * num_xstreams, (
void **)&xstreams);
1777 if (!(ABTI_IS_ERROR_CHECK_ENABLED && abt_errno !=
ABT_SUCCESS)) {
1778 ABTI_xstream *p_xstream = p_global->p_xstream_head;
1781 xstreams[i++] = p_xstream;
1782 p_xstream = p_xstream->p_next;
1785 ABTD_spinlock_release(&p_global->xstream_list_lock);
1786 ABTI_CHECK_ERROR(abt_errno);
1790 for (i = 0; i < num_xstreams; i++) {
1791 ABTI_xstream *p_xstream = xstreams[i];
1792 if (p_xstream == p_thread->p_last_xstream)
1794 if (ABTD_atomic_acquire_load_int(&p_xstream->state) !=
1798 ABTI_sched *p_sched = p_xstream->p_main_sched;
1801 for (p = 0; p < p_sched->num_pools; p++) {
1802 if (ABTI_pool_get_ptr(p_sched->pools[p]) != p_thread->p_pool) {
1810 ABTI_pool *p_pool = NULL;
1812 ABTI_sched_get_migration_pool(p_sched, p_thread->p_pool, &p_pool);
1868 void (*cb_func)(
ABT_thread thread,
void *cb_arg),
1871 ABTI_UB_ASSERT(ABTI_initialized());
1873 #ifndef ABT_CONFIG_DISABLE_MIGRATION
1874 ABTI_global *p_global;
1875 ABTI_SETUP_GLOBAL(&p_global);
1877 ABTI_local *p_local = ABTI_local_get_local();
1878 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1879 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
1881 ABTI_thread_mig_data *p_mig_data;
1883 ABTI_thread_get_mig_data(p_global, p_local, p_thread, &p_mig_data);
1884 ABTI_CHECK_ERROR(abt_errno);
1886 p_mig_data->f_migration_cb = cb_func;
1887 p_mig_data->p_migration_cb_arg = cb_arg;
1933 ABTI_UB_ASSERT(ABTI_initialized());
1934 ABTI_UB_ASSERT_BOOL(migratable);
1936 #ifndef ABT_CONFIG_DISABLE_MIGRATION
1937 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1938 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
1940 #ifndef ABT_CONFIG_ENABLE_VER_20_API
1941 if (p_thread->type &
1942 (ABTI_THREAD_TYPE_PRIMARY | ABTI_THREAD_TYPE_MAIN_SCHED))
1945 ABTI_CHECK_TRUE(!(p_thread->type &
1946 (ABTI_THREAD_TYPE_PRIMARY | ABTI_THREAD_TYPE_MAIN_SCHED)),
1951 p_thread->type |= ABTI_THREAD_TYPE_MIGRATABLE;
1953 p_thread->type &= ~ABTI_THREAD_TYPE_MIGRATABLE;
1993 ABTI_UB_ASSERT(ABTI_initialized());
1994 ABTI_UB_ASSERT(is_migratable);
1996 #ifndef ABT_CONFIG_DISABLE_MIGRATION
1997 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1998 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
2038 ABTI_UB_ASSERT(ABTI_initialized());
2039 ABTI_UB_ASSERT(is_primary);
2041 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
2042 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
2079 ABTI_UB_ASSERT(ABTI_initialized());
2080 ABTI_UB_ASSERT(is_unnamed);
2082 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
2083 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
2129 ABTI_UB_ASSERT(result);
2131 ABTI_thread *p_thread1 = ABTI_thread_get_ptr(thread1);
2132 ABTI_thread *p_thread2 = ABTI_thread_get_ptr(thread2);
2167 ABTI_UB_ASSERT(ABTI_initialized());
2168 ABTI_UB_ASSERT(stacksize);
2170 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
2171 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
2172 ABTI_ythread *p_ythread = ABTI_thread_get_ythread_or_null(p_thread);
2174 *stacksize = ABTD_ythread_context_get_stacksize(&p_ythread->ctx);
2209 ABTI_UB_ASSERT(ABTI_initialized());
2210 ABTI_UB_ASSERT(thread_id);
2212 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
2213 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
2215 *thread_id = ABTI_thread_get_id(p_thread);
2247 ABTI_UB_ASSERT(ABTI_initialized());
2249 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
2250 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
2252 p_thread->p_arg = arg;
2284 ABTI_UB_ASSERT(ABTI_initialized());
2285 ABTI_UB_ASSERT(arg);
2287 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
2288 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
2290 *arg = p_thread->p_arg;
2318 ABTI_UB_ASSERT(ABTI_initialized());
2319 ABTI_UB_ASSERT(thread_func);
2321 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
2322 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
2324 *thread_func = p_thread->f_thread;
2356 ABTI_UB_ASSERT(ABTI_initialized());
2358 ABTI_global *p_global;
2359 ABTI_SETUP_GLOBAL(&p_global);
2361 ABTI_local *p_local = ABTI_local_get_local();
2363 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
2364 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
2366 ABTI_key *p_key = ABTI_key_get_ptr(key);
2367 ABTI_CHECK_NULL_KEY_PTR(p_key);
2371 ABTI_ktable_set(p_global, p_local, &p_thread->p_keytable, p_key, value);
2372 ABTI_CHECK_ERROR(abt_errno);
2407 ABTI_UB_ASSERT(ABTI_initialized());
2408 ABTI_UB_ASSERT(value);
2410 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
2411 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
2413 ABTI_key *p_key = ABTI_key_get_ptr(key);
2414 ABTI_CHECK_NULL_KEY_PTR(p_key);
2417 *value = ABTI_ktable_get(&p_thread->p_keytable, p_key);
2455 ABTI_UB_ASSERT(ABTI_initialized());
2456 ABTI_UB_ASSERT(attr);
2458 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
2459 ABTI_CHECK_NULL_THREAD_PTR(p_thread);
2461 ABTI_thread_attr thread_attr, *p_attr;
2462 ABTI_ythread *p_ythread = ABTI_thread_get_ythread_or_null(p_thread);
2463 #ifndef ABT_CONFIG_ENABLE_VER_20_API
2468 void *p_stacktop = ABTD_ythread_context_get_stacktop(&p_ythread->ctx);
2469 size_t stacksize = ABTD_ythread_context_get_stacksize(&p_ythread->ctx);
2471 thread_attr.p_stack = (
void *)(((
char *)p_stacktop) - stacksize);
2473 thread_attr.p_stack = NULL;
2475 thread_attr.stacksize = stacksize;
2477 thread_attr.p_stack = NULL;
2478 thread_attr.stacksize = 0;
2480 #ifndef ABT_CONFIG_DISABLE_MIGRATION
2481 thread_attr.migratable =
2483 ABTI_thread_mig_data *p_mig_data =
2484 (ABTI_thread_mig_data *)ABTI_ktable_get(&p_thread->p_keytable,
2487 thread_attr.f_cb = p_mig_data->f_migration_cb;
2488 thread_attr.p_cb_arg = p_mig_data->p_migration_cb_arg;
2490 thread_attr.f_cb = NULL;
2491 thread_attr.p_cb_arg = NULL;
2494 int abt_errno = ABTI_thread_attr_dup(&thread_attr, &p_attr);
2495 ABTI_CHECK_ERROR(abt_errno);
2497 *attr = ABTI_thread_attr_get_handle(p_attr);
2505 ABTU_ret_err int ABTI_thread_revive(ABTI_global *p_global, ABTI_local *p_local,
2507 void (*thread_func)(
void *),
void *arg,
2508 ABTI_thread *p_thread)
2510 ABTI_ASSERT(ABTD_atomic_relaxed_load_int(&p_thread->state) ==
2512 int abt_errno =
thread_revive(p_global, p_local, p_pool, thread_func, arg,
2514 ABTI_CHECK_ERROR(abt_errno);
2518 ABTU_ret_err int ABTI_ythread_create_primary(ABTI_global *p_global,
2519 ABTI_local *p_local,
2520 ABTI_xstream *p_xstream,
2521 ABTI_ythread **p_ythread)
2523 ABTI_thread_attr attr;
2527 p_pool = ABTI_pool_get_ptr(p_xstream->p_main_sched->pools[0]);
2531 ABTI_thread_attr_init(&attr, NULL, 0,
ABT_FALSE);
2538 ABTI_THREAD_TYPE_YIELDABLE | ABTI_THREAD_TYPE_PRIMARY,
2540 ABTI_CHECK_ERROR(abt_errno);
2544 ABTU_ret_err int ABTI_ythread_create_root(ABTI_global *p_global,
2545 ABTI_local *p_local,
2546 ABTI_xstream *p_xstream,
2547 ABTI_ythread **pp_root_ythread)
2549 ABTI_thread_attr attr;
2551 if (p_xstream->type == ABTI_XSTREAM_TYPE_PRIMARY) {
2553 ABTI_thread_attr_init(&attr, NULL, p_global->sched_stacksize,
2557 ABTI_thread_attr_init(&attr, NULL, 0,
ABT_FALSE);
2559 const ABTI_thread_type thread_type = ABTI_THREAD_TYPE_YIELDABLE |
2560 ABTI_THREAD_TYPE_ROOT |
2561 ABTI_THREAD_TYPE_NAMED;
2562 ABTI_ythread *p_root_ythread;
2566 ABTI_CHECK_ERROR(abt_errno);
2567 *pp_root_ythread = p_root_ythread;
2571 ABTU_ret_err int ABTI_ythread_create_main_sched(ABTI_global *p_global,
2572 ABTI_local *p_local,
2573 ABTI_xstream *p_xstream,
2574 ABTI_sched *p_sched)
2576 ABTI_thread_attr attr;
2579 ABTI_thread_attr_init(&attr, NULL, p_global->sched_stacksize,
ABT_FALSE);
2583 ABTI_THREAD_TYPE_YIELDABLE |
2584 ABTI_THREAD_TYPE_MAIN_SCHED | ABTI_THREAD_TYPE_NAMED,
2586 ABTI_CHECK_ERROR(abt_errno);
2591 ABTU_ret_err int ABTI_ythread_create_sched(ABTI_global *p_global,
2592 ABTI_local *p_local,
2594 ABTI_sched *p_sched)
2596 ABTI_thread_attr attr;
2599 ABTI_thread_attr_init(&attr, NULL, p_global->sched_stacksize,
ABT_FALSE);
2601 (
void (*)(
void *))p_sched->run,
2602 (
void *)ABTI_sched_get_handle(p_sched),
2603 &attr, ABTI_THREAD_TYPE_YIELDABLE, p_sched,
2605 ABTI_CHECK_ERROR(abt_errno);
2609 void ABTI_thread_join(ABTI_local **pp_local, ABTI_thread *p_thread)
2614 void ABTI_thread_free(ABTI_global *p_global, ABTI_local *p_local,
2615 ABTI_thread *p_thread)
2620 void ABTI_ythread_free_primary(ABTI_global *p_global, ABTI_local *p_local,
2621 ABTI_ythread *p_ythread)
2623 ABTI_thread *p_thread = &p_ythread->thread;
2627 void ABTI_ythread_free_root(ABTI_global *p_global, ABTI_local *p_local,
2628 ABTI_ythread *p_ythread)
2633 ABTU_ret_err int ABTI_thread_get_mig_data(ABTI_global *p_global,
2634 ABTI_local *p_local,
2635 ABTI_thread *p_thread,
2636 ABTI_thread_mig_data **pp_mig_data)
2638 ABTI_thread_mig_data *p_mig_data =
2639 (ABTI_thread_mig_data *)ABTI_ktable_get(&p_thread->p_keytable,
2644 ABTU_calloc(1,
sizeof(ABTI_thread_mig_data), (
void **)&p_mig_data);
2645 ABTI_CHECK_ERROR(abt_errno);
2646 abt_errno = ABTI_ktable_set(p_global, p_local, &p_thread->p_keytable,
2648 if (ABTI_IS_ERROR_CHECK_ENABLED && abt_errno !=
ABT_SUCCESS) {
2654 *pp_mig_data = p_mig_data;
2658 void ABTI_thread_handle_request_cancel(ABTI_global *p_global,
2659 ABTI_xstream *p_local_xstream,
2660 ABTI_thread *p_thread)
2662 ABTI_ythread *p_ythread = ABTI_thread_get_ythread_or_null(p_thread);
2666 ABTI_ythread_resume_joiner(p_local_xstream, p_ythread);
2668 ABTI_event_thread_cancel(p_local_xstream, p_thread);
2669 ABTI_thread_terminate(p_global, p_local_xstream, p_thread);
2672 ABTU_ret_err int ABTI_thread_handle_request_migrate(ABTI_global *p_global,
2673 ABTI_local *p_local,
2674 ABTI_thread *p_thread)
2678 ABTI_thread_mig_data *p_mig_data;
2680 ABTI_thread_get_mig_data(p_global, p_local, p_thread, &p_mig_data);
2681 ABTI_CHECK_ERROR(abt_errno);
2685 ABTD_atomic_relaxed_load_ptr(&p_mig_data->p_migration_pool);
2688 abt_errno = ABTI_thread_set_associated_pool(p_global, p_thread, p_pool);
2689 ABTI_CHECK_ERROR(abt_errno);
2691 if (p_mig_data->f_migration_cb) {
2692 ABT_thread thread = ABTI_thread_get_handle(p_thread);
2693 p_mig_data->f_migration_cb(thread, p_mig_data->p_migration_cb_arg);
2696 ABTI_thread_unset_request(p_thread, ABTI_THREAD_REQ_MIGRATE);
2700 void ABTI_thread_print(ABTI_thread *p_thread, FILE *p_os,
int indent)
2702 if (p_thread == NULL) {
2703 fprintf(p_os,
"%*s== NULL thread ==\n", indent,
"");
2705 ABTI_xstream *p_xstream = p_thread->p_last_xstream;
2706 int xstream_rank = p_xstream ? p_xstream->rank : 0;
2707 const char *type, *yieldable, *state, *named, *migratable;
2709 if (p_thread->type & ABTI_THREAD_TYPE_PRIMARY) {
2711 }
else if (p_thread->type & ABTI_THREAD_TYPE_MAIN_SCHED) {
2712 type =
"MAIN_SCHED";
2713 }
else if (p_thread->type & ABTI_THREAD_TYPE_ROOT) {
2718 if (p_thread->type & ABTI_THREAD_TYPE_YIELDABLE) {
2723 if (p_thread->type & ABTI_THREAD_TYPE_NAMED) {
2728 if (p_thread->type & ABTI_THREAD_TYPE_MIGRATABLE) {
2733 switch (ABTD_atomic_acquire_load_int(&p_thread->state)) {
2744 state =
"TERMINATED";
2750 ABTI_thread_mig_data *p_mig_data =
2751 (ABTI_thread_mig_data *)ABTI_ktable_get(&p_thread->p_keytable,
2753 void *p_migration_cb_arg =
2754 p_mig_data ? p_mig_data->p_migration_cb_arg : NULL;
2757 "%*s== Thread (%p) ==\n"
2758 "%*sid : %" PRIu64
"\n"
2760 "%*syieldable : %s\n"
2762 "%*slast_ES : %p (%d)\n"
2767 "%*smigratable : %s\n"
2768 "%*srequest : 0x%x\n"
2769 "%*smig_cb_arg : %p\n"
2770 "%*skeytable : %p\n",
2771 indent,
"", (
void *)p_thread, indent,
"",
2772 ABTI_thread_get_id(p_thread), indent,
"", type, indent,
"",
2773 yieldable, indent,
"", state, indent,
"", (
void *)p_xstream,
2774 xstream_rank, indent,
"", (
void *)p_thread->p_parent, indent,
2775 "", p_thread->p_arg, indent,
"", (
void *)p_thread->p_pool,
2776 indent,
"", named, indent,
"", migratable, indent,
"",
2777 ABTD_atomic_acquire_load_uint32(&p_thread->request), indent,
"",
2778 p_migration_cb_arg, indent,
"",
2779 ABTD_atomic_acquire_load_ptr(&p_thread->p_keytable));
2781 if (p_thread->type & ABTI_THREAD_TYPE_YIELDABLE) {
2782 ABTI_ythread *p_ythread = ABTI_thread_get_ythread(p_thread);
2784 "%*sstacktop : %p\n"
2785 "%*sstacksize : %zu\n",
2787 ABTD_ythread_context_get_stacktop(&p_ythread->ctx), indent,
2788 "", ABTD_ythread_context_get_stacksize(&p_ythread->ctx));
2795 ABTD_ATOMIC_UINT64_STATIC_INITIALIZER(0);
2796 void ABTI_thread_reset_id(
void)
2798 ABTD_atomic_release_store_uint64(&
g_thread_id, 0);
2801 ABT_unit_id ABTI_thread_get_id(ABTI_thread *p_thread)
2803 if (p_thread == NULL)
2804 return ABTI_THREAD_INIT_ID;
2806 if (p_thread->id == ABTI_THREAD_INIT_ID) {
2809 return p_thread->id;
2817 ythread_create(ABTI_global *p_global, ABTI_local *p_local, ABTI_pool *p_pool,
2818 void (*thread_func)(
void *),
void *arg, ABTI_thread_attr *p_attr,
2819 ABTI_thread_type thread_type, ABTI_sched *p_sched,
2823 ABTI_ythread *p_newthread;
2824 ABTI_ktable *p_keytable = NULL;
2829 ABTI_mem_alloc_ythread_default(p_global, p_local, &p_newthread);
2830 ABTI_CHECK_ERROR(abt_errno);
2831 #ifndef ABT_CONFIG_DISABLE_MIGRATION
2832 thread_type |= ABTI_THREAD_TYPE_MIGRATABLE;
2848 const size_t default_stacksize = p_global->thread_stacksize;
2849 const size_t stacksize = p_attr->stacksize;
2850 if (
ABTU_likely(stacksize == default_stacksize)) {
2853 ABTI_mem_alloc_ythread_mempool_desc_stack(p_global, p_local,
2856 }
else if (stacksize != 0) {
2859 ABTI_mem_alloc_ythread_malloc_desc_stack(p_global,
2865 ABTI_mem_alloc_ythread_mempool_desc(p_global, p_local, 0,
2866 NULL, &p_newthread);
2868 ABTI_CHECK_ERROR(abt_errno);
2872 (
void *)((
char *)(p_attr->p_stack) + p_attr->stacksize);
2874 ABTI_mem_alloc_ythread_mempool_desc(p_global, p_local,
2876 p_stacktop, &p_newthread);
2877 ABTI_CHECK_ERROR(abt_errno);
2879 #ifndef ABT_CONFIG_DISABLE_MIGRATION
2880 thread_type |= p_attr->migratable ? ABTI_THREAD_TYPE_MIGRATABLE : 0;
2882 ABTI_thread_mig_data *p_mig_data;
2883 abt_errno =
ABTU_calloc(1,
sizeof(ABTI_thread_mig_data),
2884 (
void **)&p_mig_data);
2885 if (ABTI_IS_ERROR_CHECK_ENABLED &&
2887 ABTI_mem_free_thread(p_global, p_local, &p_newthread->thread);
2890 p_mig_data->f_migration_cb = p_attr->f_cb;
2891 p_mig_data->p_migration_cb_arg = p_attr->p_cb_arg;
2892 abt_errno = ABTI_ktable_set_unsafe(p_global, p_local, &p_keytable,
2894 (
void *)p_mig_data);
2895 if (ABTI_IS_ERROR_CHECK_ENABLED &&
2898 ABTI_ktable_free(p_global, p_local, p_keytable);
2900 ABTI_mem_free_thread(p_global, p_local, &p_newthread->thread);
2907 p_newthread->thread.f_thread = thread_func;
2908 p_newthread->thread.p_arg = arg;
2910 ABTD_atomic_release_store_int(&p_newthread->thread.state,
2912 ABTD_atomic_release_store_uint32(&p_newthread->thread.request, 0);
2913 p_newthread->thread.p_last_xstream = NULL;
2914 p_newthread->thread.p_parent = NULL;
2915 p_newthread->thread.type |= thread_type;
2916 p_newthread->thread.id = ABTI_THREAD_INIT_ID;
2917 if (p_sched && !(thread_type & (ABTI_THREAD_TYPE_PRIMARY |
2918 ABTI_THREAD_TYPE_MAIN_SCHED))) {
2920 abt_errno = ABTI_ktable_set_unsafe(p_global, p_local, &p_keytable,
2922 if (ABTI_IS_ERROR_CHECK_ENABLED &&
2925 ABTI_ktable_free(p_global, p_local, p_keytable);
2926 ABTI_mem_free_thread(p_global, p_local, &p_newthread->thread);
2930 ABTD_atomic_relaxed_store_ptr(&p_newthread->thread.p_keytable, p_keytable);
2935 ABTI_thread_init_pool(p_global, &p_newthread->thread, p_pool);
2936 if (ABTI_IS_ERROR_CHECK_ENABLED &&
2939 ABTI_ktable_free(p_global, p_local, p_keytable);
2940 ABTI_mem_free_thread(p_global, p_local, &p_newthread->thread);
2944 ABTI_event_thread_create(p_local, &p_newthread->thread,
2945 ABTI_local_get_xstream_or_null(p_local)
2946 ? ABTI_local_get_xstream(p_local)->p_thread
2951 ABTI_pool_push(p_pool, p_newthread->thread.unit,
2956 p_newthread->thread.p_pool = p_pool;
2959 ABTI_event_thread_create(p_local, &p_newthread->thread,
2960 ABTI_local_get_xstream_or_null(p_local)
2961 ? ABTI_local_get_xstream(p_local)->p_thread
2967 *pp_newthread = p_newthread;
2972 thread_revive(ABTI_global *p_global, ABTI_local *p_local, ABTI_pool *p_pool,
2973 void (*thread_func)(
void *),
void *arg,
2976 ABTI_UB_ASSERT(ABTD_atomic_relaxed_load_int(&p_thread->state) ==
2979 int abt_errno = ABTI_thread_set_associated_pool(p_global, p_thread, p_pool);
2980 ABTI_CHECK_ERROR(abt_errno);
2982 p_thread->f_thread = thread_func;
2983 p_thread->p_arg = arg;
2986 ABTD_atomic_relaxed_store_uint32(&p_thread->request, 0);
2987 p_thread->p_last_xstream = NULL;
2988 p_thread->p_parent = NULL;
2990 ABTI_ythread *p_ythread = ABTI_thread_get_ythread_or_null(p_thread);
2993 ABTD_ythread_context_reinit(&p_ythread->ctx);
2997 ABTI_event_thread_revive(p_local, p_thread,
2998 ABTI_local_get_xstream_or_null(p_local)
2999 ? ABTI_local_get_xstream(p_local)->p_thread
3005 ABTI_pool_push(p_pool, p_thread->unit,
3011 #ifndef ABT_CONFIG_DISABLE_MIGRATION
3013 ABTI_local *p_local,
3014 ABTI_thread *p_thread,
3023 ABTI_thread_mig_data *p_mig_data;
3025 ABTI_thread_get_mig_data(p_global, p_local, p_thread, &p_mig_data);
3026 ABTI_CHECK_ERROR(abt_errno);
3028 ABTD_atomic_relaxed_store_ptr(&p_mig_data->p_migration_pool,
3030 ABTI_thread_set_request(p_thread, ABTI_THREAD_REQ_MIGRATE);
3035 static inline void thread_free(ABTI_global *p_global, ABTI_local *p_local,
3036 ABTI_thread *p_thread,
ABT_bool free_unit)
3039 ABTI_event_thread_free(p_local, p_thread,
3040 ABTI_local_get_xstream_or_null(p_local)
3041 ? ABTI_local_get_xstream(p_local)->p_thread
3046 ABTI_thread_unset_associated_pool(p_global, p_thread);
3050 ABTI_ktable *p_ktable = ABTD_atomic_acquire_load_ptr(&p_thread->p_keytable);
3052 ABTI_ASSERT(p_ktable != ABTI_KTABLE_LOCKED);
3054 ABTI_ktable_free(p_global, p_local, p_ktable);
3058 ABTI_mem_free_thread(p_global, p_local, p_thread);
3065 ABTI_sched *p_sched = (ABTI_sched *)p_value;
3066 p_sched->used = ABTI_SCHED_NOT_USED;
3067 if (p_sched->automatic ==
ABT_TRUE) {
3068 ABTI_global *p_global = ABTI_global_get_global();
3069 p_sched->p_ythread = NULL;
3070 ABTI_sched_free(p_global, ABTI_local_get_local_uninlined(), p_sched,
3075 p_sched->p_ythread = NULL;
3081 ABTI_thread_mig_data *p_mig_data = (ABTI_thread_mig_data *)p_value;
3087 while (ABTD_atomic_acquire_load_int(&p_thread->state) !=
3089 ABTD_atomic_pause();
3091 ABTI_event_thread_join(NULL, p_thread, NULL);
3094 #ifndef ABT_CONFIG_ACTIVE_WAIT_POLICY
3097 ABTI_ythread *p_ythread = ABTI_thread_get_ythread_or_null(p_thread);
3100 uint32_t req = ABTD_atomic_fetch_or_uint32(&p_ythread->thread.request,
3101 ABTI_THREAD_REQ_JOIN);
3102 if (!(req & ABTI_THREAD_REQ_JOIN)) {
3103 ABTD_futex_single futex;
3104 ABTD_futex_single_init(&futex);
3105 ABTI_ythread dummy_ythread;
3106 dummy_ythread.thread.type = ABTI_THREAD_TYPE_EXT;
3108 dummy_ythread.thread.p_arg = &futex;
3109 ABTD_atomic_release_store_ythread_context_ptr(&p_ythread->ctx
3111 &dummy_ythread.ctx);
3112 ABTD_futex_suspend(&futex);
3126 ABTI_ythread *p_self,
3127 ABTI_thread *p_thread)
3129 while (ABTD_atomic_acquire_load_int(&p_thread->state) !=
3131 ABTI_ythread_yield(pp_local_xstream, p_self,
3132 ABTI_YTHREAD_YIELD_KIND_YIELD_LOOP,
3135 ABTI_event_thread_join(ABTI_xstream_get_local(*pp_local_xstream), p_thread,
3139 static inline void thread_join(ABTI_local **pp_local, ABTI_thread *p_thread)
3141 if (ABTD_atomic_acquire_load_int(&p_thread->state) ==
3143 ABTI_event_thread_join(*pp_local, p_thread,
3144 ABTI_local_get_xstream_or_null(*pp_local)
3145 ? ABTI_local_get_xstream(*pp_local)->p_thread
3150 ABTI_ASSERT(!(p_thread->type & ABTI_THREAD_TYPE_PRIMARY));
3152 ABTI_xstream *p_local_xstream = ABTI_local_get_xstream_or_null(*pp_local);
3153 if (ABTI_IS_EXT_THREAD_ENABLED && !p_local_xstream) {
3154 #ifdef ABT_CONFIG_ACTIVE_WAIT_POLICY
3162 ABTI_thread *p_self_thread = p_local_xstream->p_thread;
3164 ABTI_ythread *p_self = ABTI_thread_get_ythread_or_null(p_self_thread);
3166 #ifdef ABT_CONFIG_ACTIVE_WAIT_POLICY
3175 ABTI_ASSERT(p_thread != p_self_thread);
3177 ABTI_ythread *p_ythread = ABTI_thread_get_ythread_or_null(p_thread);
3180 *pp_local = ABTI_xstream_get_local(p_local_xstream);
3187 uint32_t req = ABTD_atomic_fetch_or_uint32(&p_ythread->thread.request,
3188 ABTI_THREAD_REQ_JOIN);
3189 if (req & ABTI_THREAD_REQ_JOIN) {
3192 *pp_local = ABTI_xstream_get_local(p_local_xstream);
3195 ABTI_ythread_suspend_join(&p_local_xstream, p_self, p_ythread,
3202 *pp_local = ABTI_xstream_get_local(p_local_xstream);
3210 ABTI_global *p_global = ABTI_global_get_global();
3211 ABTI_local *p_local = ABTI_local_get_local();
3212 ABTI_xstream *p_local_xstream = ABTI_local_get_xstream(p_local);
3213 ABTI_ASSERT(ABTD_atomic_relaxed_load_int(&p_local_xstream->state) ==
3216 ABTI_ythread *p_root_ythread = p_local_xstream->p_root_ythread;
3217 p_local_xstream->p_thread = &p_root_ythread->thread;
3218 ABTI_pool *p_root_pool = p_local_xstream->p_root_pool;
3224 ABTI_xstream *p_xstream = p_local_xstream;
3225 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
3226 ABTI_ythread_schedule(p_global, &p_xstream, p_thread);
3228 ABTI_ASSERT(p_xstream == p_local_xstream);
3230 }
while (ABTD_atomic_acquire_load_int(
3231 &p_local_xstream->p_main_sched->p_ythread->thread.state) !=
3236 ABTD_atomic_release_store_int(&p_local_xstream->state,
3239 if (p_local_xstream->type == ABTI_XSTREAM_TYPE_PRIMARY) {
3241 ABTI_ythread_exit_to_primary(p_global, p_local_xstream, p_root_ythread);
3247 ABTI_local *p_local = ABTI_local_get_local();
3248 ABTI_xstream *p_local_xstream = ABTI_local_get_xstream(p_local);
3252 ABTI_sched *p_sched = p_local_xstream->p_main_sched;
3253 ABTI_ASSERT(p_local_xstream->p_thread == &p_sched->p_ythread->thread);
3255 p_sched->run(ABTI_sched_get_handle(p_sched));
3258 ABTI_ASSERT(p_local == ABTI_local_get_local_uninlined());
3261 if (ABTD_atomic_relaxed_load_uint32(&p_sched->request) &
3262 ABTI_SCHED_REQ_REPLACE) {
3263 ABTI_ythread *p_waiter = p_sched->p_replace_waiter;
3264 ABTI_sched *p_new_sched = p_sched->p_replace_sched;
3266 p_new_sched->used = ABTI_SCHED_MAIN;
3269 p_new_sched->p_ythread = p_sched->p_ythread;
3270 p_local_xstream->p_main_sched = p_new_sched;
3273 p_sched->p_ythread = NULL;
3274 ABTI_sched_discard_and_free(ABTI_global_get_global(), p_local,
3278 p_sched = p_new_sched;
3280 ABTI_ythread_resume_and_push(p_local, p_waiter);
3282 ABTI_ASSERT(p_sched == p_local_xstream->p_main_sched);
3283 uint32_t request = ABTD_atomic_acquire_load_uint32(
3284 &p_sched->p_ythread->thread.request);
3288 if (request & ABTI_THREAD_REQ_CANCEL)
3293 if ((ABTD_atomic_relaxed_load_uint32(&p_sched->request) &
3294 ABTI_SCHED_REQ_FINISH) &&
3295 !ABTI_sched_has_unit(p_sched)) {