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(
void *p_arg);
16 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION
17 void ABTD_thread_terminate_no_arg();
20 static inline int ABTD_thread_context_create(ABTD_thread_context *p_link,
21 size_t stacksize,
void *p_stack,
22 ABTD_thread_context *p_newctx)
29 p_stacktop = (
void *)(((
char *)p_stack) + stacksize);
31 ABTD_thread_context_make(p_newctx, p_stacktop, stacksize,
32 ABTD_thread_func_wrapper);
33 ABTD_atomic_relaxed_store_thread_context_ptr(&p_newctx->p_link, p_link);
38 static inline int ABTD_thread_context_invalidate(ABTD_thread_context *p_newctx)
41 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION
44 p_newctx->p_ctx = (
void *)((intptr_t)0x1);
46 p_newctx->p_ctx = NULL;
48 ABTD_atomic_relaxed_store_thread_context_ptr(&p_newctx->p_link, NULL);
52 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION
53 static inline int ABTD_thread_context_init(ABTD_thread_context *p_link,
54 ABTD_thread_context *p_newctx)
57 p_newctx->p_ctx = NULL;
58 ABTD_atomic_relaxed_store_thread_context_ptr(&p_newctx->p_link, p_link);
62 static inline int ABTD_thread_context_arm_thread(
size_t stacksize,
64 ABTD_thread_context *p_newctx)
73 void *p_stacktop = (
void *)(((
char *)p_stack) + stacksize);
74 ABTD_thread_context_make(p_newctx, p_stacktop, stacksize,
75 ABTD_thread_func_wrapper);
81 #define ABTD_thread_context_free(p_ctx)
83 static inline void ABTD_thread_context_switch(ABTD_thread_context *p_old,
84 ABTD_thread_context *p_new)
86 ABTD_thread_context_jump(p_old, p_new, p_new);
90 ABTD_thread_finish_context(ABTD_thread_context *p_old,
91 ABTD_thread_context *p_new)
93 ABTD_thread_context_take(p_old, p_new, p_new);
96 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION
97 static inline void ABTD_thread_context_make_and_call(ABTD_thread_context *p_old,
98 void (*f_thread)(
void *),
102 ABTD_thread_context_init_and_call(p_old, p_stacktop, f_thread, p_arg);
106 ABTD_thread_context_is_dynamic_promoted(ABTD_thread_context *p_ctx)
117 void **p_return_address = (
void **)(((
char *)p_stacktop) - 0x10);
118 void ***p_stack_pointer = (
void ***)(((
char *)p_stacktop) - 0x08);
119 *p_stack_pointer = p_return_address;
120 *p_return_address = jump_f;
123 static inline void ABTD_thread_context_dynamic_promote_thread(
void *p_stacktop)
129 conv.f = ABTD_thread_terminate_no_arg;
130 void *jump_f = conv.ptr;
static void ABTDI_thread_context_dynamic_promote(void *p_stacktop, void *jump_f)