8 static int ABTI_task_create(ABTI_local *p_local, ABTI_pool *p_pool,
9 void (*task_func)(
void *),
void *arg,
10 ABTI_sched *p_sched,
int refcount,
11 ABTI_task **pp_newtask);
12 static int ABTI_task_revive(ABTI_local *p_local, ABTI_pool *p_pool,
13 void (*task_func)(
void *),
void *arg,
15 static inline uint64_t ABTI_task_get_new_id(
void);
48 ABTI_local *p_local = ABTI_local_get_local();
50 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
51 ABTI_CHECK_NULL_POOL_PTR(p_pool);
53 int refcount = (newtask != NULL) ? 1 : 0;
54 abt_errno = ABTI_task_create(p_local, p_pool, task_func, arg, NULL,
55 refcount, &p_newtask);
56 ABTI_CHECK_ERROR(abt_errno);
60 *newtask = ABTI_task_get_handle(p_newtask);
74 int ABTI_task_create_sched(ABTI_local *p_local, ABTI_pool *p_pool,
80 void *arg = (
void *)ABTI_sched_get_handle(p_sched);
82 if (p_sched->p_task) {
84 ABTI_task_revive(p_local, p_pool, (
void (*)(
void *))p_sched->run,
85 arg, p_sched->p_task);
86 ABTI_CHECK_ERROR(abt_errno);
92 ABTI_task_create(p_local, p_pool, (
void (*)(
void *))p_sched->run, arg,
93 p_sched, 1, &p_newtask);
94 ABTI_CHECK_ERROR(abt_errno);
139 ABTI_local *p_local = ABTI_local_get_local();
140 ABTI_task *p_newtask;
142 ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
143 ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
146 ABTI_pool *p_pool = ABTI_xstream_get_main_pool(p_xstream);
147 int refcount = (newtask != NULL) ? 1 : 0;
148 abt_errno = ABTI_task_create(p_local, p_pool, task_func, arg, NULL,
149 refcount, &p_newtask);
150 ABTI_CHECK_ERROR(abt_errno);
154 *newtask = ABTI_task_get_handle(p_newtask);
188 ABTI_local *p_local = ABTI_local_get_local();
190 ABTI_task *p_task = ABTI_task_get_ptr(*task);
191 ABTI_CHECK_NULL_TASK_PTR(p_task);
193 ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
194 ABTI_CHECK_NULL_POOL_PTR(p_pool);
196 abt_errno = ABTI_task_revive(p_local, p_pool, task_func, arg, p_task);
197 ABTI_CHECK_ERROR(abt_errno);
223 ABTI_local *p_local = ABTI_local_get_local();
225 ABTI_task *p_task = ABTI_task_get_ptr(h_task);
226 ABTI_CHECK_NULL_TASK_PTR(p_task);
229 while (ABTD_atomic_acquire_load_int(&p_task->state) !=
231 #ifndef ABT_CONFIG_DISABLE_EXT_THREAD 237 ABTI_thread_yield(&p_local, p_local->p_thread);
241 ABTI_task_free(p_local, p_task);
269 ABTI_local *p_local = ABTI_local_get_local();
271 ABTI_task *p_task = ABTI_task_get_ptr(task);
272 ABTI_CHECK_NULL_TASK_PTR(p_task);
275 while (ABTD_atomic_acquire_load_int(&p_task->state) !=
277 #ifndef ABT_CONFIG_DISABLE_EXT_THREAD 283 ABTI_thread_yield(&p_local, p_local->p_thread);
304 #ifdef ABT_CONFIG_DISABLE_TASK_CANCEL 308 ABTI_task *p_task = ABTI_task_get_ptr(task);
309 ABTI_CHECK_NULL_TASK_PTR(p_task);
312 ABTI_task_set_request(p_task, ABTI_TASK_REQ_CANCEL);
340 ABTI_local *p_local = ABTI_local_get_local();
342 #ifndef ABT_CONFIG_DISABLE_EXT_THREAD 351 if (p_local == NULL) {
358 ABTI_task *p_task = p_local->p_task;
359 if (p_task != NULL) {
360 *task = ABTI_task_get_handle(p_task);
385 ABTI_local *p_local = ABTI_local_get_local();
387 #ifndef ABT_CONFIG_DISABLE_EXT_THREAD 395 if (p_local == NULL) {
401 ABTI_task *p_task = p_local->p_task;
402 if (p_task != NULL) {
403 *
id = ABTI_task_get_id(p_task);
427 ABTI_task *p_task = ABTI_task_get_ptr(task);
428 ABTI_CHECK_NULL_TASK_PTR(p_task);
431 *xstream = ABTI_xstream_get_handle(p_task->p_xstream);
454 ABTI_task *p_task = ABTI_task_get_ptr(task);
455 ABTI_CHECK_NULL_TASK_PTR(p_task);
458 *state = (
ABT_task_state)ABTD_atomic_acquire_load_int(&p_task->state);
484 ABTI_task *p_task = ABTI_task_get_ptr(task);
485 ABTI_CHECK_NULL_TASK_PTR(p_task);
488 *pool = ABTI_pool_get_handle(p_task->p_pool);
516 ABTI_task *p_task = ABTI_task_get_ptr(task);
517 ABTI_CHECK_NULL_TASK_PTR(p_task);
519 ABTI_ASSERT(p_task->p_pool);
520 *
id = (int)(p_task->p_pool->id);
548 #ifndef ABT_CONFIG_DISABLE_MIGRATION 550 ABTI_task *p_task = ABTI_task_get_ptr(task);
551 ABTI_CHECK_NULL_TASK_PTR(p_task);
553 p_task->migratable = flag;
582 #ifndef ABT_CONFIG_DISABLE_MIGRATION 584 ABTI_task *p_task = ABTI_task_get_ptr(task);
585 ABTI_CHECK_NULL_TASK_PTR(p_task);
587 *flag = p_task->migratable;
617 ABTI_task *p_task1 = ABTI_task_get_ptr(task1);
618 ABTI_task *p_task2 = ABTI_task_get_ptr(task2);
638 ABTI_task *p_task = ABTI_task_get_ptr(task);
639 ABTI_CHECK_NULL_TASK_PTR(p_task);
641 *task_id = ABTI_task_get_id(p_task);
667 ABTI_task *p_task = ABTI_task_get_ptr(task);
668 ABTI_CHECK_NULL_TASK_PTR(p_task);
670 *arg = p_task->p_arg;
684 static int ABTI_task_create(ABTI_local *p_local, ABTI_pool *p_pool,
685 void (*task_func)(
void *),
void *arg,
686 ABTI_sched *p_sched,
int refcount,
687 ABTI_task **pp_newtask)
690 ABTI_task *p_newtask;
692 ABTI_CHECK_NULL_POOL_PTR(p_pool);
695 p_newtask = ABTI_mem_alloc_task(p_local);
697 p_newtask->p_xstream = NULL;
699 ABTD_atomic_relaxed_store_uint32(&p_newtask->request, 0);
700 p_newtask->f_task = task_func;
701 p_newtask->p_arg = arg;
702 #ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED 703 p_newtask->is_sched = p_sched;
705 p_newtask->p_pool = p_pool;
706 p_newtask->refcount = refcount;
707 p_newtask->p_keytable = NULL;
708 #ifndef ABT_CONFIG_DISABLE_MIGRATION 711 p_newtask->id = ABTI_TASK_INIT_ID;
714 h_newtask = ABTI_task_get_handle(p_newtask);
715 p_newtask->unit = p_pool->u_create_from_task(h_newtask);
717 LOG_EVENT(
"[T%" PRIu64
"] created\n", ABTI_task_get_id(p_newtask));
720 #ifdef ABT_CONFIG_DISABLE_POOL_PRODUCER_CHECK 721 ABTI_pool_push(p_pool, p_newtask->unit);
723 abt_errno = ABTI_pool_push(p_pool, p_newtask->unit,
724 ABTI_self_get_native_thread_id(p_local));
726 ABTI_task_free(p_local, p_newtask);
732 *pp_newtask = p_newtask;
742 static int ABTI_task_revive(ABTI_local *p_local, ABTI_pool *p_pool,
743 void (*task_func)(
void *),
void *arg,
748 ABTI_CHECK_TRUE(ABTD_atomic_relaxed_load_int(&p_task->state) ==
752 p_task->p_xstream = NULL;
754 ABTD_atomic_relaxed_store_uint32(&p_task->request, 0);
755 p_task->f_task = task_func;
757 p_task->refcount = 1;
758 p_task->p_keytable = NULL;
760 if (p_task->p_pool != p_pool) {
762 p_task->p_pool->u_free(&p_task->unit);
765 p_task->p_pool = p_pool;
768 ABT_task task = ABTI_task_get_handle(p_task);
769 p_task->unit = p_pool->u_create_from_task(task);
772 LOG_EVENT(
"[T%" PRIu64
"] revived\n", ABTI_task_get_id(p_task));
775 #ifdef ABT_CONFIG_DISABLE_POOL_PRODUCER_CHECK 776 ABTI_pool_push(p_pool, p_task->unit);
778 abt_errno = ABTI_pool_push(p_pool, p_task->unit,
779 ABTI_self_get_native_thread_id(p_local));
780 ABTI_CHECK_ERROR(abt_errno);
791 void ABTI_task_free(ABTI_local *p_local, ABTI_task *p_task)
793 LOG_EVENT(
"[T%" PRIu64
"] freed\n", ABTI_task_get_id(p_task));
796 p_task->p_pool->u_free(&p_task->unit);
799 if (p_task->p_keytable) {
800 ABTI_ktable_free(p_task->p_keytable);
803 ABTI_mem_free_task(p_local, p_task);
806 void ABTI_task_print(ABTI_task *p_task, FILE *p_os,
int indent)
810 if (p_task == NULL) {
811 fprintf(p_os,
"%s== NULL TASKLET ==\n", prefix);
815 ABTI_xstream *p_xstream = p_task->p_xstream;
816 int xstream_rank = p_xstream ? p_xstream->rank : 0;
818 switch (ABTD_atomic_acquire_load_int(&p_task->state)) {
826 state =
"TERMINATED";
833 "%s== TASKLET (%p) ==\n" 834 "%sid : %" PRIu64
"\n" 837 #ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED
841 #ifndef ABT_CONFIG_DISABLE_MIGRATION
848 prefix, (
void *)p_task, prefix, ABTI_task_get_id(p_task), prefix,
849 state, prefix, (
void *)p_task->p_xstream, xstream_rank,
850 #ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED
851 prefix, (
void *)p_task->is_sched,
853 prefix, (
void *)p_task->p_pool,
854 #ifndef ABT_CONFIG_DISABLE_MIGRATION
855 prefix, (p_task->migratable ==
ABT_TRUE) ?
"TRUE" :
"FALSE",
857 prefix, p_task->refcount, prefix,
858 ABTD_atomic_acquire_load_uint32(&p_task->request), prefix,
859 p_task->p_arg, prefix, (
void *)p_task->p_keytable);
866 static ABTD_atomic_uint64
g_task_id = ABTD_ATOMIC_UINT64_STATIC_INITIALIZER(0);
867 void ABTI_task_reset_id(
void)
869 ABTD_atomic_release_store_uint64(&g_task_id, 0);
872 uint64_t ABTI_task_get_id(ABTI_task *p_task)
874 if (p_task->id == ABTI_TASK_INIT_ID) {
875 p_task->id = ABTI_task_get_new_id();
884 static inline uint64_t ABTI_task_get_new_id(
void)
886 return ABTD_atomic_fetch_add_uint64(&g_task_id, 1);
struct ABT_xstream_opaque * ABT_xstream
char * ABTU_get_indent_str(int indent)
int ABT_task_cancel(ABT_task task)
Request the cancellation of the target task.
struct ABT_task_opaque * ABT_task
int ABT_task_create(ABT_pool pool, void(*task_func)(void *), void *arg, ABT_task *newtask)
Create a new task and return its handle through newtask.
int ABT_task_join(ABT_task task)
Wait for the tasklet to terminate.
int ABT_task_self(ABT_task *task)
Return the handle of the calling tasklet.
struct ABT_pool_opaque * ABT_pool
int ABT_task_create_on_xstream(ABT_xstream xstream, void(*task_func)(void *), void *arg, ABT_task *newtask)
Create a new tasklet associated with the target ES (xstream).
int ABT_task_equal(ABT_task task1, ABT_task task2, ABT_bool *result)
Compare two tasklet handles for equality.
#define HANDLE_ERROR_FUNC_WITH_CODE(n)
int ABT_task_get_id(ABT_task task, uint64_t *task_id)
Get the tasklet's id.
ABTI_global * gp_ABTI_global
int ABT_task_get_last_pool(ABT_task task, ABT_pool *pool)
Return the last pool of task.
#define LOG_EVENT(fmt,...)
int ABT_task_set_migratable(ABT_task task, ABT_bool flag)
Set the tasklet's migratability.
#define ABT_ERR_UNINITIALIZED
int ABT_task_get_arg(ABT_task task, void **arg)
Retrieve the argument for the tasklet function.
static ABTD_atomic_uint64 g_task_id
#define ABT_ERR_FEATURE_NA
int ABT_task_get_state(ABT_task task, ABT_task_state *state)
Return the state of task.
#define ABT_ERR_MIGRATION_NA
int ABT_task_get_last_pool_id(ABT_task task, int *id)
Get the last pool's ID of the tasklet.
int ABT_task_self_id(uint64_t *id)
Return the ID of the calling tasklet.
int ABT_task_free(ABT_task *task)
Release the task object associated with task handle.
#define ABT_ERR_INV_XSTREAM
static void ABTU_free(void *ptr)
int ABT_task_is_migratable(ABT_task task, ABT_bool *flag)
Get the tasklet's migratability.
int ABT_task_get_xstream(ABT_task task, ABT_xstream *xstream)
Get the ES associated with the target tasklet.
int ABT_task_revive(ABT_pool pool, void(*task_func)(void *), void *arg, ABT_task *task)
Revive the tasklet.