8 static inline void ABTD_thread_terminate(ABTI_xstream *p_local_xstream,
9 ABTI_thread *p_thread);
11 void ABTD_thread_func_wrapper(
void *p_arg)
13 ABTD_thread_context *p_ctx = (ABTD_thread_context *)p_arg;
14 ABTI_thread *p_thread = ABTI_thread_context_get_thread(p_ctx);
15 ABTI_xstream *p_local_xstream = p_thread->unit_def.p_last_xstream;
16 ABTI_tool_event_thread_run(p_local_xstream, p_thread,
17 p_local_xstream->p_unit,
18 p_thread->unit_def.p_parent);
19 p_local_xstream->p_unit = &p_thread->unit_def;
21 p_thread->unit_def.f_unit(p_thread->unit_def.p_arg);
26 p_local_xstream = ABTI_local_get_xstream();
27 ABTD_thread_terminate(p_local_xstream, p_thread);
30 void ABTD_thread_exit(ABTI_xstream *p_local_xstream, ABTI_thread *p_thread)
32 ABTD_thread_terminate(p_local_xstream, p_thread);
35 static inline void ABTD_thread_terminate(ABTI_xstream *p_local_xstream,
36 ABTI_thread *p_thread)
38 ABTD_thread_context *p_ctx = &p_thread->ctx;
39 ABTD_thread_context *p_link =
40 ABTD_atomic_acquire_load_thread_context_ptr(&p_ctx->p_link);
43 ABTI_thread *p_joiner = ABTI_thread_context_get_thread(p_link);
44 if (p_thread->unit_def.p_last_xstream ==
45 p_joiner->unit_def.p_last_xstream) {
48 ABTD_atomic_release_store_int(&p_thread->unit_def.state,
49 ABTI_UNIT_STATE_TERMINATED);
50 LOG_DEBUG(
"[U%" PRIu64
":E%d] terminated\n",
51 ABTI_thread_get_id(p_thread),
52 p_thread->unit_def.p_last_xstream->rank);
55 ABTI_tool_event_thread_resume(p_local_xstream, p_joiner,
57 ABTI_thread_finish_context_to_sibling(p_local_xstream, p_thread,
64 ABTI_thread_set_ready(p_local_xstream, p_joiner);
68 ABTD_atomic_release_store_uint32(&p_thread->unit_def.request,
69 ABTI_UNIT_REQ_TERMINATE);
72 uint32_t req = ABTD_atomic_fetch_or_uint32(&p_thread->unit_def.request,
74 ABTI_UNIT_REQ_TERMINATE);
75 if (req & ABTI_UNIT_REQ_JOIN) {
80 ABTD_atomic_acquire_load_thread_context_ptr(&p_ctx->p_link);
82 ABTI_thread_set_ready(p_local_xstream,
83 ABTI_thread_context_get_thread(p_link));
90 ABTI_thread_finish_context_to_parent(p_local_xstream, p_thread);
93 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION
94 void ABTD_thread_terminate_no_arg()
96 ABTI_xstream *p_local_xstream = ABTI_local_get_xstream();
99 ABTI_unit *p_unit = p_local_xstream->p_unit;
100 ABTI_ASSERT(ABTI_unit_type_is_thread(p_unit->type));
101 ABTD_thread_terminate(p_local_xstream, ABTI_unit_get_thread(p_unit));
105 void ABTD_thread_cancel(ABTI_xstream *p_local_xstream, ABTI_thread *p_thread)
112 ABTD_thread_context *p_ctx = &p_thread->ctx;
114 if (ABTD_atomic_acquire_load_thread_context_ptr(&p_ctx->p_link)) {
116 ABTI_thread *p_joiner = ABTI_thread_context_get_thread(
117 ABTD_atomic_relaxed_load_thread_context_ptr(&p_ctx->p_link));
118 ABTI_thread_set_ready(p_local_xstream, p_joiner);
120 uint32_t req = ABTD_atomic_fetch_or_uint32(&p_thread->unit_def.request,
122 ABTI_UNIT_REQ_TERMINATE);
123 if (req & ABTI_UNIT_REQ_JOIN) {
126 while (ABTD_atomic_acquire_load_thread_context_ptr(
127 &p_ctx->p_link) == NULL)
129 ABTI_thread *p_joiner = ABTI_thread_context_get_thread(
130 ABTD_atomic_relaxed_load_thread_context_ptr(&p_ctx->p_link));
131 ABTI_thread_set_ready(p_local_xstream, p_joiner);
134 ABTI_tool_event_thread_cancel(p_local_xstream, p_thread);
137 void ABTD_thread_print_context(ABTI_thread *p_thread, FILE *p_os,
int indent)
140 ABTD_thread_context *p_ctx = &p_thread->ctx;
141 fprintf(p_os,
"%sp_ctx : %p\n", prefix, p_ctx->p_ctx);
142 fprintf(p_os,
"%sp_link : %p\n", prefix,
143 (
void *)ABTD_atomic_acquire_load_thread_context_ptr(
char * ABTU_get_indent_str(int indent)
#define LOG_DEBUG(fmt,...)
static void ABTU_free(void *ptr)