10 const ABTI_pool_optional_def *p_optional_def,
11 const ABTI_pool_deprecated_def *p_deprecated_def,
12 const ABTI_pool_old_def *p_old_def, ABTI_pool_config *p_config,
16 ABTI_pool_old_def *p_old_def,
17 ABTI_pool_required_def *p_required_def,
18 ABTI_pool_optional_def *p_optional_def,
19 ABTI_pool_deprecated_def *p_deprecated_def);
23 size_t len,
size_t *num,
114 ABTI_UB_ASSERT(ABTI_initialized());
115 ABTI_UB_ASSERT(newpool);
117 #ifndef ABT_CONFIG_ENABLE_VER_20_API
122 ABTI_pool_required_def required_def, *p_required_def;
123 ABTI_pool_optional_def optional_def, *p_optional_def;
124 ABTI_pool_deprecated_def deprecated_def, *p_deprecated_def;
125 ABTI_pool_old_def old_def, *p_old_def;
127 if (ABTI_pool_user_def_is_new(def)) {
130 ABTI_pool_user_def *p_def = ABTI_pool_user_def_get_ptr(def);
131 ABTI_CHECK_NULL_POOL_USER_DEF_PTR(p_def);
132 p_required_def = &p_def->required_def;
133 p_optional_def = &p_def->optional_def;
134 p_deprecated_def = NULL;
139 ABTI_UB_ASSERT(def->
u_free);
141 ABTI_UB_ASSERT(def->
p_push);
142 ABTI_UB_ASSERT(def->
p_pop);
145 &optional_def, &deprecated_def);
146 p_required_def = &required_def;
147 p_optional_def = &optional_def;
148 p_deprecated_def = &deprecated_def;
149 p_old_def = &old_def;
152 ABTI_pool *p_newpool;
153 ABTI_pool_config *p_config = ABTI_pool_config_get_ptr(config);
156 pool_create(access, p_required_def, p_optional_def, p_deprecated_def,
157 p_old_def, p_config, def_automatic,
ABT_FALSE, &p_newpool);
158 ABTI_CHECK_ERROR(abt_errno);
160 *newpool = ABTI_pool_get_handle(p_newpool);
224 ABTI_UB_ASSERT(ABTI_initialized());
225 ABTI_UB_ASSERT_BOOL(automatic);
226 ABTI_UB_ASSERT(newpool);
228 #ifndef ABT_CONFIG_ENABLE_VER_20_API
232 ABTI_pool *p_newpool;
233 int abt_errno = ABTI_pool_create_basic(kind, access, automatic, &p_newpool);
234 ABTI_CHECK_ERROR(abt_errno);
236 *newpool = ABTI_pool_get_handle(p_newpool);
271 ABTI_UB_ASSERT(ABTI_initialized());
272 ABTI_UB_ASSERT(pool);
275 ABTI_pool *p_pool = ABTI_pool_get_ptr(h_pool);
276 ABTI_CHECK_NULL_POOL_PTR(p_pool);
277 ABTI_UB_ASSERT(ABTI_pool_is_empty(p_pool));
279 ABTI_pool_free(p_pool);
309 ABTI_UB_ASSERT(ABTI_initialized());
310 ABTI_UB_ASSERT(access);
312 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
313 ABTI_CHECK_NULL_POOL_PTR(p_pool);
315 *access = p_pool->access;
344 ABTI_UB_ASSERT(ABTI_initialized());
345 ABTI_UB_ASSERT(is_empty);
347 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
348 ABTI_CHECK_NULL_POOL_PTR(p_pool);
350 *is_empty = ABTI_pool_is_empty(p_pool);
394 ABTI_UB_ASSERT(ABTI_initialized());
395 ABTI_UB_ASSERT(size);
397 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
398 ABTI_CHECK_NULL_POOL_PTR(p_pool);
399 ABTI_CHECK_TRUE(p_pool->optional_def.p_get_size,
ABT_ERR_POOL);
401 *size = ABTI_pool_get_total_size(p_pool);
442 ABTI_UB_ASSERT(ABTI_initialized());
443 ABTI_UB_ASSERT(size);
445 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
446 ABTI_CHECK_NULL_POOL_PTR(p_pool);
447 ABTI_CHECK_TRUE(p_pool->optional_def.p_get_size,
ABT_ERR_POOL);
449 *size = ABTI_pool_get_size(p_pool);
814 ABTI_UB_ASSERT(ABTI_initialized());
815 ABTI_UB_ASSERT(print_fn);
817 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
818 ABTI_CHECK_NULL_POOL_PTR(p_pool);
819 ABTI_CHECK_TRUE(p_pool->optional_def.p_print_all,
ABT_ERR_POOL);
821 p_pool->optional_def.p_print_all(pool, arg, print_fn);
872 ABTI_UB_ASSERT(ABTI_initialized());
873 ABTI_UB_ASSERT(p_unit);
875 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
876 ABTI_CHECK_NULL_POOL_PTR(p_pool);
880 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
881 *p_unit = p_thread->unit;
939 ABTI_UB_ASSERT(ABTI_initialized());
940 ABTI_UB_ASSERT(p_unit);
942 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
943 ABTI_CHECK_NULL_POOL_PTR(p_pool);
944 ABTI_CHECK_TRUE(p_pool->optional_def.p_pop_wait,
ABT_ERR_POOL);
949 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
950 *p_unit = p_thread->unit;
1013 ABTI_UB_ASSERT(ABTI_initialized());
1014 ABTI_UB_ASSERT(p_unit);
1016 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1017 ABTI_CHECK_NULL_POOL_PTR(p_pool);
1018 ABTI_CHECK_TRUE(p_pool->deprecated_def.p_pop_timedwait,
ABT_ERR_POOL);
1020 ABT_thread thread = ABTI_pool_pop_timedwait(p_pool, abstime_secs);
1022 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1023 *p_unit = p_thread->unit;
1071 ABTI_UB_ASSERT(ABTI_initialized());
1073 ABTI_global *p_global = ABTI_global_get_global();
1074 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1075 ABTI_CHECK_NULL_POOL_PTR(p_pool);
1079 ABTI_thread *p_thread;
1081 ABTI_unit_set_associated_pool(p_global, unit, p_pool, &p_thread);
1082 ABTI_CHECK_ERROR(abt_errno);
1131 ABTI_UB_ASSERT(ABTI_initialized());
1133 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1134 ABTI_CHECK_NULL_POOL_PTR(p_pool);
1135 ABTI_CHECK_TRUE(p_pool->deprecated_def.p_remove,
ABT_ERR_POOL);
1139 int abt_errno = ABTI_pool_remove(p_pool, unit);
1140 ABTI_CHECK_ERROR(abt_errno);
1190 ABTI_UB_ASSERT(ABTI_initialized());
1191 ABTI_UB_ASSERT(print_fn);
1193 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1194 ABTI_CHECK_NULL_POOL_PTR(p_pool);
1195 ABTI_CHECK_TRUE(p_pool->optional_def.p_print_all,
ABT_ERR_POOL);
1198 p_pool->optional_def.p_print_all(pool, (
void *)&func_arg,
1227 ABTI_UB_ASSERT(ABTI_initialized());
1229 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1230 ABTI_CHECK_NULL_POOL_PTR(p_pool);
1232 p_pool->data = data;
1262 ABTI_UB_ASSERT(ABTI_initialized());
1263 ABTI_UB_ASSERT(data);
1265 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1266 ABTI_CHECK_NULL_POOL_PTR(p_pool);
1268 *data = p_pool->data;
1317 ABTI_UB_ASSERT(ABTI_initialized());
1319 ABTI_local *p_local = ABTI_local_get_local();
1321 ABTI_global *p_global;
1322 ABTI_SETUP_GLOBAL(&p_global);
1324 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1325 ABTI_CHECK_NULL_POOL_PTR(p_pool);
1327 ABTI_sched *p_sched = ABTI_sched_get_ptr(sched);
1328 ABTI_CHECK_NULL_SCHED_PTR(p_sched);
1331 #ifndef ABT_CONFIG_ENABLE_VER_20_API
1334 ABTI_UB_ASSERT(p_sched->used == ABTI_SCHED_NOT_USED);
1336 p_sched->used = ABTI_SCHED_IN_POOL;
1338 #ifndef ABT_CONFIG_ENABLE_VER_20_API
1343 ABTI_ythread_create_sched(p_global, p_local, p_pool, p_sched);
1345 p_sched->used = ABTI_SCHED_NOT_USED;
1346 ABTI_HANDLE_ERROR(abt_errno);
1374 ABTI_UB_ASSERT(ABTI_initialized());
1377 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1378 ABTI_CHECK_NULL_POOL_PTR(p_pool);
1380 *
id = (int)p_pool->id;
1391 ABTI_pool **pp_newpool)
1401 ABTI_pool_required_def required_def;
1402 ABTI_pool_optional_def optional_def;
1403 ABTI_pool_deprecated_def deprecated_def;
1406 abt_errno = ABTI_pool_get_fifo_def(access, &required_def,
1407 &optional_def, &deprecated_def);
1411 ABTI_pool_get_fifo_wait_def(access, &required_def,
1412 &optional_def, &deprecated_def);
1416 ABTI_pool_get_randws_def(access, &required_def, &optional_def,
1423 ABTI_CHECK_ERROR(abt_errno);
1426 pool_create(access, &required_def, &optional_def, &deprecated_def, NULL,
1427 NULL, automatic,
ABT_TRUE, pp_newpool);
1428 ABTI_CHECK_ERROR(abt_errno);
1432 void ABTI_pool_free(ABTI_pool *p_pool)
1434 ABT_pool h_pool = ABTI_pool_get_handle(p_pool);
1435 if (p_pool->optional_def.p_free) {
1436 p_pool->optional_def.p_free(h_pool);
1441 ABT_thread ABTI_pool_pop_timedwait(ABTI_pool *p_pool,
double abstime_secs)
1443 ABTI_UB_ASSERT(p_pool->deprecated_def.p_pop_timedwait);
1445 p_pool->deprecated_def.p_pop_timedwait(ABTI_pool_get_handle(p_pool),
1450 ABTI_thread *p_thread =
1451 ABTI_unit_get_thread(ABTI_global_get_global(), unit);
1452 ABT_thread thread = ABTI_thread_get_handle(p_thread);
1458 void ABTI_pool_print(ABTI_pool *p_pool, FILE *p_os,
int indent)
1460 if (p_pool == NULL) {
1461 fprintf(p_os,
"%*s== NULL POOL ==\n", indent,
"");
1465 switch (p_pool->access) {
1487 "%*s== POOL (%p) ==\n"
1488 "%*sid : %" PRIu64
"\n"
1490 "%*sautomatic : %s\n"
1491 "%*snum_scheds : %d\n"
1492 "%*sis_empty : %s\n"
1494 "%*snum_blocked : %d\n"
1496 indent,
"", (
void *)p_pool, indent,
"", p_pool->id, indent,
"",
1498 (p_pool->automatic ==
ABT_TRUE) ?
"TRUE" :
"FALSE", indent,
"",
1499 ABTD_atomic_acquire_load_int32(&p_pool->num_scheds), indent,
"",
1500 (ABTI_pool_is_empty(p_pool) ?
"TRUE" :
"FALSE"), indent,
"",
1501 (p_pool->optional_def.p_get_size ? ABTI_pool_get_size(p_pool)
1504 ABTD_atomic_acquire_load_int32(&p_pool->num_blocked), indent,
1510 static ABTD_atomic_uint64
g_pool_id = ABTD_ATOMIC_UINT64_STATIC_INITIALIZER(0);
1511 void ABTI_pool_reset_id(
void)
1513 ABTD_atomic_release_store_uint64(&
g_pool_id, 0);
1522 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1523 return p_pool->old_def.u_create_from_thread(thread);
1528 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1529 p_pool->old_def.u_free(&unit);
1534 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1535 size_t size = p_pool->old_def.p_get_size(pool);
1542 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1543 ABT_unit unit = p_pool->old_def.p_pop(pool);
1545 ABTI_global *p_global = ABTI_global_get_global();
1546 ABTI_thread *p_thread = ABTI_unit_get_thread(p_global, unit);
1547 return ABTI_thread_get_handle(p_thread);
1557 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1558 p_pool->old_def.p_push(pool, unit);
1563 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1564 return p_pool->old_def.p_init(pool, config);
1569 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1570 p_pool->old_def.p_free(pool);
1575 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1576 return p_pool->old_def.p_get_size(pool);
1583 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1584 ABT_unit unit = p_pool->old_def.p_pop_wait(pool, time_secs);
1586 ABTI_global *p_global = ABTI_global_get_global();
1587 ABTI_thread *p_thread = ABTI_unit_get_thread(p_global, unit);
1588 return ABTI_thread_get_handle(p_thread);
1595 size_t max_threads,
size_t *num_popped,
1600 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1601 for (i = 0; i < max_threads; i++) {
1602 ABT_unit unit = p_pool->old_def.p_pop(pool);
1604 ABTI_global *p_global = ABTI_global_get_global();
1605 ABTI_thread *p_thread = ABTI_unit_get_thread(p_global, unit);
1606 threads[i] = ABTI_thread_get_handle(p_thread);
1619 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1620 for (i = 0; i < num_units; i++) {
1621 p_pool->old_def.p_push(pool, units[i]);
1628 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1630 p_pool->old_def.p_print_all(pool, (
void *)&wrapper_arg,
1636 ABTI_pool_old_def *p_old_def,
1637 ABTI_pool_required_def *p_required_def,
1638 ABTI_pool_optional_def *p_optional_def,
1639 ABTI_pool_deprecated_def *p_deprecated_def)
1643 p_old_def->u_free = p_def->
u_free;
1644 p_old_def->p_init = p_def->
p_init;
1646 p_old_def->p_push = p_def->
p_push;
1647 p_old_def->p_pop = p_def->
p_pop;
1648 #ifdef ABT_CONFIG_ENABLE_VER_20_API
1649 p_old_def->p_pop_wait = p_def->p_pop_wait;
1651 p_old_def->p_pop_wait = NULL;
1671 p_optional_def->p_pop_wait =
1673 p_optional_def->p_print_all =
1679 p_deprecated_def->p_remove = p_def->
p_remove;
1685 const ABTI_pool_required_def *p_required_def,
1686 const ABTI_pool_optional_def *p_optional_def,
1687 const ABTI_pool_deprecated_def *p_deprecated_def,
1688 const ABTI_pool_old_def *p_old_def, ABTI_pool_config *p_config,
1693 abt_errno =
ABTU_malloc(
sizeof(ABTI_pool), (
void **)&p_pool);
1694 ABTI_CHECK_ERROR(abt_errno);
1697 ABT_bool automatic = def_automatic;
1699 int automatic_val = 0;
1708 p_pool->access = access;
1709 p_pool->automatic = automatic;
1710 p_pool->is_builtin = is_builtin;
1711 ABTD_atomic_release_store_int32(&p_pool->num_scheds, 0);
1712 ABTD_atomic_release_store_int32(&p_pool->num_blocked, 0);
1713 p_pool->data = NULL;
1714 memcpy(&p_pool->required_def, p_required_def,
1715 sizeof(ABTI_pool_required_def));
1716 if (p_optional_def) {
1717 memcpy(&p_pool->optional_def, p_optional_def,
1718 sizeof(ABTI_pool_optional_def));
1720 memset(&p_pool->optional_def, 0,
sizeof(ABTI_pool_optional_def));
1722 if (p_deprecated_def) {
1723 memcpy(&p_pool->deprecated_def, p_deprecated_def,
1724 sizeof(ABTI_pool_deprecated_def));
1726 memset(&p_pool->deprecated_def, 0,
sizeof(ABTI_pool_deprecated_def));
1729 memcpy(&p_pool->old_def, p_old_def,
sizeof(ABTI_pool_old_def));
1731 memset(&p_pool->old_def, 0,
sizeof(ABTI_pool_old_def));
1736 if (p_pool->optional_def.p_init) {
1739 p_pool->optional_def.p_init(ABTI_pool_get_handle(p_pool), config);
1745 *pp_newpool = p_pool;
1751 return (uint64_t)ABTD_atomic_fetch_add_uint64(&
g_pool_id, 1);
1757 ABTI_UB_ASSERT(ABTI_initialized());
1758 ABTI_UB_ASSERT(thread);
1760 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1761 ABTI_CHECK_NULL_POOL_PTR(p_pool);
1762 *thread = ABTI_pool_pop(p_pool, pool_ctx);
1767 size_t len,
size_t *num,
1771 ABTI_UB_ASSERT(ABTI_initialized());
1772 ABTI_UB_ASSERT(threads || len == 0);
1773 ABTI_UB_ASSERT(num);
1775 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1776 ABTI_CHECK_NULL_POOL_PTR(p_pool);
1777 ABTI_CHECK_TRUE(p_pool->optional_def.p_pop_many,
ABT_ERR_POOL);
1780 ABTI_pool_pop_many(p_pool, threads, len, num, pool_ctx);
1788 ABTI_UB_ASSERT(ABTI_initialized());
1790 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1791 ABTI_CHECK_NULL_POOL_PTR(p_pool);
1792 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1795 ABTI_global *p_global = ABTI_global_get_global();
1797 ABTI_thread_set_associated_pool(p_global, p_thread, p_pool);
1798 ABTI_CHECK_ERROR(abt_errno);
1799 ABTI_pool_push(p_pool, p_thread->unit, pool_ctx);
1807 ABTI_UB_ASSERT(ABTI_initialized());
1808 ABTI_UB_ASSERT(threads || num == 0);
1810 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1811 ABTI_CHECK_NULL_POOL_PTR(p_pool);
1812 ABTI_CHECK_TRUE(p_pool->optional_def.p_push_many,
ABT_ERR_POOL);
1815 ABTI_global *p_global = ABTI_global_get_global();
1817 ABT_unit *push_units, push_units_buffer[64];
1818 if (num >
sizeof(push_units_buffer) /
sizeof(push_units_buffer[0])) {
1821 ABTI_CHECK_ERROR(abt_errno);
1823 push_units = push_units_buffer;
1826 size_t i, num_units = 0;
1827 for (i = 0; i < num; i++) {
1830 ABTI_thread *p_thread = ABTI_thread_get_ptr(threads[i]);
1833 ABTI_thread_set_associated_pool(p_global, p_thread, p_pool);
1835 if (push_units != push_units_buffer)
1837 ABTI_HANDLE_ERROR(abt_errno);
1839 push_units[num_units++] = p_thread->unit;
1842 if (num_units > 0) {
1843 ABTI_pool_push_many(p_pool, push_units, num_units, pool_ctx);
1845 if (push_units != push_units_buffer)
1855 ABTI_UB_ASSERT(ABTI_initialized());
1856 ABTI_UB_ASSERT(thread);
1858 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1859 ABTI_CHECK_NULL_POOL_PTR(p_pool);
1860 ABTI_CHECK_TRUE(p_pool->optional_def.p_pop_wait,
ABT_ERR_POOL);
1862 *thread = ABTI_pool_pop_wait(p_pool, time_secs, pool_ctx);
1870 ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1878 ABTI_global *p_global = ABTI_global_get_global();
1879 ABTI_thread *p_thread = ABTI_unit_get_thread(p_global, unit);
1880 ABT_thread thread = ABTI_thread_get_handle(p_thread);