ARGOBOTS  1059a7c2eb7e3f99f736a9c3a4f6ea476ac1b804
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
task.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 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_thread **pp_newtask);
12 
40 int ABT_task_create(ABT_pool pool, void (*task_func)(void *), void *arg,
41  ABT_task *newtask)
42 {
43  ABTI_local *p_local = ABTI_local_get_local();
44  ABTI_thread *p_newtask;
45  ABTI_pool *p_pool = ABTI_pool_get_ptr(pool);
47 
48  int refcount = (newtask != NULL) ? 1 : 0;
49  int abt_errno = task_create(p_local, p_pool, task_func, arg, NULL, refcount,
50  &p_newtask);
51  ABTI_CHECK_ERROR(abt_errno);
52 
53  /* Return value */
54  if (newtask)
55  *newtask = ABTI_thread_get_handle(p_newtask);
56  return ABT_SUCCESS;
57 }
58 
90 int ABT_task_create_on_xstream(ABT_xstream xstream, void (*task_func)(void *),
91  void *arg, ABT_task *newtask)
92 {
93  ABTI_local *p_local = ABTI_local_get_local();
94  ABTI_thread *p_newtask;
95 
96  ABTI_xstream *p_xstream = ABTI_xstream_get_ptr(xstream);
97  ABTI_CHECK_NULL_XSTREAM_PTR(p_xstream);
98 
99  /* TODO: need to consider the access type of target pool */
100  ABTI_pool *p_pool = ABTI_xstream_get_main_pool(p_xstream);
101  int refcount = (newtask != NULL) ? 1 : 0;
102  int abt_errno = task_create(p_local, p_pool, task_func, arg, NULL, refcount,
103  &p_newtask);
104  ABTI_CHECK_ERROR(abt_errno);
105 
106  /* Return value */
107  if (newtask)
108  *newtask = ABTI_thread_get_handle(p_newtask);
109  return ABT_SUCCESS;
110 }
111 
112 #ifdef ABT_CONFIG_USE_DOXYGEN
113 
131 int ABT_task_revive(ABT_pool pool, void (*task_func)(void *), void *arg,
132  ABT_task *task);
133 #endif
134 
135 #ifdef ABT_CONFIG_USE_DOXYGEN
136 
149 int ABT_task_free(ABT_task *task);
150 #endif
151 
152 #ifdef ABT_CONFIG_USE_DOXYGEN
153 
165 int ABT_task_join(ABT_task task);
166 #endif
167 
168 #ifdef ABT_CONFIG_USE_DOXYGEN
169 
177 int ABT_task_cancel(ABT_task task);
178 #endif
179 
198 {
199  *task = ABT_TASK_NULL;
200 
201  ABTI_xstream *p_local_xstream;
203 
204  ABTI_thread *p_thread = p_local_xstream->p_thread;
205  if (p_thread->type & ABTI_THREAD_TYPE_YIELDABLE) {
206  return ABT_ERR_INV_THREAD;
207  } else {
208  *task = ABTI_thread_get_handle(p_thread);
209  }
210  return ABT_SUCCESS;
211 }
212 
227 {
228  ABTI_xstream *p_local_xstream;
230 
231  ABTI_thread *p_thread = p_local_xstream->p_thread;
234  *id = ABTI_thread_get_id(p_thread);
235  return ABT_SUCCESS;
236 }
237 
238 #ifdef ABT_CONFIG_USE_DOXYGEN
239 
252 int ABT_task_get_xstream(ABT_task task, ABT_xstream *xstream);
253 #endif
254 
255 #ifdef ABT_CONFIG_USE_DOXYGEN
256 
265 int ABT_task_get_state(ABT_task task, ABT_task_state *state);
266 #endif
267 
268 #ifdef ABT_CONFIG_USE_DOXYGEN
269 
281 int ABT_task_get_last_pool(ABT_task task, ABT_pool *pool);
282 #endif
283 
284 #ifdef ABT_CONFIG_USE_DOXYGEN
285 
299 int ABT_task_get_last_pool_id(ABT_task task, int *id);
300 #endif
301 
302 #ifdef ABT_CONFIG_USE_DOXYGEN
303 
320 #endif
321 
322 #ifdef ABT_CONFIG_USE_DOXYGEN
323 
337 int ABT_task_is_migratable(ABT_task task, ABT_bool *flag);
338 #endif
339 
340 #ifdef ABT_CONFIG_USE_DOXYGEN
341 
355 int ABT_task_is_unnamed(ABT_task task, ABT_bool *flag);
356 #endif
357 
358 #ifdef ABT_CONFIG_USE_DOXYGEN
359 
374 int ABT_task_equal(ABT_task task1, ABT_task task2, ABT_bool *result);
375 #endif
376 
377 #ifdef ABT_CONFIG_USE_DOXYGEN
378 
389 int ABT_task_get_id(ABT_task task, ABT_unit_id *task_id);
390 #endif
391 
392 #ifdef ABT_CONFIG_USE_DOXYGEN
393 
405 int ABT_task_get_arg(ABT_task task, void **arg);
406 #endif
407 
408 #ifdef ABT_CONFIG_USE_DOXYGEN
409 
422 int ABT_task_set_specific(ABT_task task, ABT_key key, void *value);
423 #endif
424 
425 #ifdef ABT_CONFIG_USE_DOXYGEN
426 
441 int ABT_task_get_specific(ABT_task task, ABT_key key, void **value);
442 #endif
443 
444 /*****************************************************************************/
445 /* Internal static functions */
446 /*****************************************************************************/
447 
448 ABTU_ret_err static int task_create(ABTI_local *p_local, ABTI_pool *p_pool,
449  void (*task_func)(void *), void *arg,
450  ABTI_sched *p_sched, int refcount,
451  ABTI_thread **pp_newtask)
452 {
453  ABTI_thread *p_newtask;
454  ABT_task h_newtask;
455 
456  /* Allocate a task object */
457  int abt_errno = ABTI_mem_alloc_nythread(p_local, &p_newtask);
458  ABTI_CHECK_ERROR(abt_errno);
459 
460  p_newtask->p_last_xstream = NULL;
461  p_newtask->p_parent = NULL;
464  p_newtask->f_thread = task_func;
465  p_newtask->p_arg = arg;
466  p_newtask->p_pool = p_pool;
467  ABTD_atomic_relaxed_store_ptr(&p_newtask->p_keytable, NULL);
468  p_newtask->id = ABTI_TASK_INIT_ID;
469 
470  /* Create a wrapper work unit */
471  h_newtask = ABTI_thread_get_handle(p_newtask);
472  ABTI_thread_type thread_type =
475 #ifndef ABT_CONFIG_DISABLE_MIGRATION
476  thread_type |= ABTI_THREAD_TYPE_MIGRATABLE;
477 #endif
478  p_newtask->type |= thread_type;
479  p_newtask->unit = p_pool->u_create_from_task(h_newtask);
480 
481  ABTI_tool_event_thread_create(p_local, p_newtask,
483  ? ABTI_local_get_xstream(p_local)
484  ->p_thread
485  : NULL,
486  p_pool);
487  LOG_DEBUG("[T%" PRIu64 "] created\n", ABTI_thread_get_id(p_newtask));
488 
489  /* Add this task to the scheduler's pool */
490  ABTI_pool_push(p_pool, p_newtask->unit);
491 
492  /* Return value */
493  *pp_newtask = p_newtask;
494 
495  return ABT_SUCCESS;
496 }
static ABTU_ret_err int ABTI_mem_alloc_nythread(ABTI_local *p_local, ABTI_thread **pp_thread)
Definition: abti_mem.h:65
ABTI_pool * p_pool
Definition: abti.h:324
ABTD_atomic_uint32 request
Definition: abti.h:323
uint64_t ABT_unit_id
Definition: abt.h:341
ABT_unit_id id
Definition: abti.h:326
struct ABT_xstream_opaque * ABT_xstream
Definition: abt.h:313
int ABT_task_set_specific(ABT_task task, ABT_key key, void *value)
Set the tasklet-specific value associated with the key.
static ABTU_ret_err int task_create(ABTI_local *p_local, ABTI_pool *p_pool, void(*task_func)(void *), void *arg, ABTI_sched *p_sched, int refcount, ABTI_thread **pp_newtask)
Definition: task.c:448
static void ABTD_atomic_relaxed_store_ptr(ABTD_atomic_ptr *ptr, void *val)
Definition: abtd_atomic.h:914
struct ABTI_local ABTI_local
Definition: abti.h:101
#define ABTI_tool_event_thread_create(p_local, p_thread, p_caller, p_pool)
Definition: abti_tool.h:309
void(* f_thread)(void *)
Definition: abti.h:320
ABTI_thread_type type
Definition: abti.h:316
static ABTI_pool * ABTI_xstream_get_main_pool(ABTI_xstream *p_xstream)
Definition: abti_stream.h:42
int ABT_task_cancel(ABT_task task)
Request the cancellation of the target task.
struct ABT_thread_opaque * ABT_task
Definition: abt.h:353
#define ABT_ERR_INV_THREAD
Definition: abt.h:80
ABTI_thread * p_thread
Definition: abti.h:251
#define ABTI_THREAD_TYPE_NAMED
Definition: abti.h:78
int ABT_task_create(ABT_pool pool, void(*task_func)(void *), void *arg, ABT_task *newtask) ABT_API_PUBLIC
Create a new task and return its handle through newtask.
Definition: task.c:40
int ABT_bool
Definition: abt.h:373
#define ABTI_THREAD_TYPE_THREAD
Definition: abti.h:73
int ABT_task_join(ABT_task task)
Wait for the tasklet to terminate.
int ABT_task_get_specific(ABT_task task, ABT_key key, void **value)
Get the tasklet-specific value associated with the key.
int ABT_task_self(ABT_task *task) ABT_API_PUBLIC
Return the handle of the calling tasklet.
Definition: task.c:197
struct ABT_pool_opaque * ABT_pool
Definition: abt.h:329
ABT_unit_create_from_task_fn u_create_from_task
Definition: abti.h:297
ABT_unit_id ABTI_thread_get_id(ABTI_thread *p_thread)
Definition: thread.c:1600
struct ABT_key_opaque * ABT_key
Definition: abt.h:355
int ABT_task_create_on_xstream(ABT_xstream xstream, void(*task_func)(void *), void *arg, ABT_task *newtask) ABT_API_PUBLIC
Create a new tasklet associated with the target ES (xstream).
Definition: task.c:90
static ABTI_xstream * ABTI_xstream_get_ptr(ABT_xstream xstream)
Definition: abti_stream.h:11
ABTI_xstream * p_last_xstream
Definition: abti.h:318
#define ABTI_CHECK_TRUE(cond, abt_errno)
Definition: abti_error.h:137
enum ABT_thread_state ABT_task_state
Definition: abt.h:349
uint32_t ABTI_thread_type
Definition: abti.h:115
int ABT_task_equal(ABT_task task1, ABT_task task2, ABT_bool *result)
Compare two tasklet handles for equality.
ABTD_atomic_int state
Definition: abti.h:322
static ABTI_pool * ABTI_pool_get_ptr(ABT_pool pool)
Definition: abti_pool.h:11
void * p_arg
Definition: abti.h:321
#define ABT_SUCCESS
Definition: abt.h:64
int ABT_task_get_last_pool(ABT_task task, ABT_pool *pool)
Return the last pool of task.
int ABT_task_set_migratable(ABT_task task, ABT_bool flag)
Set the tasklet's migratability.
#define ABTI_THREAD_TYPE_YIELDABLE
Definition: abti.h:77
int ABT_task_self_id(ABT_unit_id *id) ABT_API_PUBLIC
Return the ID of the calling tasklet.
Definition: task.c:226
static void ABTD_atomic_relaxed_store_uint32(ABTD_atomic_uint32 *ptr, uint32_t val)
Definition: abtd_atomic.h:884
#define ABTI_CHECK_NULL_XSTREAM_PTR(p)
Definition: abti_error.h:166
int ABT_task_get_arg(ABT_task task, void **arg)
Retrieve the argument for the tasklet function.
static void ABTI_pool_push(ABTI_pool *p_pool, ABT_unit unit)
Definition: abti_pool.h:65
#define ABTI_CHECK_NULL_POOL_PTR(p)
Definition: abti_error.h:175
int ABT_task_get_id(ABT_task task, ABT_unit_id *task_id)
Get the tasklet's id.
int ABT_task_get_state(ABT_task task, ABT_task_state *state)
Return the state of task.
#define LOG_DEBUG(fmt,...)
Definition: abti_log.h:26
#define ABTI_THREAD_TYPE_MIGRATABLE
Definition: abti.h:79
int ABT_task_get_last_pool_id(ABT_task task, int *id)
Get the last pool's ID of the tasklet.
#define ABTI_CHECK_ERROR(abt_errno)
Definition: abti_error.h:127
static void ABTD_atomic_relaxed_store_int(ABTD_atomic_int *ptr, int val)
Definition: abtd_atomic.h:865
int ABT_task_free(ABT_task *task)
Release the task object associated with task handle.
static ABTI_xstream * ABTI_local_get_xstream(ABTI_local *p_local)
Definition: abti_local.h:86
ABTD_atomic_ptr p_keytable
Definition: abti.h:325
#define ABTI_TASK_INIT_ID
Definition: abti.h:54
ABT_unit unit
Definition: abti.h:317
#define ABTI_SETUP_LOCAL_XSTREAM_WITH_INIT_CHECK(pp_local_xstream)
Definition: abti_error.h:109
static ABTI_local * ABTI_local_get_local(void)
Definition: abti_local.h:41
int ABT_task_is_unnamed(ABT_task task, ABT_bool *flag)
Check if the target task is unnamed.
#define ABT_TASK_NULL
Definition: abt.h:429
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.
ABTI_thread * p_parent
Definition: abti.h:319
static ABT_thread ABTI_thread_get_handle(ABTI_thread *p_thread)
Definition: abti_thread.h:24
#define ABTU_ret_err
Definition: abtu.h:49
static ABTI_xstream * ABTI_local_get_xstream_or_null(ABTI_local *p_local)
Definition: abti_local.h:77
int ABT_task_revive(ABT_pool pool, void(*task_func)(void *), void *arg, ABT_task *task)
Revive the tasklet.