ARGOBOTS  dce6e727ffc4ca5b3ffc04cb9517c6689be51ec5
pool.c
Go to the documentation of this file.
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  * See COPYRIGHT in top-level directory.
4  */
5 
6 #include "abti.h"
7 
8 ABTU_ret_err static int pool_create(
9  ABT_pool_access access, const ABTI_pool_required_def *p_required_def,
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,
13  ABT_bool def_automatic, ABT_bool is_builtin, ABTI_pool **pp_newpool);
14 static void
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);
20 static inline int pool_pop_thread_ex(ABT_pool pool, ABT_thread *thread,
21  ABT_pool_context pool_ctx);
22 static inline int pool_pop_threads_ex(ABT_pool pool, ABT_thread *threads,
23  size_t len, size_t *num,
24  ABT_pool_context pool_ctx);
25 static inline int pool_push_thread_ex(ABT_pool pool, ABT_thread thread,
26  ABT_pool_context pool_ctx);
27 static inline int pool_push_threads_ex(ABT_pool pool, const ABT_thread *threads,
28  size_t num, ABT_pool_context pool_ctx);
29 static inline int pool_pop_wait_thread_ex(ABT_pool pool, ABT_thread *thread,
30  double time_secs,
31  ABT_pool_context pool_ctx);
32 typedef struct {
33  void *arg;
34  void (*print_fn)(void *, ABT_unit);
36 static void pool_print_thread_to_unit(void *arg, ABT_thread thread);
37 typedef struct {
38  void *arg;
39  void (*print_fn)(void *, ABT_thread);
41 static void pool_print_unit_to_thread(void *arg, ABT_unit unit);
42 
112  ABT_pool *newpool)
113 {
115  ABTI_UB_ASSERT(newpool);
116  ABTI_UB_ASSERT(def);
117 #ifndef ABT_CONFIG_ENABLE_VER_20_API
118  /* Argobots 1.x sets newpool to NULL on error. */
119  *newpool = ABT_POOL_NULL;
120 #endif
121  ABT_pool_access access;
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;
126  /* Copy def */
127  if (ABTI_pool_user_def_is_new(def)) {
128  /* New ABTI_pool_user_def */
129  access = ABT_POOL_ACCESS_MPMC;
132  p_required_def = &p_def->required_def;
133  p_optional_def = &p_def->optional_def;
134  p_deprecated_def = NULL;
135  p_old_def = NULL;
136  } else {
137  /* Old ABT_pool_def */
139  ABTI_UB_ASSERT(def->u_free);
141  ABTI_UB_ASSERT(def->p_push);
142  ABTI_UB_ASSERT(def->p_pop);
143  access = def->access;
144  pool_create_def_from_old_def(def, &old_def, &required_def,
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;
150  }
151 
152  ABTI_pool *p_newpool;
153  ABTI_pool_config *p_config = ABTI_pool_config_get_ptr(config);
154  const ABT_bool def_automatic = ABT_FALSE;
155  int abt_errno =
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);
159 
160  *newpool = ABTI_pool_get_handle(p_newpool);
161  return ABT_SUCCESS;
162 }
163 
222  ABT_bool automatic, ABT_pool *newpool)
223 {
225  ABTI_UB_ASSERT_BOOL(automatic);
226  ABTI_UB_ASSERT(newpool);
227 
228 #ifndef ABT_CONFIG_ENABLE_VER_20_API
229  /* Argobots 1.x sets newpool to NULL on error. */
230  *newpool = ABT_POOL_NULL;
231 #endif
232  ABTI_pool *p_newpool;
233  int abt_errno = ABTI_pool_create_basic(kind, access, automatic, &p_newpool);
234  ABTI_CHECK_ERROR(abt_errno);
235 
236  *newpool = ABTI_pool_get_handle(p_newpool);
237  return ABT_SUCCESS;
238 }
239 
270 {
272  ABTI_UB_ASSERT(pool);
273 
274  ABT_pool h_pool = *pool;
275  ABTI_pool *p_pool = ABTI_pool_get_ptr(h_pool);
276  ABTI_CHECK_NULL_POOL_PTR(p_pool);
278 
279  ABTI_pool_free(p_pool);
280 
281  *pool = ABT_POOL_NULL;
282  return ABT_SUCCESS;
283 }
284 
308 {
310  ABTI_UB_ASSERT(access);
311 
312  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
313  ABTI_CHECK_NULL_POOL_PTR(p_pool);
314 
315  *access = p_pool->access;
316  return ABT_SUCCESS;
317 }
318 
342 int ABT_pool_is_empty(ABT_pool pool, ABT_bool *is_empty)
343 {
345  ABTI_UB_ASSERT(is_empty);
346 
347  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
348  ABTI_CHECK_NULL_POOL_PTR(p_pool);
349 
350  *is_empty = ABTI_pool_is_empty(p_pool);
351  return ABT_SUCCESS;
352 }
353 
392 int ABT_pool_get_total_size(ABT_pool pool, size_t *size)
393 {
395  ABTI_UB_ASSERT(size);
396 
397  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
398  ABTI_CHECK_NULL_POOL_PTR(p_pool);
400 
401  *size = ABTI_pool_get_total_size(p_pool);
402  return ABT_SUCCESS;
403 }
404 
440 int ABT_pool_get_size(ABT_pool pool, size_t *size)
441 {
443  ABTI_UB_ASSERT(size);
444 
445  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
446  ABTI_CHECK_NULL_POOL_PTR(p_pool);
448 
449  *size = ABTI_pool_get_size(p_pool);
450  return ABT_SUCCESS;
451 }
452 
476 {
478 }
479 
507  ABT_pool_context pool_ctx)
508 {
509  return pool_pop_thread_ex(pool, thread, pool_ctx);
510 }
511 
536 int ABT_pool_pop_threads(ABT_pool pool, ABT_thread *threads, size_t len,
537  size_t *num)
538 {
539  return pool_pop_threads_ex(pool, threads, len, num,
541 }
542 
578 int ABT_pool_pop_threads_ex(ABT_pool pool, ABT_thread *threads, size_t len,
579  size_t *num, ABT_pool_context pool_ctx)
580 {
581  return pool_pop_threads_ex(pool, threads, len, num, pool_ctx);
582 }
583 
608 {
610 }
611 
639  ABT_pool_context pool_ctx)
640 {
641  return pool_push_thread_ex(pool, thread, pool_ctx);
642 }
643 
671 int ABT_pool_push_threads(ABT_pool pool, const ABT_thread *threads, size_t num)
672 {
673  return pool_push_threads_ex(pool, threads, num,
675 }
676 
706  size_t num, ABT_pool_context pool_ctx)
707 {
708  return pool_push_threads_ex(pool, threads, num, pool_ctx);
709 }
710 
737  double time_secs)
738 {
739  return pool_pop_wait_thread_ex(pool, thread, time_secs,
741 }
742 
775  double time_secs, ABT_pool_context pool_ctx)
776 {
777  return pool_pop_wait_thread_ex(pool, thread, time_secs, pool_ctx);
778 }
779 
812  void (*print_fn)(void *arg, ABT_thread))
813 {
815  ABTI_UB_ASSERT(print_fn);
816 
817  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
818  ABTI_CHECK_NULL_POOL_PTR(p_pool);
820 
821  p_pool->optional_def.p_print_all(pool, arg, print_fn);
822  return ABT_SUCCESS;
823 }
824 
870 int ABT_pool_pop(ABT_pool pool, ABT_unit *p_unit)
871 {
873  ABTI_UB_ASSERT(p_unit);
874 
875  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
876  ABTI_CHECK_NULL_POOL_PTR(p_pool);
877 
879  if (thread != ABT_THREAD_NULL) {
880  ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
881  *p_unit = p_thread->unit;
882  } else {
883  *p_unit = ABT_UNIT_NULL;
884  }
885  return ABT_SUCCESS;
886 }
887 
937 int ABT_pool_pop_wait(ABT_pool pool, ABT_unit *p_unit, double time_secs)
938 {
940  ABTI_UB_ASSERT(p_unit);
941 
942  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
943  ABTI_CHECK_NULL_POOL_PTR(p_pool);
945 
946  ABT_thread thread =
948  if (thread != ABT_THREAD_NULL) {
949  ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
950  *p_unit = p_thread->unit;
951  } else {
952  *p_unit = ABT_UNIT_NULL;
953  }
954  return ABT_SUCCESS;
955 }
956 
1011 int ABT_pool_pop_timedwait(ABT_pool pool, ABT_unit *p_unit, double abstime_secs)
1012 {
1014  ABTI_UB_ASSERT(p_unit);
1015 
1016  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1017  ABTI_CHECK_NULL_POOL_PTR(p_pool);
1019 
1020  ABT_thread thread = ABTI_pool_pop_timedwait(p_pool, abstime_secs);
1021  if (thread != ABT_THREAD_NULL) {
1022  ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1023  *p_unit = p_thread->unit;
1024  } else {
1025  *p_unit = ABT_UNIT_NULL;
1026  }
1027  return ABT_SUCCESS;
1028 }
1029 
1069 int ABT_pool_push(ABT_pool pool, ABT_unit unit)
1072 
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);
1076 
1078 
1079  ABTI_thread *p_thread;
1080  int abt_errno =
1081  ABTI_unit_set_associated_pool(p_global, unit, p_pool, &p_thread);
1082  ABTI_CHECK_ERROR(abt_errno);
1083  /* ABTI_unit_set_associated_pool() might change unit, so "unit" must be read
1084  * again from p_thread. */
1086  return ABT_SUCCESS;
1087 }
1088 
1129 int ABT_pool_remove(ABT_pool pool, ABT_unit unit)
1132 
1133  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1134  ABTI_CHECK_NULL_POOL_PTR(p_pool);
1136 
1137  /* unit must be in this pool, so we do not need to reset its associated
1138  * pool. */
1139  int abt_errno = ABTI_pool_remove(p_pool, unit);
1140  ABTI_CHECK_ERROR(abt_errno);
1141  return ABT_SUCCESS;
1142 }
1143 
1187 int ABT_pool_print_all(ABT_pool pool, void *arg,
1188  void (*print_fn)(void *, ABT_unit))
1189 {
1191  ABTI_UB_ASSERT(print_fn);
1192 
1193  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1194  ABTI_CHECK_NULL_POOL_PTR(p_pool);
1196 
1197  pool_print_thread_to_unit_arg_t func_arg = { arg, print_fn };
1198  p_pool->optional_def.p_print_all(pool, (void *)&func_arg,
1200  return ABT_SUCCESS;
1201 }
1202 
1225 int ABT_pool_set_data(ABT_pool pool, void *data)
1228 
1229  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1230  ABTI_CHECK_NULL_POOL_PTR(p_pool);
1231 
1232  p_pool->data = data;
1233  return ABT_SUCCESS;
1234 }
1235 
1260 int ABT_pool_get_data(ABT_pool pool, void **data)
1264 
1265  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1266  ABTI_CHECK_NULL_POOL_PTR(p_pool);
1267 
1268  *data = p_pool->data;
1269  return ABT_SUCCESS;
1270 }
1271 
1315 int ABT_pool_add_sched(ABT_pool pool, ABT_sched sched)
1318 
1319  ABTI_local *p_local = ABTI_local_get_local();
1320 
1321  ABTI_global *p_global;
1322  ABTI_SETUP_GLOBAL(&p_global);
1323 
1324  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1325  ABTI_CHECK_NULL_POOL_PTR(p_pool);
1326 
1327  ABTI_sched *p_sched = ABTI_sched_get_ptr(sched);
1328  ABTI_CHECK_NULL_SCHED_PTR(p_sched);
1329 
1330  /* Mark the scheduler as it is used in pool */
1331 #ifndef ABT_CONFIG_ENABLE_VER_20_API
1333 #else
1335 #endif
1336  p_sched->used = ABTI_SCHED_IN_POOL;
1337 
1338 #ifndef ABT_CONFIG_ENABLE_VER_20_API
1339  /* In both ABT_SCHED_TYPE_ULT and ABT_SCHED_TYPE_TASK cases, we use ULT-type
1340  * scheduler to reduce the code maintenance cost. */
1341 #endif
1342  int abt_errno =
1343  ABTI_ythread_create_sched(p_global, p_local, p_pool, p_sched);
1344  if (abt_errno != ABT_SUCCESS) {
1345  p_sched->used = ABTI_SCHED_NOT_USED;
1346  ABTI_HANDLE_ERROR(abt_errno);
1347  }
1348  return ABT_SUCCESS;
1349 }
1350 
1372 int ABT_pool_get_id(ABT_pool pool, int *id)
1375  ABTI_UB_ASSERT(id);
1376 
1377  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1378  ABTI_CHECK_NULL_POOL_PTR(p_pool);
1379 
1380  *id = (int)p_pool->id;
1381  return ABT_SUCCESS;
1382 }
1383 
1384 /*****************************************************************************/
1385 /* Private APIs */
1386 /*****************************************************************************/
1387 
1390  ABT_bool automatic,
1391  ABTI_pool **pp_newpool)
1392 {
1393  int abt_errno;
1395  access == ABT_POOL_ACCESS_SPSC ||
1396  access == ABT_POOL_ACCESS_MPSC ||
1397  access == ABT_POOL_ACCESS_SPMC ||
1398  access == ABT_POOL_ACCESS_MPMC,
1400 
1401  ABTI_pool_required_def required_def;
1402  ABTI_pool_optional_def optional_def;
1403  ABTI_pool_deprecated_def deprecated_def;
1404  switch (kind) {
1405  case ABT_POOL_FIFO:
1406  abt_errno = ABTI_pool_get_fifo_def(access, &required_def,
1407  &optional_def, &deprecated_def);
1408  break;
1409  case ABT_POOL_FIFO_WAIT:
1410  abt_errno =
1411  ABTI_pool_get_fifo_wait_def(access, &required_def,
1412  &optional_def, &deprecated_def);
1413  break;
1414  case ABT_POOL_RANDWS:
1415  abt_errno =
1416  ABTI_pool_get_randws_def(access, &required_def, &optional_def,
1417  &deprecated_def);
1418  break;
1419  default:
1420  abt_errno = ABT_ERR_INV_POOL_KIND;
1421  break;
1422  }
1423  ABTI_CHECK_ERROR(abt_errno);
1424 
1425  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);
1429  return ABT_SUCCESS;
1430 }
1431 
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);
1437  }
1438  ABTU_free(p_pool);
1439 }
1440 
1441 ABT_thread ABTI_pool_pop_timedwait(ABTI_pool *p_pool, double abstime_secs)
1444  ABT_unit unit =
1446  abstime_secs);
1447  if (unit == ABT_UNIT_NULL) {
1448  return ABT_THREAD_NULL;
1449  } else {
1450  ABTI_thread *p_thread =
1452  ABT_thread thread = ABTI_thread_get_handle(p_thread);
1453  LOG_DEBUG_POOL_POP(p_pool, thread);
1454  return thread;
1455  }
1456 }
1457 
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, "");
1462  } else {
1463  const char *access;
1464 
1465  switch (p_pool->access) {
1466  case ABT_POOL_ACCESS_PRIV:
1467  access = "PRIV";
1468  break;
1469  case ABT_POOL_ACCESS_SPSC:
1470  access = "SPSC";
1471  break;
1472  case ABT_POOL_ACCESS_MPSC:
1473  access = "MPSC";
1474  break;
1475  case ABT_POOL_ACCESS_SPMC:
1476  access = "SPMC";
1477  break;
1478  case ABT_POOL_ACCESS_MPMC:
1479  access = "MPMC";
1480  break;
1481  default:
1482  access = "UNKNOWN";
1483  break;
1484  }
1485 
1486  fprintf(p_os,
1487  "%*s== POOL (%p) ==\n"
1488  "%*sid : %" PRIu64 "\n"
1489  "%*saccess : %s\n"
1490  "%*sautomatic : %s\n"
1491  "%*snum_scheds : %d\n"
1492  "%*sis_empty : %s\n"
1493  "%*ssize : %zu\n"
1494  "%*snum_blocked : %d\n"
1495  "%*sdata : %p\n",
1496  indent, "", (void *)p_pool, indent, "", p_pool->id, indent, "",
1497  access, 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)
1502  : 0),
1503  indent, "",
1504  ABTD_atomic_acquire_load_int32(&p_pool->num_blocked), indent,
1505  "", p_pool->data);
1506  }
1507  fflush(p_os);
1508 }
1509 
1514 }
1515 
1516 /*****************************************************************************/
1517 /* Internal static functions */
1518 /*****************************************************************************/
1519 
1522  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1523  return p_pool->old_def.u_create_from_thread(thread);
1524 }
1525 
1526 static void pool_free_unit_wrapper(ABT_pool pool, ABT_unit unit)
1528  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1529  p_pool->old_def.u_free(&unit);
1530 }
1531 
1534  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1535  size_t size = p_pool->old_def.p_get_size(pool);
1536  return (size == 0) ? ABT_TRUE : ABT_FALSE;
1537 }
1538 
1541  (void)context;
1542  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1543  ABT_unit unit = p_pool->old_def.p_pop(pool);
1544  if (unit != ABT_UNIT_NULL) {
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);
1548  } else {
1549  return ABT_THREAD_NULL;
1550  }
1551 }
1552 
1553 static void pool_push_wrapper(ABT_pool pool, ABT_unit unit,
1555 {
1556  (void)context;
1557  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1558  p_pool->old_def.p_push(pool, unit);
1559 }
1560 
1561 static int pool_init_wrapper(ABT_pool pool, ABT_pool_config config)
1563  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1564  return p_pool->old_def.p_init(pool, config);
1565 }
1566 
1567 static void pool_free_wrapper(ABT_pool pool)
1569  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1570  p_pool->old_def.p_free(pool);
1571 }
1572 
1573 static size_t pool_get_size_wrapper(ABT_pool pool)
1575  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1576  return p_pool->old_def.p_get_size(pool);
1577 }
1578 
1579 static ABT_thread pool_pop_wait_wrapper(ABT_pool pool, double time_secs,
1581 {
1582  (void)context;
1583  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1584  ABT_unit unit = p_pool->old_def.p_pop_wait(pool, time_secs);
1585  if (unit != ABT_UNIT_NULL) {
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);
1589  } else {
1590  return ABT_THREAD_NULL;
1591  }
1592 }
1593 
1594 static void pool_pop_many_wrapper(ABT_pool pool, ABT_thread *threads,
1595  size_t max_threads, size_t *num_popped,
1596  ABT_pool_context context)
1597 {
1598  (void)context;
1599  size_t i;
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);
1603  if (unit != ABT_UNIT_NULL) {
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);
1607  } else {
1608  break;
1609  }
1610  }
1611  *num_popped = i;
1612 }
1613 
1614 static void pool_push_many_wrapper(ABT_pool pool, const ABT_unit *units,
1615  size_t num_units, ABT_pool_context context)
1616 {
1617  (void)context;
1618  size_t i;
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]);
1622  }
1623 }
1624 
1625 static void pool_print_all_wrapper(ABT_pool pool, void *arg,
1626  void (*print_f)(void *, ABT_thread))
1627 {
1628  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1629  pool_print_unit_to_thread_arg_t wrapper_arg = { arg, print_f };
1630  p_pool->old_def.p_print_all(pool, (void *)&wrapper_arg,
1632 }
1633 
1634 static void
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)
1640 {
1641  /* Create p_old_def*/
1642  p_old_def->u_create_from_thread = p_def->u_create_from_thread;
1643  p_old_def->u_free = p_def->u_free;
1644  p_old_def->p_init = p_def->p_init;
1645  p_old_def->p_get_size = p_def->p_get_size;
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;
1650 #else
1651  p_old_def->p_pop_wait = NULL;
1652 #endif
1653  p_old_def->p_free = p_def->p_free;
1654  p_old_def->p_print_all = p_def->p_print_all;
1655 
1656  /* Set up p_required_def */
1657  p_required_def->p_create_unit = pool_create_unit_wrapper;
1658  p_required_def->p_free_unit = pool_free_unit_wrapper;
1659  p_required_def->p_is_empty = pool_is_empty_wrapper;
1660  p_required_def->p_pop = pool_pop_wrapper;
1661  p_required_def->p_push = pool_push_wrapper;
1662 
1663  /* Set up p_optional_def */
1664  /* Must be created from ABT_pool_def */
1665  p_optional_def->p_get_size = pool_get_size_wrapper;
1666  p_optional_def->p_pop_many = pool_pop_many_wrapper;
1667  p_optional_def->p_push_many = pool_push_many_wrapper;
1668  /* Optional */
1669  p_optional_def->p_init = p_old_def->p_init ? pool_init_wrapper : NULL;
1670  p_optional_def->p_free = p_old_def->p_free ? pool_free_wrapper : NULL;
1671  p_optional_def->p_pop_wait =
1672  p_old_def->p_pop_wait ? pool_pop_wait_wrapper : NULL;
1673  p_optional_def->p_print_all =
1674  p_old_def->p_print_all ? pool_print_all_wrapper : NULL;
1675 
1676  /* Set up p_deprecated_def */
1677  p_deprecated_def->u_is_in_pool = p_def->u_is_in_pool;
1678  p_deprecated_def->p_pop_timedwait = p_def->p_pop_timedwait;
1679  p_deprecated_def->p_remove = p_def->p_remove;
1680 }
1681 
1682 static inline uint64_t pool_get_new_id(void);
1683 ABTU_ret_err static int
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,
1689  ABT_bool def_automatic, ABT_bool is_builtin, ABTI_pool **pp_newpool)
1690 {
1691  int abt_errno;
1692  ABTI_pool *p_pool;
1693  abt_errno = ABTU_malloc(sizeof(ABTI_pool), (void **)&p_pool);
1694  ABTI_CHECK_ERROR(abt_errno);
1695 
1696  /* Read the config and set the configured parameter */
1697  ABT_bool automatic = def_automatic;
1698  if (p_config) {
1699  int automatic_val = 0;
1700  abt_errno =
1702  &automatic_val);
1703  if (abt_errno == ABT_SUCCESS) {
1704  automatic = (automatic_val == 0) ? ABT_FALSE : ABT_TRUE;
1705  }
1706  }
1707 
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));
1719  } else {
1720  memset(&p_pool->optional_def, 0, sizeof(ABTI_pool_optional_def));
1721  }
1722  if (p_deprecated_def) {
1723  memcpy(&p_pool->deprecated_def, p_deprecated_def,
1724  sizeof(ABTI_pool_deprecated_def));
1725  } else {
1726  memset(&p_pool->deprecated_def, 0, sizeof(ABTI_pool_deprecated_def));
1727  }
1728  if (p_old_def) {
1729  memcpy(&p_pool->old_def, p_old_def, sizeof(ABTI_pool_old_def));
1730  } else {
1731  memset(&p_pool->old_def, 0, sizeof(ABTI_pool_old_def));
1732  }
1733  p_pool->id = pool_get_new_id();
1734 
1735  /* Configure the pool */
1736  if (p_pool->optional_def.p_init) {
1737  ABT_pool_config config = ABTI_pool_config_get_handle(p_config);
1738  abt_errno =
1739  p_pool->optional_def.p_init(ABTI_pool_get_handle(p_pool), config);
1740  if (abt_errno != ABT_SUCCESS) {
1741  ABTU_free(p_pool);
1742  return abt_errno;
1743  }
1744  }
1745  *pp_newpool = p_pool;
1746  return ABT_SUCCESS;
1747 }
1748 
1749 static inline uint64_t pool_get_new_id(void)
1751  return (uint64_t)ABTD_atomic_fetch_add_uint64(&g_pool_id, 1);
1752 }
1753 
1754 static inline int pool_pop_thread_ex(ABT_pool pool, ABT_thread *thread,
1756 {
1758  ABTI_UB_ASSERT(thread);
1759 
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);
1763  return ABT_SUCCESS;
1764 }
1765 
1766 static inline int pool_pop_threads_ex(ABT_pool pool, ABT_thread *threads,
1767  size_t len, size_t *num,
1768  ABT_pool_context pool_ctx)
1769 {
1770  ABTI_STATIC_ASSERT(sizeof(ABT_unit) == sizeof(ABT_thread));
1772  ABTI_UB_ASSERT(threads || len == 0);
1773  ABTI_UB_ASSERT(num);
1774 
1775  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1776  ABTI_CHECK_NULL_POOL_PTR(p_pool);
1778 
1779  if (len > 0) {
1780  ABTI_pool_pop_many(p_pool, threads, len, num, pool_ctx);
1781  }
1782  return ABT_SUCCESS;
1783 }
1784 
1785 static inline int pool_push_thread_ex(ABT_pool pool, ABT_thread thread,
1787 {
1789 
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);
1793 
1794  if (p_thread) {
1795  ABTI_global *p_global = ABTI_global_get_global();
1796  int abt_errno =
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);
1800  }
1801  return ABT_SUCCESS;
1802 }
1803 
1804 static inline int pool_push_threads_ex(ABT_pool pool, const ABT_thread *threads,
1805  size_t num, ABT_pool_context pool_ctx)
1806 {
1808  ABTI_UB_ASSERT(threads || num == 0);
1809 
1810  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1811  ABTI_CHECK_NULL_POOL_PTR(p_pool);
1813 
1814  if (num > 0) {
1815  ABTI_global *p_global = ABTI_global_get_global();
1816  int abt_errno;
1817  ABT_unit *push_units, push_units_buffer[64];
1818  if (num > sizeof(push_units_buffer) / sizeof(push_units_buffer[0])) {
1819  abt_errno =
1820  ABTU_malloc(sizeof(ABT_unit) * num, (void **)&push_units);
1821  ABTI_CHECK_ERROR(abt_errno);
1822  } else {
1823  push_units = push_units_buffer;
1824  }
1825 
1826  size_t i, num_units = 0;
1827  for (i = 0; i < num; i++) {
1828  /* FIXME: the following can break the intermediate mapping if an
1829  * error happens. */
1830  ABTI_thread *p_thread = ABTI_thread_get_ptr(threads[i]);
1831  if (p_thread) {
1832  abt_errno =
1833  ABTI_thread_set_associated_pool(p_global, p_thread, p_pool);
1834  if (abt_errno != ABT_SUCCESS) {
1835  if (push_units != push_units_buffer)
1836  ABTU_free(push_units);
1837  ABTI_HANDLE_ERROR(abt_errno);
1838  }
1839  push_units[num_units++] = p_thread->unit;
1840  }
1841  }
1842  if (num_units > 0) {
1843  ABTI_pool_push_many(p_pool, push_units, num_units, pool_ctx);
1844  }
1845  if (push_units != push_units_buffer)
1846  ABTU_free(push_units);
1847  }
1848  return ABT_SUCCESS;
1849 }
1850 
1851 static inline int pool_pop_wait_thread_ex(ABT_pool pool, ABT_thread *thread,
1852  double time_secs,
1853  ABT_pool_context pool_ctx)
1854 {
1856  ABTI_UB_ASSERT(thread);
1857 
1858  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
1859  ABTI_CHECK_NULL_POOL_PTR(p_pool);
1861 
1862  *thread = ABTI_pool_pop_wait(p_pool, time_secs, pool_ctx);
1863  return ABT_SUCCESS;
1864 }
1865 
1866 static void pool_print_thread_to_unit(void *arg, ABT_thread thread)
1870  ABTI_thread *p_thread = ABTI_thread_get_ptr(thread);
1871  p_arg->print_fn(p_arg->arg, p_thread->unit);
1872 }
1873 
1874 static void pool_print_unit_to_thread(void *arg, ABT_unit unit)
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);
1881  p_arg->print_fn(p_arg->arg, thread);
1882 }
ABT_pool_pop_thread
int ABT_pool_pop_thread(ABT_pool pool, ABT_thread *thread)
Pop a work unit from a pool.
Definition: pool.c:475
ABTI_pool_optional_def::p_get_size
ABT_pool_user_get_size_fn p_get_size
Definition: abti.h:361
ABTI_CHECK_NULL_SCHED_PTR
#define ABTI_CHECK_NULL_SCHED_PTR(p)
Definition: abti_error.h:211
ABTI_sched_get_ptr
static ABTI_sched * ABTI_sched_get_ptr(ABT_sched sched)
Definition: abti_sched.h:11
ABT_pool_get_data
int ABT_pool_get_data(ABT_pool pool, void **data)
Retrieve user data from a pool.
Definition: pool.c:1261
ABTI_pool_optional_def::p_init
ABT_pool_user_init_fn p_init
Definition: abti.h:359
ABT_pool_pop_wait
int ABT_pool_pop_wait(ABT_pool pool, ABT_unit *p_unit, double time_secs)
Pop a unit from a pool with wait.
Definition: pool.c:937
ABTI_pool_deprecated_def::p_remove
ABT_pool_remove_fn p_remove
Definition: abti.h:373
ABT_bool
int ABT_bool
Boolean type.
Definition: abt.h:1043
ABT_pool_get_size
int ABT_pool_get_size(ABT_pool pool, size_t *size)
Get the size of a pool.
Definition: pool.c:440
ABT_pool_print_all_threads
int ABT_pool_print_all_threads(ABT_pool pool, void *arg, void(*print_fn)(void *arg, ABT_thread))
Apply a print function to every work unit in a pool.
Definition: pool.c:811
pool_pop_wrapper
static ABT_thread pool_pop_wrapper(ABT_pool pool, ABT_pool_context context)
Definition: pool.c:1540
ABT_pool_context
uint64_t ABT_pool_context
A pool context value.
Definition: abt.h:1566
ABTI_SCHED_NOT_USED
@ ABTI_SCHED_NOT_USED
Definition: abti.h:71
pool_create_unit_wrapper
static ABT_unit pool_create_unit_wrapper(ABT_pool pool, ABT_thread thread)
Definition: pool.c:1521
ABTD_atomic_uint64
Definition: abtd_atomic.h:35
ABT_pool_add_sched
int ABT_pool_add_sched(ABT_pool pool, ABT_sched sched)
Create a new work unit associated with a scheduler and push it to a pool.
Definition: pool.c:1316
ABT_thread
struct ABT_thread_opaque * ABT_thread
Work unit handle type.
Definition: abt.h:932
ABTI_pool_required_def::p_push
ABT_pool_user_push_fn p_push
Definition: abti.h:354
ABTI_pool_required_def::p_pop
ABT_pool_user_pop_fn p_pop
Definition: abti.h:353
ABTI_SETUP_GLOBAL
#define ABTI_SETUP_GLOBAL(pp_global)
Definition: abti_error.h:75
ABT_pool_is_empty
int ABT_pool_is_empty(ABT_pool pool, ABT_bool *is_empty)
Check if a pool is empty.
Definition: pool.c:342
ABTI_unit_set_associated_pool
static ABTU_ret_err int ABTI_unit_set_associated_pool(ABTI_global *p_global, ABT_unit unit, ABTI_pool *p_pool, ABTI_thread **pp_thread)
Definition: abti_unit.h:55
ABT_POOL_CONTEXT_OP_POOL_OTHER
#define ABT_POOL_CONTEXT_OP_POOL_OTHER
A flag that hints an unspecified pool operation.
Definition: abt.h:1660
ABTI_pool_optional_def::p_print_all
ABT_pool_user_print_all_fn p_print_all
Definition: abti.h:365
ABTI_global_get_global
static ABTI_global * ABTI_global_get_global(void)
Definition: abti_global.h:9
ABTI_pool_optional_def
Definition: abti.h:357
ABTI_pool_old_def::u_free
ABT_unit_free_fn u_free
Definition: abti.h:379
ABT_ERR_POOL
#define ABT_ERR_POOL
Error code: error related to a pool.
Definition: abt.h:292
ABTI_pool_old_def::u_create_from_thread
ABT_unit_create_from_thread_fn u_create_from_thread
Definition: abti.h:378
ABTI_pool_user_def_get_ptr
static ABTI_pool_user_def * ABTI_pool_user_def_get_ptr(ABT_pool_user_def def)
Definition: abti_pool_user_def.h:12
ABTI_CHECK_ERROR
#define ABTI_CHECK_ERROR(abt_errno)
Definition: abti_error.h:136
data
Definition: fifo.c:45
pool_pop_wait_wrapper
static ABT_thread pool_pop_wait_wrapper(ABT_pool pool, double time_secs, ABT_pool_context context)
Definition: pool.c:1580
ABT_pool_def::u_free
ABT_unit_free_fn u_free
Function that frees a work unit.
Definition: abt.h:2154
pool_pop_threads_ex
static int pool_pop_threads_ex(ABT_pool pool, ABT_thread *threads, size_t len, size_t *num, ABT_pool_context pool_ctx)
Definition: pool.c:1767
ABT_POOL_ACCESS_MPMC
@ ABT_POOL_ACCESS_MPMC
Definition: abt.h:575
ABTI_thread::unit
ABT_unit unit
Definition: abti.h:427
pool_push_wrapper
static void pool_push_wrapper(ABT_pool pool, ABT_unit unit, ABT_pool_context context)
Definition: pool.c:1554
pool_push_thread_ex
static int pool_push_thread_ex(ABT_pool pool, ABT_thread thread, ABT_pool_context pool_ctx)
Definition: pool.c:1786
ABT_pool_push_threads
int ABT_pool_push_threads(ABT_pool pool, const ABT_thread *threads, size_t num)
Push work units to a pool.
Definition: pool.c:671
ABTI_pool_old_def::p_push
ABT_pool_push_fn p_push
Definition: abti.h:382
ABTI_pool_get_size
static size_t ABTI_pool_get_size(ABTI_pool *p_pool)
Definition: abti_pool.h:141
ABT_THREAD_NULL
#define ABT_THREAD_NULL
Definition: abt.h:1105
pool_print_unit_to_thread_arg_t::print_fn
void(* print_fn)(void *, ABT_thread)
Definition: pool.c:39
ABT_pool_def::p_remove
ABT_pool_remove_fn p_remove
Function that removes a work unit from a pool.
Definition: abt.h:2271
ABTI_thread_get_handle
static ABT_thread ABTI_thread_get_handle(ABTI_thread *p_thread)
Definition: abti_thread.h:24
ABTI_thread_set_associated_pool
static ABTU_ret_err int ABTI_thread_set_associated_pool(ABTI_global *p_global, ABTI_thread *p_thread, ABTI_pool *p_pool)
Definition: abti_unit.h:155
ABTD_atomic_release_store_int32
static void ABTD_atomic_release_store_int32(ABTD_atomic_int32 *ptr, int32_t val)
Definition: abtd_atomic.h:1088
ABTI_thread
Definition: abti.h:422
ABT_pool_def::u_is_in_pool
ABT_unit_is_in_pool_fn u_is_in_pool
Function that returns whether a work unit is in its associated pool or not.
Definition: abt.h:2098
ABTI_pool_pop_timedwait
ABT_thread ABTI_pool_pop_timedwait(ABTI_pool *p_pool, double abstime_secs)
Definition: pool.c:1442
ABTI_pool_required_def::p_free_unit
ABT_pool_user_free_unit_fn p_free_unit
Definition: abti.h:351
pool_print_unit_to_thread_arg_t
Definition: pool.c:37
ABT_pool
struct ABT_pool_opaque * ABT_pool
Pool handle type.
Definition: abt.h:878
ABTI_CHECK_NULL_POOL_USER_DEF_PTR
#define ABTI_CHECK_NULL_POOL_USER_DEF_PTR(p)
Definition: abti_error.h:202
pool_print_thread_to_unit
static void pool_print_thread_to_unit(void *arg, ABT_thread thread)
Definition: pool.c:1867
ABT_POOL_ACCESS_MPSC
@ ABT_POOL_ACCESS_MPSC
Definition: abt.h:569
ABTI_SCHED_IN_POOL
@ ABTI_SCHED_IN_POOL
Definition: abti.h:73
pool_is_empty_wrapper
static ABT_bool pool_is_empty_wrapper(ABT_pool pool)
Definition: pool.c:1533
ABTI_pool_old_def::p_init
ABT_pool_init_fn p_init
Definition: abti.h:380
ABTI_pool_pop
static ABT_thread ABTI_pool_pop(ABTI_pool *p_pool, ABT_pool_context context)
Definition: abti_pool.h:93
ABT_POOL_RANDWS
@ ABT_POOL_RANDWS
Definition: abt.h:549
ABTI_pool_deprecated_def::p_pop_timedwait
ABT_pool_pop_timedwait_fn p_pop_timedwait
Definition: abti.h:372
ABT_POOL_ACCESS_PRIV
@ ABT_POOL_ACCESS_PRIV
Definition: abt.h:560
ABTI_sched::used
ABTI_sched_used used
Definition: abti.h:320
ABT_sched
struct ABT_sched_opaque * ABT_sched
Scheduler handle type.
Definition: abt.h:845
ABTD_atomic_acquire_load_int32
static int32_t ABTD_atomic_acquire_load_int32(const ABTD_atomic_int32 *ptr)
Definition: abtd_atomic.h:911
ABT_ERR_INV_SCHED
#define ABT_ERR_INV_SCHED
Error code: invalid scheduler.
Definition: abt.h:129
ABTI_pool_required_def
Definition: abti.h:348
ABT_pool_pop_threads_ex
int ABT_pool_pop_threads_ex(ABT_pool pool, ABT_thread *threads, size_t len, size_t *num, ABT_pool_context pool_ctx)
Pop work units from a pool.
Definition: pool.c:578
ABTI_pool
Definition: abti.h:389
ABT_pool_print_all
int ABT_pool_print_all(ABT_pool pool, void *arg, void(*print_fn)(void *, ABT_unit))
Apply a print function to every work unit in a pool using a user-defined function.
Definition: pool.c:1188
pool_free_unit_wrapper
static void pool_free_unit_wrapper(ABT_pool pool, ABT_unit unit)
Definition: pool.c:1527
ABT_POOL_NULL
#define ABT_POOL_NULL
Definition: abt.h:1102
ABTD_atomic_release_store_uint64
static void ABTD_atomic_release_store_uint64(ABTD_atomic_uint64 *ptr, uint64_t val)
Definition: abtd_atomic.h:1124
abti.h
pool_init_wrapper
static int pool_init_wrapper(ABT_pool pool, ABT_pool_config config)
Definition: pool.c:1562
ABTI_pool::data
void * data
Definition: abti.h:396
LOG_DEBUG_POOL_POP
#define LOG_DEBUG_POOL_POP(p_pool, thread)
Definition: abti_log.h:39
ABT_pool_def
A struct that defines a pool.
Definition: abt.h:2049
ABTI_pool_config_get_handle
static ABT_pool_config ABTI_pool_config_get_handle(ABTI_pool_config *p_config)
Definition: abti_pool_config.h:27
ABTI_pool_push_many
static void ABTI_pool_push_many(ABTI_pool *p_pool, const ABT_unit *units, size_t num, ABT_pool_context context)
Definition: abti_pool.h:112
ABTI_pool_deprecated_def::u_is_in_pool
ABT_unit_is_in_pool_fn u_is_in_pool
Definition: abti.h:371
pool_print_thread_to_unit_arg_t::print_fn
void(* print_fn)(void *, ABT_unit)
Definition: pool.c:34
ABT_pool_remove
int ABT_pool_remove(ABT_pool pool, ABT_unit unit)
Remove a specified work unit from a pool.
Definition: pool.c:1130
ABTI_HANDLE_ERROR
#define ABTI_HANDLE_ERROR(n)
Definition: abti_error.h:130
g_pool_id
static ABTD_atomic_uint64 g_pool_id
Definition: pool.c:1511
ABT_pool_config
struct ABT_pool_config_opaque * ABT_pool_config
Pool configuration handle type.
Definition: abt.h:885
ABTI_pool_pop_wait
static ABT_thread ABTI_pool_pop_wait(ABTI_pool *p_pool, double time_secs, ABT_pool_context context)
Definition: abti_pool.h:79
ABTI_pool_create_basic
ABTU_ret_err int ABTI_pool_create_basic(ABT_pool_kind kind, ABT_pool_access access, ABT_bool automatic, ABTI_pool **pp_newpool)
Definition: pool.c:1389
ABTU_malloc
static ABTU_ret_err int ABTU_malloc(size_t size, void **p_ptr)
Definition: abtu.h:235
ABTI_pool_remove
static ABTU_ret_err int ABTI_pool_remove(ABTI_pool *p_pool, ABT_unit unit)
Definition: abti_pool.h:71
ABT_pool_def::p_pop_timedwait
ABT_pool_pop_timedwait_fn p_pop_timedwait
Function that pops a work unit from a pool with wait.
Definition: abt.h:2257
ABTI_pool_old_def
Definition: abti.h:376
ABT_pool_def::p_pop
ABT_pool_pop_fn p_pop
Function that pops a work unit from a pool.
Definition: abt.h:2213
ABT_pool_def::p_free
ABT_pool_free_fn p_free
Function that frees a pool.
Definition: abt.h:2284
ABTI_pool_user_def::optional_def
ABTI_pool_optional_def optional_def
Definition: abti.h:415
ABTI_pool_get_randws_def
ABTU_ret_err int ABTI_pool_get_randws_def(ABT_pool_access access, ABTI_pool_required_def *p_required_def, ABTI_pool_optional_def *p_optional_def, ABTI_pool_deprecated_def *p_deprecated_def)
Definition: randws.c:64
ABT_ERR_INV_UNIT
#define ABT_ERR_INV_UNIT
Error code: invalid work unit for scheduling.
Definition: abt.h:181
ABT_POOL_FIFO
@ ABT_POOL_FIFO
Definition: abt.h:516
ABTD_ATOMIC_UINT64_STATIC_INITIALIZER
#define ABTD_ATOMIC_UINT64_STATIC_INITIALIZER(val)
Definition: abtd_atomic.h:67
ABT_ERR_INV_POOL_ACCESS
#define ABT_ERR_INV_POOL_ACCESS
Error code: invalid pool access type.
Definition: abt.h:166
pool_pop_thread_ex
static int pool_pop_thread_ex(ABT_pool pool, ABT_thread *thread, ABT_pool_context pool_ctx)
Definition: pool.c:1755
ABT_pool_def::p_print_all
ABT_pool_print_all_fn p_print_all
Function that applies a user-given function to all work units in a pool.
Definition: abt.h:2302
ABT_pool_def::access
ABT_pool_access access
Access type.
Definition: abt.h:2062
ABTI_pool_optional_def::p_pop_wait
ABT_pool_user_pop_wait_fn p_pop_wait
Definition: abti.h:362
ABTI_pool_get_total_size
static size_t ABTI_pool_get_total_size(ABTI_pool *p_pool)
Definition: abti_pool.h:147
ABT_POOL_FIFO_WAIT
@ ABT_POOL_FIFO_WAIT
Definition: abt.h:525
pool_print_unit_to_thread_arg_t::arg
void * arg
Definition: pool.c:38
ABT_unit
struct ABT_unit_opaque * ABT_unit
Work unit handle type for scheduling.
Definition: abt.h:911
pool_print_thread_to_unit_arg_t
Definition: pool.c:32
ABTI_pool_old_def::p_pop
ABT_pool_pop_fn p_pop
Definition: abti.h:383
ABT_pool_config_automatic
const ABT_pool_config_var ABT_pool_config_automatic
Predefined ABT_pool_config_var to configure whether the pool is freed automatically or not.
Definition: pool_config.c:39
ABTI_initialized
ABT_bool ABTI_initialized(void)
Definition: global.c:187
ABTI_pool_old_def::p_free
ABT_pool_free_fn p_free
Definition: abti.h:385
ABTI_local_get_local
static ABTI_local * ABTI_local_get_local(void)
Definition: abti_local.h:41
ABT_pool_pop
int ABT_pool_pop(ABT_pool pool, ABT_unit *p_unit)
Pop a work unit from a pool.
Definition: pool.c:870
ABT_pool_def::p_get_size
ABT_pool_get_size_fn p_get_size
Function that returns a work unit.
Definition: abt.h:2186
ABTI_pool_get_fifo_wait_def
ABTU_ret_err int ABTI_pool_get_fifo_wait_def(ABT_pool_access access, ABTI_pool_required_def *p_required_def, ABTI_pool_optional_def *p_optional_def, ABTI_pool_deprecated_def *p_deprecated_def)
Definition: fifo_wait.c:47
ABTI_STATIC_ASSERT
#define ABTI_STATIC_ASSERT(cond)
Definition: abti_error.h:35
ABT_pool_def::p_push
ABT_pool_push_fn p_push
Function that pushes a work unit to a pool.
Definition: abt.h:2200
ABTI_pool_config
Definition: abti.h:418
ABT_SUCCESS
#define ABT_SUCCESS
Error code: the routine returns successfully.
Definition: abt.h:92
ABT_pool_push
int ABT_pool_push(ABT_pool pool, ABT_unit unit)
Push a unit to a pool.
Definition: pool.c:1070
pool_get_size_wrapper
static size_t pool_get_size_wrapper(ABT_pool pool)
Definition: pool.c:1574
ABTU_ret_err
#define ABTU_ret_err
Definition: abtu.h:155
pool_get_new_id
static uint64_t pool_get_new_id(void)
Definition: pool.c:1750
ABT_pool_get_total_size
int ABT_pool_get_total_size(ABT_pool pool, size_t *size)
Get the total size of a pool.
Definition: pool.c:392
ABTI_pool_optional_def::p_push_many
ABT_pool_user_push_many_fn p_push_many
Definition: abti.h:364
ABTI_pool::deprecated_def
ABTI_pool_deprecated_def deprecated_def
Definition: abti.h:401
ABT_pool_create_basic
int ABT_pool_create_basic(ABT_pool_kind kind, ABT_pool_access access, ABT_bool automatic, ABT_pool *newpool)
Create a new pool from a predefined type.
Definition: pool.c:221
ABT_TRUE
#define ABT_TRUE
True constant for ABT_bool.
Definition: abt.h:784
ABTI_pool_get_ptr
static ABTI_pool * ABTI_pool_get_ptr(ABT_pool pool)
Definition: abti_pool.h:11
ABT_pool_push_thread
int ABT_pool_push_thread(ABT_pool pool, ABT_thread thread)
Push a work unit to a pool.
Definition: pool.c:607
ABT_POOL_ACCESS_SPMC
@ ABT_POOL_ACCESS_SPMC
Definition: abt.h:573
pool_push_threads_ex
static int pool_push_threads_ex(ABT_pool pool, const ABT_thread *threads, size_t num, ABT_pool_context pool_ctx)
Definition: pool.c:1805
pool_create_def_from_old_def
static void pool_create_def_from_old_def(const ABT_pool_def *p_def, ABTI_pool_old_def *p_old_def, ABTI_pool_required_def *p_required_def, ABTI_pool_optional_def *p_optional_def, ABTI_pool_deprecated_def *p_deprecated_def)
Definition: pool.c:1636
ABTI_sched
Definition: abti.h:319
ABT_FALSE
#define ABT_FALSE
False constant for ABT_bool.
Definition: abt.h:786
ABTI_pool_pop_many
static void ABTI_pool_pop_many(ABTI_pool *p_pool, ABT_thread *threads, size_t len, size_t *num, ABT_pool_context context)
Definition: abti_pool.h:102
ABTI_pool::access
ABT_pool_access access
Definition: abti.h:390
pool_print_all_wrapper
static void pool_print_all_wrapper(ABT_pool pool, void *arg, void(*print_f)(void *, ABT_thread))
Definition: pool.c:1626
pool_create
static ABTU_ret_err int pool_create(ABT_pool_access access, const ABTI_pool_required_def *p_required_def, const ABTI_pool_optional_def *p_optional_def, const ABTI_pool_deprecated_def *p_deprecated_def, const ABTI_pool_old_def *p_old_def, ABTI_pool_config *p_config, ABT_bool def_automatic, ABT_bool is_builtin, ABTI_pool **pp_newpool)
Definition: pool.c:1685
ABTI_pool::old_def
ABTI_pool_old_def old_def
Definition: abti.h:402
pool_print_unit_to_thread
static void pool_print_unit_to_thread(void *arg, ABT_unit unit)
Definition: pool.c:1875
ABTI_UB_ASSERT
#define ABTI_UB_ASSERT(cond)
Definition: abti_error.h:19
ABTI_pool_optional_def::p_pop_many
ABT_pool_user_pop_many_fn p_pop_many
Definition: abti.h:363
ABTI_CHECK_NULL_POOL_PTR
#define ABTI_CHECK_NULL_POOL_PTR(p)
Definition: abti_error.h:184
ABTD_atomic_fetch_add_uint64
static uint64_t ABTD_atomic_fetch_add_uint64(ABTD_atomic_uint64 *ptr, uint64_t v)
Definition: abtd_atomic.h:477
ABT_ERR_INV_POOL_KIND
#define ABT_ERR_INV_POOL_KIND
Error code: invalid pool kind.
Definition: abt.h:161
ABT_POOL_ACCESS_SPSC
@ ABT_POOL_ACCESS_SPSC
Definition: abt.h:565
ABTI_pool_reset_id
void ABTI_pool_reset_id(void)
Definition: pool.c:1512
ABTI_pool_old_def::p_pop_wait
ABT_pool_pop_wait_fn p_pop_wait
Definition: abti.h:384
ABTU_free
static void ABTU_free(void *ptr)
Definition: abtu.h:228
ABT_pool_pop_thread_ex
int ABT_pool_pop_thread_ex(ABT_pool pool, ABT_thread *thread, ABT_pool_context pool_ctx)
Pop a work unit from a pool.
Definition: pool.c:506
ABTI_unit_get_thread
static ABTI_thread * ABTI_unit_get_thread(ABTI_global *p_global, ABT_unit unit)
Definition: abti_unit.h:43
ABT_pool_set_data
int ABT_pool_set_data(ABT_pool pool, void *data)
Set user data in a pool.
Definition: pool.c:1226
ABT_pool_pop_wait_thread_ex
int ABT_pool_pop_wait_thread_ex(ABT_pool pool, ABT_thread *thread, double time_secs, ABT_pool_context pool_ctx)
Pop a work unit from a pool.
Definition: pool.c:774
ABTI_pool_config_read
ABTU_ret_err int ABTI_pool_config_read(const ABTI_pool_config *p_config, int key, void *p_val)
Definition: pool_config.c:270
ABTI_pool_get_fifo_def
ABTU_ret_err int ABTI_pool_get_fifo_def(ABT_pool_access access, ABTI_pool_required_def *p_required_def, ABTI_pool_optional_def *p_optional_def, ABTI_pool_deprecated_def *p_deprecated_def)
Definition: fifo.c:58
ABT_pool_def::u_create_from_thread
ABT_unit_create_from_thread_fn u_create_from_thread
Function that creates an ABT_unit handle that is associated with an ABT_thread handle.
Definition: abt.h:2128
ABTI_pool_print
void ABTI_pool_print(ABTI_pool *p_pool, FILE *p_os, int indent)
Definition: pool.c:1459
ABT_pool_config_var::key
int key
Definition: abt.h:1534
ABTI_pool_push
static void ABTI_pool_push(ABTI_pool *p_pool, ABT_unit unit, ABT_pool_context context)
Definition: abti_pool.h:53
ABTI_pool_user_def
Definition: abti.h:405
ABTI_pool_old_def::p_print_all
ABT_pool_print_all_fn p_print_all
Definition: abti.h:386
ABT_pool_pop_timedwait
int ABT_pool_pop_timedwait(ABT_pool pool, ABT_unit *p_unit, double abstime_secs)
Pop a unit from a pool with timed wait.
Definition: pool.c:1011
ABT_pool_free
int ABT_pool_free(ABT_pool *pool)
Free a pool.
Definition: pool.c:269
ABTI_pool_config_get_ptr
static ABTI_pool_config * ABTI_pool_config_get_ptr(ABT_pool_config config)
Definition: abti_pool_config.h:11
ABTI_local
struct ABTI_local ABTI_local
Definition: abti.h:132
ABT_pool_create
int ABT_pool_create(ABT_pool_user_def def, ABT_pool_config config, ABT_pool *newpool)
Create a new pool.
Definition: pool.c:111
ABTI_pool_user_def::required_def
ABTI_pool_required_def required_def
Definition: abti.h:414
ABTI_pool_is_empty
static ABT_bool ABTI_pool_is_empty(ABTI_pool *p_pool)
Definition: abti_pool.h:136
ABTI_pool::id
uint64_t id
Definition: abti.h:397
ABTI_CHECK_TRUE
#define ABTI_CHECK_TRUE(cond, abt_errno)
Definition: abti_error.h:146
ABTI_global
Definition: abti.h:223
ABTI_pool_free
void ABTI_pool_free(ABTI_pool *p_pool)
Definition: pool.c:1433
ABT_pool_def::p_init
ABT_pool_init_fn p_init
Function that frees a work unit.
Definition: abt.h:2168
ABTI_pool::optional_def
ABTI_pool_optional_def optional_def
Definition: abti.h:400
ABT_UNIT_NULL
#define ABT_UNIT_NULL
Definition: abt.h:1104
ABTI_ythread_create_sched
ABTU_ret_err int ABTI_ythread_create_sched(ABTI_global *p_global, ABTI_local *p_local, ABTI_pool *p_pool, ABTI_sched *p_sched)
Definition: thread.c:2593
pool_pop_wait_thread_ex
static int pool_pop_wait_thread_ex(ABT_pool pool, ABT_thread *thread, double time_secs, ABT_pool_context pool_ctx)
Definition: pool.c:1852
ABTI_pool_deprecated_def
Definition: abti.h:368
ABTI_pool_required_def::p_is_empty
ABT_pool_user_is_empty_fn p_is_empty
Definition: abti.h:352
ABT_pool_pop_wait_thread
int ABT_pool_pop_wait_thread(ABT_pool pool, ABT_thread *thread, double time_secs)
Pop a work unit from a pool.
Definition: pool.c:736
pool_push_many_wrapper
static void pool_push_many_wrapper(ABT_pool pool, const ABT_unit *units, size_t num_units, ABT_pool_context context)
Definition: pool.c:1615
ABTI_pool_user_def_is_new
ABT_bool ABTI_pool_user_def_is_new(const ABT_pool_user_def def)
Definition: pool_user_def.c:368
ABT_pool_kind
ABT_pool_kind
Predefined pool type.
Definition: abt.h:514
pool_free_wrapper
static void pool_free_wrapper(ABT_pool pool)
Definition: pool.c:1568
ABTI_thread_get_ptr
static ABTI_thread * ABTI_thread_get_ptr(ABT_thread thread)
Definition: abti_thread.h:9
pool_print_thread_to_unit_arg_t::arg
void * arg
Definition: pool.c:33
ABTI_pool_get_handle
static ABT_pool ABTI_pool_get_handle(ABTI_pool *p_pool)
Definition: abti_pool.h:26
ABTI_pool_required_def::p_create_unit
ABT_pool_user_create_unit_fn p_create_unit
Definition: abti.h:350
ABT_pool_get_access
int ABT_pool_get_access(ABT_pool pool, ABT_pool_access *access)
Get an access type of a pool.
Definition: pool.c:307
ABTI_pool_old_def::p_get_size
ABT_pool_get_size_fn p_get_size
Definition: abti.h:381
ABTI_pool_optional_def::p_free
ABT_pool_user_free_fn p_free
Definition: abti.h:360
ABT_pool_push_thread_ex
int ABT_pool_push_thread_ex(ABT_pool pool, ABT_thread thread, ABT_pool_context pool_ctx)
Push a work unit to a pool.
Definition: pool.c:638
pool_pop_many_wrapper
static void pool_pop_many_wrapper(ABT_pool pool, ABT_thread *threads, size_t max_threads, size_t *num_popped, ABT_pool_context context)
Definition: pool.c:1595
ABTI_UB_ASSERT_BOOL
#define ABTI_UB_ASSERT_BOOL(bool_val)
Definition: abti_error.h:26
ABT_pool_push_threads_ex
int ABT_pool_push_threads_ex(ABT_pool pool, const ABT_thread *threads, size_t num, ABT_pool_context pool_ctx)
Push work units to a pool.
Definition: pool.c:705
ABT_pool_get_id
int ABT_pool_get_id(ABT_pool pool, int *id)
Get ID of a pool.
Definition: pool.c:1373
ABT_pool_pop_threads
int ABT_pool_pop_threads(ABT_pool pool, ABT_thread *threads, size_t len, size_t *num)
Pop work units from a pool.
Definition: pool.c:536
ABT_pool_access
ABT_pool_access
Pool access type.
Definition: abt.h:556