ARGOBOTS  66b1c39742507d8df30e8d28c54839b961a14814
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
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 */
static void ABTD_ythread_context_jump(ABTD_ythread_context *p_old, ABTD_ythread_context *p_new, void *arg)
ABTD_ythread_context_atomic_ptr p_link
Definition: abtd_context.h:51
static void ABTD_ythread_context_init(ABTD_ythread_context *p_link, ABTD_ythread_context *p_newctx)
Definition: abtd_ythread.h:47
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
static ABTU_noreturn void ABTD_ythread_context_take(ABTD_ythread_context *p_old, ABTD_ythread_context *p_new, void *arg)
static void ABTD_atomic_relaxed_store_ythread_context_ptr(ABTD_ythread_context_atomic_ptr *ptr, ABTD_ythread_context *p_ctx)
Definition: abtd_context.h:36
static void ABTD_ythread_context_init_and_call(ABTD_ythread_context *p_ctx, void *sp, void(*thread_func)(void *), void *arg)
int ABT_bool
Definition: abt.h:373
void ABTD_ythread_func_wrapper(void *p_arg)
Definition: abtd_ythread.c:11
#define ABT_FALSE
Definition: abt.h:285
static void ABTD_ythread_context_invalidate(ABTD_ythread_context *p_newctx)
Definition: abtd_ythread.h:34
#define ABT_TRUE
Definition: abt.h:284
static void ABTD_ythread_context_dynamic_promote_ythread(void *p_stacktop)
Definition: abtd_ythread.h:114
#define ABTU_noreturn
Definition: abtu.h:31
static ABT_bool ABTD_ythread_context_is_dynamic_promoted(ABTD_ythread_context *p_ctx)
Definition: abtd_ythread.h:96
static void ABTD_ythread_context_make(ABTD_ythread_context *p_ctx, void *sp, size_t size, void(*thread_func)(void *))
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
static void ABTDI_ythread_context_dynamic_promote(void *p_stacktop, void *jump_f)
Definition: abtd_ythread.h:103
static void ABTD_ythread_context_arm_ythread(size_t stacksize, void *p_stack, ABTD_ythread_context *p_newctx)
Definition: abtd_ythread.h:55
static void ABTD_ythread_context_switch(ABTD_ythread_context *p_old, ABTD_ythread_context *p_new)
Definition: abtd_ythread.h:73
void ABTD_ythread_terminate_no_arg()
Definition: abtd_ythread.c:100
static ABTU_noreturn void ABTD_ythread_finish_context(ABTD_ythread_context *p_old, ABTD_ythread_context *p_new)
Definition: abtd_ythread.h:80