6 #ifndef ABTD_YTHREAD_H_INCLUDED
7 #define ABTD_YTHREAD_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_ythread_func_wrapper(
void *p_arg);
16 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION
17 void ABTD_ythread_terminate_no_arg(
void);
20 static inline void ABTD_ythread_context_create(ABTD_ythread_context *p_link,
21 size_t stacksize,
void *p_stack,
22 ABTD_ythread_context *p_newctx)
26 void *p_stacktop = (
void *)(((
char *)p_stack) + stacksize);
28 ABTD_ythread_context_make(p_newctx, p_stacktop, stacksize,
29 ABTD_ythread_func_wrapper);
30 ABTD_atomic_relaxed_store_ythread_context_ptr(&p_newctx->p_link, p_link);
34 ABTD_ythread_context_invalidate(ABTD_ythread_context *p_newctx)
36 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION
39 p_newctx->p_ctx = (
void *)((intptr_t)0x1);
41 p_newctx->p_ctx = NULL;
43 ABTD_atomic_relaxed_store_ythread_context_ptr(&p_newctx->p_link, NULL);
46 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION
47 static inline void ABTD_ythread_context_init(ABTD_ythread_context *p_link,
48 ABTD_ythread_context *p_newctx)
50 p_newctx->p_ctx = NULL;
51 ABTD_atomic_relaxed_store_ythread_context_ptr(&p_newctx->p_link, p_link);
55 ABTD_ythread_context_arm_ythread(
size_t stacksize,
void *p_stack,
56 ABTD_ythread_context *p_newctx)
67 void *p_stacktop = (
void *)(((
char *)p_stack) + stacksize);
68 ABTD_ythread_context_make(p_newctx, p_stacktop, stacksize,
69 ABTD_ythread_func_wrapper);
73 static inline void ABTD_ythread_context_switch(ABTD_ythread_context *p_old,
74 ABTD_ythread_context *p_new)
76 ABTD_ythread_context_jump(p_old, p_new, p_new);
80 ABTD_ythread_finish_context(ABTD_ythread_context *p_old,
81 ABTD_ythread_context *p_new)
83 ABTD_ythread_context_take(p_old, p_new, p_new);
86 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION
88 ABTD_ythread_context_make_and_call(ABTD_ythread_context *p_old,
89 void (*f_thread)(
void *),
void *p_arg,
92 ABTD_ythread_context_init_and_call(p_old, p_stacktop, f_thread, p_arg);
96 ABTD_ythread_context_is_dynamic_promoted(ABTD_ythread_context *p_ctx)
107 void **p_return_address = (
void **)(((
char *)p_stacktop) - 0x10);
108 void ***p_stack_pointer = (
void ***)(((
char *)p_stacktop) - 0x08);
109 *p_stack_pointer = p_return_address;
110 *p_return_address = jump_f;
114 ABTD_ythread_context_dynamic_promote_ythread(
void *p_stacktop)
120 conv.f = ABTD_ythread_terminate_no_arg;
121 void *jump_f = conv.ptr;