8 static inline void ABTD_thread_terminate_thread(ABTI_local *p_local,
9 ABTI_thread *p_thread);
10 static inline void ABTD_thread_terminate_sched(ABTI_local *p_local,
11 ABTI_thread *p_thread);
13 void ABTD_thread_func_wrapper_thread(
void *p_arg)
15 ABTD_thread_context *p_ctx = (ABTD_thread_context *)p_arg;
16 void (*thread_func)(
void *) = p_ctx->f_thread;
18 thread_func(p_ctx->p_arg);
21 ABTI_thread *p_thread = (ABTI_thread *)p_ctx;
22 #ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED 23 ABTI_ASSERT(p_thread->is_sched == NULL);
26 ABTI_local *p_local = ABTI_local_get_local();
27 ABTD_thread_terminate_thread(p_local, p_thread);
30 void ABTD_thread_func_wrapper_sched(
void *p_arg)
32 ABTD_thread_context *p_ctx = (ABTD_thread_context *)p_arg;
33 void (*thread_func)(
void *) = p_ctx->f_thread;
35 thread_func(p_ctx->p_arg);
38 ABTI_thread *p_thread = (ABTI_thread *)p_ctx;
39 #ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED 40 ABTI_ASSERT(p_thread->is_sched != NULL);
43 ABTI_local *p_local = ABTI_local_get_local();
44 ABTD_thread_terminate_sched(p_local, p_thread);
47 void ABTD_thread_exit(ABTI_local *p_local, ABTI_thread *p_thread)
49 #ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED 50 if (p_thread->is_sched) {
51 ABTD_thread_terminate_sched(p_local, p_thread);
54 ABTD_thread_terminate_thread(p_local, p_thread);
55 #ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED 61 ABTI_thread *p_thread,
64 ABTD_thread_context *p_ctx = &p_thread->ctx;
65 ABTD_thread_context *p_link =
66 ABTD_atomic_acquire_load_thread_context_ptr(&p_ctx->p_link);
69 ABTI_thread *p_joiner = (ABTI_thread *)p_link;
70 if (p_thread->p_last_xstream == p_joiner->p_last_xstream) {
73 ABTD_atomic_release_store_int(&p_thread->state,
75 LOG_EVENT(
"[U%" PRIu64
":E%d] terminated\n",
76 ABTI_thread_get_id(p_thread),
77 p_thread->p_last_xstream->rank);
83 #ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED 85 ABTI_thread_finish_context_sched_to_thread(p_local,
90 ABTI_thread_finish_context_thread_to_thread(p_local, p_thread,
92 #ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED 100 ABTI_thread_set_ready(p_local, p_joiner);
104 ABTD_atomic_release_store_uint32(&p_thread->request,
105 ABTI_THREAD_REQ_TERMINATE);
109 ABTD_atomic_fetch_or_uint32(&p_thread->request,
110 ABTI_THREAD_REQ_JOIN |
111 ABTI_THREAD_REQ_TERMINATE);
112 if (req & ABTI_THREAD_REQ_JOIN) {
117 ABTD_atomic_acquire_load_thread_context_ptr(&p_ctx->p_link);
119 ABTI_thread_set_ready(p_local, (ABTI_thread *)p_link);
127 #ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED 128 if (p_thread->is_sched) {
131 p_sched = ABTI_xstream_get_parent_sched(p_thread->p_last_xstream);
134 p_sched = ABTI_xstream_get_top_sched(p_thread->p_last_xstream);
135 #ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED 138 #ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED 140 ABTI_thread_finish_context_sched_to_sched(p_thread->is_sched, p_sched);
143 ABTI_thread_finish_context_thread_to_sched(p_thread, p_sched);
144 #ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED 149 static inline void ABTD_thread_terminate_thread(ABTI_local *p_local,
150 ABTI_thread *p_thread)
155 static inline void ABTD_thread_terminate_sched(ABTI_local *p_local,
156 ABTI_thread *p_thread)
161 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION 162 void ABTD_thread_terminate_thread_no_arg()
164 ABTI_local *p_local = ABTI_local_get_local();
167 ABTI_thread *p_thread = p_local->p_thread;
168 ABTD_thread_terminate_thread(p_local, p_thread);
172 void ABTD_thread_cancel(ABTI_local *p_local, ABTI_thread *p_thread)
179 ABTD_thread_context *p_ctx = &p_thread->ctx;
181 if (ABTD_atomic_acquire_load_thread_context_ptr(&p_ctx->p_link)) {
183 ABTI_thread *p_joiner =
184 (ABTI_thread *)ABTD_atomic_relaxed_load_thread_context_ptr(
186 ABTI_thread_set_ready(p_local, p_joiner);
189 ABTD_atomic_fetch_or_uint32(&p_thread->request,
190 ABTI_THREAD_REQ_JOIN |
191 ABTI_THREAD_REQ_TERMINATE);
192 if (req & ABTI_THREAD_REQ_JOIN) {
195 while (ABTD_atomic_acquire_load_thread_context_ptr(
196 &p_ctx->p_link) == NULL)
198 ABTI_thread *p_joiner =
199 (ABTI_thread *)ABTD_atomic_relaxed_load_thread_context_ptr(
201 ABTI_thread_set_ready(p_local, p_joiner);
206 void ABTD_thread_print_context(ABTI_thread *p_thread, FILE *p_os,
int indent)
209 ABTD_thread_context *p_ctx = &p_thread->ctx;
210 fprintf(p_os,
"%sp_ctx : %p\n", prefix, p_ctx->p_ctx);
211 fprintf(p_os,
"%sp_arg : %p\n", prefix, p_ctx->p_arg);
212 fprintf(p_os,
"%sp_link : %p\n", prefix,
213 (
void *)ABTD_atomic_acquire_load_thread_context_ptr(
char * ABTU_get_indent_str(int indent)
#define LOG_EVENT(fmt,...)
static void ABTDI_thread_terminate(ABTI_local *p_local, ABTI_thread *p_thread, ABT_bool is_sched)
static void ABTU_free(void *ptr)