ARGOBOTS  8bef54a19d7b3e50f977f85716578b627bf37d9c
abtd_ythread.h
Go to the documentation of this file.
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  * See COPYRIGHT in top-level directory.
4  */
5 
6 #ifndef ABTD_YTHREAD_H_INCLUDED
7 #define ABTD_YTHREAD_H_INCLUDED
8 
9 #if defined(ABT_C_HAVE_VISIBILITY)
10 #define ABT_API_PRIVATE __attribute__((visibility("hidden")))
11 #else
12 #define ABT_API_PRIVATE
13 #endif
14 
15 void ABTD_ythread_func_wrapper(void *p_arg);
16 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION
18 #endif
19 
21  size_t stacksize, void *p_stack,
22  ABTD_ythread_context *p_newctx)
23 {
24  /* ABTD_ythread_context_make uses the top address of stack.
25  Note that the parameter, p_stack, points to the bottom of stack. */
26  void *p_stacktop = (void *)(((char *)p_stack) + stacksize);
27 
28  ABTD_ythread_context_make(p_newctx, p_stacktop, stacksize,
31 }
32 
33 static inline void
35 {
36 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION
37  /* p_ctx is used to check whether the context requires dynamic promotion is
38  * necessary or not, so this value must not be NULL. */
39  p_newctx->p_ctx = (void *)((intptr_t)0x1);
40 #else
41  p_newctx->p_ctx = NULL;
42 #endif
44 }
45 
46 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION
48  ABTD_ythread_context *p_newctx)
49 {
50  p_newctx->p_ctx = NULL;
52 }
53 
54 static inline void
55 ABTD_ythread_context_arm_ythread(size_t stacksize, void *p_stack,
56  ABTD_ythread_context *p_newctx)
57 {
58  /*
59  * This function *arms* the dynamic promotion thread (initialized by
60  * ABTD_ythread_context_init) as if it were created by
61  * ABTD_ythread_context_create; this function fully creates the context
62  * so that the thread can be run by ABTD_ythread_context_jump.
63  *
64  * ABTD_ythread_context_make uses the top address of stack.
65  * Note that the parameter, p_stack, points to the bottom of stack.
66  */
67  void *p_stacktop = (void *)(((char *)p_stack) + stacksize);
68  ABTD_ythread_context_make(p_newctx, p_stacktop, stacksize,
70 }
71 #endif
72 
74  ABTD_ythread_context *p_new)
75 {
76  ABTD_ythread_context_jump(p_old, p_new, p_new);
77 }
78 
79 ABTU_noreturn static inline void
81  ABTD_ythread_context *p_new)
82 {
83  ABTD_ythread_context_take(p_old, p_new, p_new);
84 }
85 
86 #if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION
87 static inline void
89  void (*f_thread)(void *), void *p_arg,
90  void *p_stacktop)
91 {
92  ABTD_ythread_context_init_and_call(p_old, p_stacktop, f_thread, p_arg);
93 }
94 
95 static inline ABT_bool
97 {
98  /* Check if the ULT has been dynamically promoted; internally, it checks if
99  * the context is NULL. */
100  return p_ctx->p_ctx ? ABT_TRUE : ABT_FALSE;
101 }
102 
103 static inline void ABTDI_ythread_context_dynamic_promote(void *p_stacktop,
104  void *jump_f)
105 {
106  /* Perform dynamic promotion */
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;
111 }
112 
113 static inline void
115 {
116  union fp_conv {
117  void (*f)(void);
118  void *ptr;
119  } conv;
121  void *jump_f = conv.ptr;
122  ABTDI_ythread_context_dynamic_promote(p_stacktop, jump_f);
123 }
124 #endif
125 
126 #endif /* ABTD_YTHREAD_H_INCLUDED */
ABT_bool
int ABT_bool
Boolean type.
Definition: abt.h:1001
ABTD_ythread_context_jump
static void ABTD_ythread_context_jump(ABTD_ythread_context *p_old, ABTD_ythread_context *p_new, void *arg)
ABTD_ythread_context_init
static void ABTD_ythread_context_init(ABTD_ythread_context *p_link, ABTD_ythread_context *p_newctx)
Definition: abtd_ythread.h:47
ABTD_ythread_terminate_no_arg
void ABTD_ythread_terminate_no_arg(void)
Definition: abtd_ythread.c:107
ABTD_atomic_relaxed_store_ythread_context_ptr
static void ABTD_atomic_relaxed_store_ythread_context_ptr(ABTD_ythread_context_atomic_ptr *ptr, ABTD_ythread_context *p_ctx)
Definition: abtd_context.h:43
ABTU_noreturn
#define ABTU_noreturn
Definition: abtu.h:127
ABTD_ythread_context::p_link
ABTD_ythread_context_atomic_ptr p_link
Definition: abtd_fcontext.h:36
ABTD_ythread_context
Definition: abtd_fcontext.h:33
ABTD_ythread_context_init_and_call
static void ABTD_ythread_context_init_and_call(ABTD_ythread_context *p_ctx, void *sp, void(*thread_func)(void *), void *arg)
ABTD_ythread_func_wrapper
void ABTD_ythread_func_wrapper(void *p_arg)
Definition: abtd_ythread.c:11
ABTD_ythread_context_invalidate
static void ABTD_ythread_context_invalidate(ABTD_ythread_context *p_newctx)
Definition: abtd_ythread.h:34
ABTD_ythread_context::p_ctx
void * p_ctx
Definition: abtd_fcontext.h:34
ABTDI_ythread_context_dynamic_promote
static void ABTDI_ythread_context_dynamic_promote(void *p_stacktop, void *jump_f)
Definition: abtd_ythread.h:103
ABT_TRUE
#define ABT_TRUE
True constant for ABT_bool.
Definition: abt.h:748
ABTD_ythread_context_arm_ythread
static void ABTD_ythread_context_arm_ythread(size_t stacksize, void *p_stack, ABTD_ythread_context *p_newctx)
Definition: abtd_ythread.h:55
ABTD_ythread_context_is_dynamic_promoted
static ABT_bool ABTD_ythread_context_is_dynamic_promoted(ABTD_ythread_context *p_ctx)
Definition: abtd_ythread.h:96
ABTD_ythread_context_dynamic_promote_ythread
static void ABTD_ythread_context_dynamic_promote_ythread(void *p_stacktop)
Definition: abtd_ythread.h:114
ABT_FALSE
#define ABT_FALSE
False constant for ABT_bool.
Definition: abt.h:750
ABTD_ythread_context_switch
static void ABTD_ythread_context_switch(ABTD_ythread_context *p_old, ABTD_ythread_context *p_new)
Definition: abtd_ythread.h:73
ABTD_ythread_context_create
static void ABTD_ythread_context_create(ABTD_ythread_context *p_link, size_t stacksize, void *p_stack, ABTD_ythread_context *p_newctx)
Definition: abtd_ythread.h:20
ABTD_ythread_finish_context
static ABTU_noreturn void ABTD_ythread_finish_context(ABTD_ythread_context *p_old, ABTD_ythread_context *p_new)
Definition: abtd_ythread.h:80
ABTD_ythread_context_make_and_call
static void ABTD_ythread_context_make_and_call(ABTD_ythread_context *p_old, void(*f_thread)(void *), void *p_arg, void *p_stacktop)
Definition: abtd_ythread.h:88
ABTD_ythread_context_make
static void ABTD_ythread_context_make(ABTD_ythread_context *p_ctx, void *sp, size_t size, void(*thread_func)(void *))
ABTD_ythread_context_take
static ABTU_noreturn void ABTD_ythread_context_take(ABTD_ythread_context *p_old, ABTD_ythread_context *p_new, void *arg)