10                                      ABTI_sched_config *p_config,
 
   12                                      ABTI_sched **pp_newsched);
 
   14 #ifdef ABT_CONFIG_USE_DEBUG_LOG 
   15 static inline uint64_t sched_get_new_id(
void);
 
   94     ABTI_UB_ASSERT(ABTI_initialized());
 
   96     ABTI_UB_ASSERT(def->
run);
 
   97     ABTI_UB_ASSERT(pools || num_pools == 0);
 
  100 #ifndef ABT_CONFIG_ENABLE_VER_20_API 
  104     ABTI_UB_ASSERT(newsched);
 
  110     ABTI_sched_config *p_config = ABTI_sched_config_get_ptr(config);
 
  112         sched_create(def, num_pools, pools, p_config, def_automatic, &p_sched);
 
  113     ABTI_CHECK_ERROR(abt_errno);
 
  116     *newsched = ABTI_sched_get_handle(p_sched);
 
  185     ABTI_UB_ASSERT(ABTI_initialized());
 
  187 #ifndef ABT_CONFIG_ENABLE_VER_20_API 
  191     ABTI_UB_ASSERT(newsched);
 
  195     ABTI_sched *p_newsched;
 
  196     ABTI_sched_config *p_config = ABTI_sched_config_get_ptr(config);
 
  197     int abt_errno = ABTI_sched_create_basic(predef, num_pools, pools, p_config,
 
  199     ABTI_CHECK_ERROR(abt_errno);
 
  200     *newsched = ABTI_sched_get_handle(p_newsched);
 
  247     ABTI_UB_ASSERT(ABTI_initialized());
 
  248     ABTI_UB_ASSERT(sched);
 
  250     ABTI_global *p_global;
 
  251     ABTI_SETUP_GLOBAL(&p_global);
 
  252     ABTI_local *p_local = ABTI_local_get_local();
 
  253     ABTI_sched *p_sched = ABTI_sched_get_ptr(*sched);
 
  254     ABTI_CHECK_NULL_SCHED_PTR(p_sched);
 
  255 #ifndef ABT_CONFIG_ENABLE_VER_20_API 
  256     ABTI_CHECK_TRUE(p_sched->used == ABTI_SCHED_NOT_USED, 
ABT_ERR_SCHED);
 
  258     ABTI_UB_ASSERT(p_sched->used == ABTI_SCHED_NOT_USED);
 
  262     ABTI_sched_free(p_global, p_local, p_sched, 
ABT_FALSE);
 
  293     ABTI_UB_ASSERT(ABTI_initialized());
 
  294     ABTI_UB_ASSERT(num_pools);
 
  296     ABTI_sched *p_sched = ABTI_sched_get_ptr(sched);
 
  297     ABTI_CHECK_NULL_SCHED_PTR(p_sched);
 
  299     *num_pools = p_sched->num_pools;
 
  342     ABTI_UB_ASSERT(ABTI_initialized());
 
  343     ABTI_UB_ASSERT(pools || max_pools > 0);
 
  345     ABTI_sched *p_sched = ABTI_sched_get_ptr(sched);
 
  346     ABTI_CHECK_NULL_SCHED_PTR(p_sched);
 
  349 #ifndef ABT_CONFIG_ENABLE_VER_20_API 
  350     ABTI_CHECK_TRUE((
size_t)(idx + max_pools) <= p_sched->num_pools,
 
  355     for (p = idx; p < (size_t)idx + max_pools; p++) {
 
  356         if (p >= p_sched->num_pools) {
 
  360         pools[p - idx] = p_sched->pools[p];
 
  397     ABTI_UB_ASSERT(ABTI_initialized());
 
  399     ABTI_sched *p_sched = ABTI_sched_get_ptr(sched);
 
  400     ABTI_CHECK_NULL_SCHED_PTR(p_sched);
 
  402     ABTI_sched_finish(p_sched);
 
  436     ABTI_UB_ASSERT(ABTI_initialized());
 
  438     ABTI_sched *p_sched = ABTI_sched_get_ptr(sched);
 
  439     ABTI_CHECK_NULL_SCHED_PTR(p_sched);
 
  441     ABTI_sched_exit(p_sched);
 
  484     ABTI_UB_ASSERT(ABTI_initialized());
 
  485     ABTI_UB_ASSERT(stop);
 
  487 #ifndef ABT_CONFIG_ENABLE_VER_20_API 
  490     ABTI_sched *p_sched = ABTI_sched_get_ptr(sched);
 
  491     ABTI_CHECK_NULL_SCHED_PTR(p_sched);
 
  492 #ifndef ABT_CONFIG_ENABLE_VER_20_API 
  496     *stop = ABTI_sched_has_to_stop(p_sched);
 
  524     ABTI_UB_ASSERT(ABTI_initialized());
 
  526     ABTI_sched *p_sched = ABTI_sched_get_ptr(sched);
 
  527     ABTI_CHECK_NULL_SCHED_PTR(p_sched);
 
  529     p_sched->data = data;
 
  558     ABTI_UB_ASSERT(ABTI_initialized());
 
  559     ABTI_UB_ASSERT(data);
 
  561     ABTI_sched *p_sched = ABTI_sched_get_ptr(sched);
 
  562     ABTI_CHECK_NULL_SCHED_PTR(p_sched);
 
  564     *data = p_sched->data;
 
  605     ABTI_UB_ASSERT(ABTI_initialized());
 
  606     ABTI_UB_ASSERT(size);
 
  608 #ifndef ABT_CONFIG_ENABLE_VER_20_API 
  612     ABTI_sched *p_sched = ABTI_sched_get_ptr(sched);
 
  613     ABTI_CHECK_NULL_SCHED_PTR(p_sched);
 
  616     for (p = 0; p < p_sched->num_pools; p++) {
 
  617         ABTI_pool *p_pool = ABTI_pool_get_ptr(p_sched->pools[p]);
 
  618         ABTI_CHECK_TRUE(p_pool->optional_def.p_get_size, 
ABT_ERR_POOL);
 
  622     size_t pool_size = 0;
 
  623     for (p = 0; p < p_sched->num_pools; p++) {
 
  624         ABTI_pool *p_pool = ABTI_pool_get_ptr(p_sched->pools[p]);
 
  625         pool_size += ABTI_pool_get_size(p_pool);
 
  670     ABTI_UB_ASSERT(ABTI_initialized());
 
  671     ABTI_UB_ASSERT(size);
 
  673 #ifndef ABT_CONFIG_ENABLE_VER_20_API 
  677     ABTI_sched *p_sched = ABTI_sched_get_ptr(sched);
 
  678     ABTI_CHECK_NULL_SCHED_PTR(p_sched);
 
  681     for (p = 0; p < p_sched->num_pools; p++) {
 
  682         ABTI_pool *p_pool = ABTI_pool_get_ptr(p_sched->pools[p]);
 
  683         ABTI_CHECK_TRUE(p_pool->optional_def.p_get_size, 
ABT_ERR_POOL);
 
  687     size_t pool_size = 0;
 
  688     for (p = 0; p < p_sched->num_pools; p++) {
 
  689         ABTI_pool *p_pool = ABTI_pool_get_ptr(p_sched->pools[p]);
 
  690         pool_size += ABTI_pool_get_total_size(p_pool);
 
  700 void ABTI_sched_finish(ABTI_sched *p_sched)
 
  702     ABTI_sched_set_request(p_sched, ABTI_SCHED_REQ_FINISH);
 
  705 void ABTI_sched_exit(ABTI_sched *p_sched)
 
  707     ABTI_sched_set_request(p_sched, ABTI_SCHED_REQ_EXIT);
 
  712                                          ABTI_sched_config *p_config,
 
  713                                          ABTI_sched **pp_newsched)
 
  729             ABTI_CHECK_ERROR(abt_errno);
 
  732             for (p = 0; p < num_pools; p++) {
 
  734                     ABTI_pool *p_newpool;
 
  738                     if (ABTI_IS_ERROR_CHECK_ENABLED &&
 
  742                         for (i = 0; i < p; i++) {
 
  746                             ABTI_pool_free(ABTI_pool_get_ptr(pool_list[i]));
 
  749                         ABTI_HANDLE_ERROR(abt_errno);
 
  751                     pool_list[p] = ABTI_pool_get_handle(p_newpool);
 
  753                     pool_list[p] = pools[p];
 
  765                 abt_errno = 
sched_create(ABTI_sched_get_basic_def(), num_pools,
 
  766                                          pool_list, p_config, def_automatic,
 
  770                 abt_errno = 
sched_create(ABTI_sched_get_basic_wait_def(),
 
  771                                          num_pools, pool_list, p_config,
 
  772                                          def_automatic, pp_newsched);
 
  775                 abt_errno = 
sched_create(ABTI_sched_get_prio_def(), num_pools,
 
  776                                          pool_list, p_config, def_automatic,
 
  780                 abt_errno = 
sched_create(ABTI_sched_get_randws_def(), num_pools,
 
  781                                          pool_list, p_config, def_automatic,
 
  788         if (ABTI_IS_ERROR_CHECK_ENABLED && abt_errno != 
ABT_SUCCESS) {
 
  791             for (i = 0; i < num_pools; i++) {
 
  795                 ABTI_pool_free(ABTI_pool_get_ptr(pool_list[i]));
 
  798             ABTI_HANDLE_ERROR(abt_errno);
 
  814                 num_pools = ABTI_SCHED_NUM_PRIO;
 
  821                 ABTI_CHECK_ERROR(abt_errno);
 
  827         ABT_pool pool_list[ABTI_SCHED_NUM_PRIO];
 
  831         for (p = 0; p < num_pools; p++)
 
  833         for (p = 0; p < num_pools; p++) {
 
  834             ABTI_pool *p_newpool;
 
  836                 ABTI_pool_create_basic(kind, def_access, 
ABT_TRUE, &p_newpool);
 
  837             if (ABTI_IS_ERROR_CHECK_ENABLED && abt_errno != 
ABT_SUCCESS) {
 
  840                 for (i = 0; i < p; i++) {
 
  842                     ABTI_pool_free(ABTI_pool_get_ptr(pool_list[i]));
 
  844                 ABTI_HANDLE_ERROR(abt_errno);
 
  846             pool_list[p] = ABTI_pool_get_handle(p_newpool);
 
  853                 abt_errno = 
sched_create(ABTI_sched_get_basic_def(), num_pools,
 
  854                                          pool_list, p_config, def_automatic,
 
  858                 abt_errno = 
sched_create(ABTI_sched_get_basic_wait_def(),
 
  859                                          num_pools, pool_list, p_config,
 
  860                                          def_automatic, pp_newsched);
 
  863                 abt_errno = 
sched_create(ABTI_sched_get_prio_def(), num_pools,
 
  864                                          pool_list, p_config, def_automatic,
 
  868                 abt_errno = 
sched_create(ABTI_sched_get_randws_def(), num_pools,
 
  869                                          pool_list, p_config, def_automatic,
 
  876         if (ABTI_IS_ERROR_CHECK_ENABLED && abt_errno != 
ABT_SUCCESS) {
 
  879             for (i = 0; i < num_pools; i++) {
 
  881                 ABTI_pool_free(ABTI_pool_get_ptr(pool_list[i]));
 
  883             ABTI_HANDLE_ERROR(abt_errno);
 
  889 void ABTI_sched_free(ABTI_global *p_global, ABTI_local *p_local,
 
  890                      ABTI_sched *p_sched, 
ABT_bool force_free)
 
  892     ABTI_ASSERT(p_sched->used == ABTI_SCHED_NOT_USED);
 
  895         p_sched->free(ABTI_sched_get_handle(p_sched));
 
  900     for (p = 0; p < p_sched->num_pools; p++) {
 
  901         ABTI_pool *p_pool = ABTI_pool_get_ptr(p_sched->pools[p]);
 
  908         int32_t num_scheds = ABTI_pool_release(p_pool);
 
  909         if ((p_pool->automatic == 
ABT_TRUE && num_scheds == 0) || force_free) {
 
  910             ABTI_pool_free(p_pool);
 
  916     if (p_sched->p_ythread) {
 
  917         ABTI_thread_free(p_global, p_local, &p_sched->p_ythread->thread);
 
  920     p_sched->data = NULL;
 
  925 ABT_bool ABTI_sched_has_to_stop(ABTI_sched *p_sched)
 
  928     if (ABTD_atomic_acquire_load_uint32(&p_sched->request) &
 
  929         ABTI_SCHED_REQ_EXIT) {
 
  933     if (!ABTI_sched_has_unit(p_sched)) {
 
  934         if (ABTD_atomic_acquire_load_uint32(&p_sched->request) &
 
  935             (ABTI_SCHED_REQ_FINISH | ABTI_SCHED_REQ_REPLACE)) {
 
  937             if (!ABTI_sched_has_unit(p_sched))
 
  939         } 
else if (p_sched->used == ABTI_SCHED_IN_POOL) {
 
  948 ABT_bool ABTI_sched_has_unit(ABTI_sched *p_sched)
 
  955     size_t p, num_pools = p_sched->num_pools;
 
  956     for (p = 0; p < num_pools; p++) {
 
  958         ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
 
  959         if (!ABTI_pool_is_empty(p_pool))
 
  961         switch (p_pool->access) {
 
  963                 if (ABTD_atomic_acquire_load_int32(&p_pool->num_blocked))
 
  970                 if (ABTD_atomic_acquire_load_int32(&p_pool->num_scheds) == 1) {
 
  971                     if (ABTD_atomic_acquire_load_int32(&p_pool->num_blocked))
 
  983 ABTU_ret_err int ABTI_sched_get_migration_pool(ABTI_sched *p_sched,
 
  984                                                ABTI_pool *source_pool,
 
  988     if (p_sched->get_migr_pool == NULL) {
 
  990         *pp_pool = ABTI_pool_get_ptr(p_sched->pools[0]);
 
  992         ABT_sched sched = ABTI_sched_get_handle(p_sched);
 
  993         ABTI_pool *p_pool = ABTI_pool_get_ptr(p_sched->get_migr_pool(sched));
 
 1000 void ABTI_sched_print(ABTI_sched *p_sched, FILE *p_os, 
int indent,
 
 1003     if (p_sched == NULL) {
 
 1004         fprintf(p_os, 
"%*s== NULL SCHED ==\n", indent, 
"");
 
 1006         ABTI_sched_kind kind;
 
 1007         const char *kind_str, *used;
 
 1009         kind = p_sched->kind;
 
 1012         } 
else if (kind == 
sched_get_kind(ABTI_sched_get_basic_wait_def())) {
 
 1013             kind_str = 
"BASIC_WAIT";
 
 1016         } 
else if (kind == 
sched_get_kind(ABTI_sched_get_randws_def())) {
 
 1017             kind_str = 
"RANDWS";
 
 1022         switch (p_sched->used) {
 
 1023             case ABTI_SCHED_NOT_USED:
 
 1026             case ABTI_SCHED_MAIN:
 
 1029             case ABTI_SCHED_IN_POOL:
 
 1038                 "%*s== SCHED (%p) ==\n" 
 1039 #ifdef ABT_CONFIG_USE_DEBUG_LOG
 
 1040                 "%*sid       : %" PRIu64 
"\n" 
 1042                 "%*skind     : %" PRIxPTR 
" (%s)\n" 
 1044                 "%*sautomatic: %s\n" 
 1045                 "%*srequest  : 0x%x\n" 
 1046                 "%*snum_pools: %zu\n" 
 1047                 "%*shas_unit : %s\n" 
 1050                 indent, 
"", (
void *)p_sched,
 
 1051 #ifdef ABT_CONFIG_USE_DEBUG_LOG
 
 1052                 indent, 
"", p_sched->id,
 
 1054                 indent, 
"", p_sched->kind, kind_str, indent, 
"", used, indent,
 
 1055                 "", (p_sched->automatic == 
ABT_TRUE) ? 
"TRUE" : 
"FALSE", indent,
 
 1056                 "", ABTD_atomic_acquire_load_uint32(&p_sched->request), indent,
 
 1057                 "", p_sched->num_pools, indent, 
"",
 
 1058                 (ABTI_sched_has_unit(p_sched) ? 
"TRUE" : 
"FALSE"), indent, 
"",
 
 1059                 (
void *)p_sched->p_ythread, indent, 
"", p_sched->data);
 
 1062             for (i = 0; i < p_sched->num_pools; i++) {
 
 1063                 ABTI_pool *p_pool = ABTI_pool_get_ptr(p_sched->pools[i]);
 
 1064                 ABTI_pool_print(p_pool, p_os, indent + 2);
 
 1071 static ABTD_atomic_uint64 
g_sched_id = ABTD_ATOMIC_UINT64_STATIC_INITIALIZER(0);
 
 1072 void ABTI_sched_reset_id(
void)
 
 1074     ABTD_atomic_relaxed_store_uint64(&
g_sched_id, 0);
 
 1083     return (ABTI_sched_kind)def;
 
 1088                                      ABTI_sched_config *p_config,
 
 1090                                      ABTI_sched **pp_newsched)
 
 1092     ABTI_sched *p_sched;
 
 1095     abt_errno = 
ABTU_malloc(
sizeof(ABTI_sched), (
void **)&p_sched);
 
 1096     ABTI_CHECK_ERROR(abt_errno);
 
 1099     ABT_bool automatic = def_automatic;
 
 1101         int automatic_val = 0;
 
 1113     if (ABTI_IS_ERROR_CHECK_ENABLED && abt_errno != 
ABT_SUCCESS) {
 
 1117     for (p = 0; p < num_pools; p++) {
 
 1119             ABTI_pool *p_newpool;
 
 1123             if (ABTI_IS_ERROR_CHECK_ENABLED && abt_errno != 
ABT_SUCCESS) {
 
 1125                 for (i = 0; i < p; i++) {
 
 1127                         ABTI_pool_free(ABTI_pool_get_ptr(pool_list[i]));
 
 1133             pool_list[p] = ABTI_pool_get_handle(p_newpool);
 
 1135             pool_list[p] = pools[p];
 
 1139     for (p = 0; p < num_pools; p++) {
 
 1140         ABTI_pool_retain(ABTI_pool_get_ptr(pool_list[p]));
 
 1143     p_sched->used = ABTI_SCHED_NOT_USED;
 
 1144     p_sched->automatic = automatic;
 
 1146     p_sched->p_replace_sched = NULL;
 
 1147     p_sched->p_replace_waiter = NULL;
 
 1148     ABTD_atomic_relaxed_store_uint32(&p_sched->request, 0);
 
 1149     p_sched->pools = pool_list;
 
 1150     p_sched->num_pools = num_pools;
 
 1151     p_sched->type = def->
type;
 
 1152     p_sched->p_ythread = NULL;
 
 1153     p_sched->data = NULL;
 
 1155     p_sched->init = def->
init;
 
 1156     p_sched->run = def->
run;
 
 1157     p_sched->free = def->
free;
 
 1160 #ifdef ABT_CONFIG_USE_DEBUG_LOG 
 1161     p_sched->id = sched_get_new_id();
 
 1165     ABT_sched newsched = ABTI_sched_get_handle(p_sched);
 
 1168     if (p_sched->init) {
 
 1170         abt_errno = p_sched->init(newsched, config);
 
 1171         if (ABTI_IS_ERROR_CHECK_ENABLED && abt_errno != 
ABT_SUCCESS) {
 
 1172             for (p = 0; p < num_pools; p++) {
 
 1174                     ABTI_pool_free(ABTI_pool_get_ptr(pool_list[p]));
 
 1176                     ABTI_pool_release(ABTI_pool_get_ptr(pool_list[p]));
 
 1185     *pp_newsched = p_sched;
 
 1190 #ifdef ABT_CONFIG_USE_DEBUG_LOG 
 1191 static inline uint64_t sched_get_new_id(
void)
 
 1193     return ABTD_atomic_fetch_add_uint64(&
g_sched_id, 1);