6 #ifndef ABTD_UCONTEXT_H_INCLUDED 7 #define ABTD_UCONTEXT_H_INCLUDED 9 static void ABTD_ucontext_wrapper(
int arg1,
int arg2)
11 ABTD_thread_context *p_self;
12 #if SIZEOF_VOID_P == 8 13 p_self = (ABTD_thread_context *)(((uintptr_t)((uint32_t)arg1) << 32) |
14 ((uintptr_t)((uint32_t)arg2)));
15 #elif SIZEOF_VOID_P == 4 16 p_self = (ABTD_thread_context *)((uintptr_t)arg1);
18 #error "Unknown pointer size." 20 p_self->f_uctx_thread(p_self->p_uctx_arg);
26 static inline void ABTD_thread_context_make(ABTD_thread_context *p_ctx,
27 void *sp,
size_t size,
28 void (*thread_func)(
void *))
30 getcontext(&p_ctx->uctx);
31 p_ctx->p_ctx = &p_ctx->uctx;
34 p_ctx->uctx.uc_link = NULL;
35 p_ctx->uctx.uc_stack.ss_sp = (
void *)(((
char *)sp) - size);
36 p_ctx->uctx.uc_stack.ss_size = size;
37 p_ctx->f_uctx_thread = thread_func;
39 #if SIZEOF_VOID_P == 8 40 int arg_upper = (int)(((uintptr_t)p_ctx) >> 32);
41 int arg_lower = (int)(((uintptr_t)p_ctx) >> 0);
42 makecontext(&p_ctx->uctx, (void (*)())ABTD_ucontext_wrapper, 2, arg_upper,
44 #elif SIZEOF_VOID_P == 4 45 int arg = (int)((uintptr_t)p_ctx);
46 makecontext(&p_ctx->uctx, (void (*)())ABTD_ucontext_wrapper, 1, arg);
48 #error "Unknown pointer size." 52 static inline void ABTD_thread_context_jump(ABTD_thread_context *p_old,
53 ABTD_thread_context *p_new,
56 p_new->p_uctx_arg = arg;
57 swapcontext(&p_old->uctx, &p_new->uctx);
60 static inline void ABTD_thread_context_take(ABTD_thread_context *p_old,
61 ABTD_thread_context *p_new,
64 p_new->p_uctx_arg = arg;
65 setcontext(&p_new->uctx);
69 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION 70 #error "ABTD_thread_context_make_and_call is not implemented."