6 #ifndef ABTD_THREAD_H_INCLUDED 7 #define ABTD_THREAD_H_INCLUDED 9 #if defined(ABT_C_HAVE_VISIBILITY) 10 #define ABT_API_PRIVATE __attribute__((visibility("hidden"))) 12 #define ABT_API_PRIVATE 15 void ABTD_thread_func_wrapper_thread(
void *p_arg);
16 void ABTD_thread_func_wrapper_sched(
void *p_arg);
17 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION 18 void ABTD_thread_terminate_thread_no_arg();
22 void (*f_wrapper)(
void *),
23 void (*f_thread)(
void *),
24 void *p_arg,
size_t stacksize,
26 ABTD_thread_context *p_newctx)
33 p_stacktop = (
void *)(((
char *)p_stack) + stacksize);
35 ABTD_thread_context_make(p_newctx, p_stacktop, stacksize, f_wrapper);
36 p_newctx->f_thread = f_thread;
37 p_newctx->p_arg = p_arg;
38 ABTD_atomic_relaxed_store_thread_context_ptr(&p_newctx->p_link, p_link);
43 static inline int ABTD_thread_context_create_thread(
44 ABTD_thread_context *p_link,
void (*f_thread)(
void *),
void *p_arg,
45 size_t stacksize,
void *p_stack, ABTD_thread_context *p_newctx)
48 f_thread, p_arg, stacksize, p_stack,
52 static inline int ABTD_thread_context_create_sched(
53 ABTD_thread_context *p_link,
void (*f_thread)(
void *),
void *p_arg,
54 size_t stacksize,
void *p_stack, ABTD_thread_context *p_newctx)
57 f_thread, p_arg, stacksize, p_stack,
61 static inline int ABTD_thread_context_invalidate(ABTD_thread_context *p_newctx)
64 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION 67 p_newctx->p_ctx = (
void *)((intptr_t)0x1);
69 p_newctx->p_ctx = NULL;
71 p_newctx->f_thread = NULL;
72 p_newctx->p_arg = NULL;
73 ABTD_atomic_relaxed_store_thread_context_ptr(&p_newctx->p_link, NULL);
77 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION 78 static inline int ABTD_thread_context_init(ABTD_thread_context *p_link,
79 void (*f_thread)(
void *),
81 ABTD_thread_context *p_newctx)
84 p_newctx->p_ctx = NULL;
85 p_newctx->f_thread = f_thread;
86 p_newctx->p_arg = p_arg;
87 ABTD_atomic_relaxed_store_thread_context_ptr(&p_newctx->p_link, p_link);
91 static inline int ABTD_thread_context_arm_thread(
size_t stacksize,
93 ABTD_thread_context *p_newctx)
102 void *p_stacktop = (
void *)(((
char *)p_stack) + stacksize);
103 ABTD_thread_context_make(p_newctx, p_stacktop, stacksize,
104 ABTD_thread_func_wrapper_thread);
110 #define ABTD_thread_context_free(p_ctx) 112 static inline void ABTD_thread_context_switch(ABTD_thread_context *p_old,
113 ABTD_thread_context *p_new)
115 ABTD_thread_context_jump(p_old, p_new, p_new);
118 static inline void ABTD_thread_finish_context(ABTD_thread_context *p_old,
119 ABTD_thread_context *p_new)
121 ABTD_thread_context_take(p_old, p_new, p_new);
124 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION 125 static inline void ABTD_thread_context_make_and_call(ABTD_thread_context *p_old,
126 void (*f_thread)(
void *),
130 ABTD_thread_context_init_and_call(p_old, p_stacktop, f_thread, p_arg);
134 ABTD_thread_context_is_dynamic_promoted(ABTD_thread_context *p_ctx)
145 void **p_return_address = (
void **)(((
char *)p_stacktop) - 0x10);
146 void ***p_stack_pointer = (
void ***)(((
char *)p_stacktop) - 0x08);
147 *p_stack_pointer = p_return_address;
148 *p_return_address = jump_f;
151 static inline void ABTD_thread_context_dynamic_promote_thread(
void *p_stacktop)
157 conv.f = ABTD_thread_terminate_thread_no_arg;
158 void *jump_f = conv.ptr;
163 static inline void ABTD_thread_context_set_arg(ABTD_thread_context *p_ctx,
169 static inline void *ABTD_thread_context_get_arg(ABTD_thread_context *p_ctx)
static int ABTDI_thread_context_create(ABTD_thread_context *p_link, void(*f_wrapper)(void *), void(*f_thread)(void *), void *p_arg, size_t stacksize, void *p_stack, ABTD_thread_context *p_newctx)
static void ABTDI_thread_context_dynamic_promote(void *p_stacktop, void *jump_f)