@@ -10,16 +10,15 @@ static inline void ABTD_thread_terminate_thread(ABTI_local *p_local,
1010static inline void ABTD_thread_terminate_sched (ABTI_local * p_local ,
1111 ABTI_thread * p_thread );
1212
13- #if defined(ABT_CONFIG_USE_FCONTEXT )
1413void ABTD_thread_func_wrapper_thread (void * p_arg )
1514{
16- ABTD_thread_context * p_fctx = (ABTD_thread_context * )p_arg ;
17- void (* thread_func )(void * ) = p_fctx -> f_thread ;
15+ ABTD_thread_context * p_ctx = (ABTD_thread_context * )p_arg ;
16+ void (* thread_func )(void * ) = p_ctx -> f_thread ;
1817
19- thread_func (p_fctx -> p_arg );
18+ thread_func (p_ctx -> p_arg );
2019
2120 /* NOTE: ctx is located in the beginning of ABTI_thread */
22- ABTI_thread * p_thread = (ABTI_thread * )p_fctx ;
21+ ABTI_thread * p_thread = (ABTI_thread * )p_ctx ;
2322#ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED
2423 ABTI_ASSERT (p_thread -> is_sched == NULL );
2524#endif
@@ -30,56 +29,20 @@ void ABTD_thread_func_wrapper_thread(void *p_arg)
3029
3130void ABTD_thread_func_wrapper_sched (void * p_arg )
3231{
33- ABTD_thread_context * p_fctx = (ABTD_thread_context * )p_arg ;
34- void (* thread_func )(void * ) = p_fctx -> f_thread ;
32+ ABTD_thread_context * p_ctx = (ABTD_thread_context * )p_arg ;
33+ void (* thread_func )(void * ) = p_ctx -> f_thread ;
3534
36- thread_func (p_fctx -> p_arg );
35+ thread_func (p_ctx -> p_arg );
3736
3837 /* NOTE: ctx is located in the beginning of ABTI_thread */
39- ABTI_thread * p_thread = (ABTI_thread * )p_fctx ;
38+ ABTI_thread * p_thread = (ABTI_thread * )p_ctx ;
4039#ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED
4140 ABTI_ASSERT (p_thread -> is_sched != NULL );
4241#endif
4342
4443 ABTI_local * p_local = ABTI_local_get_local ();
4544 ABTD_thread_terminate_sched (p_local , p_thread );
4645}
47- #else
48- void ABTD_thread_func_wrapper (int func_upper , int func_lower ,
49- int arg_upper , int arg_lower )
50- {
51- ABTI_local * p_local = ABTI_local_get_local ();
52- void (* thread_func )(void * );
53- void * p_arg ;
54- size_t ptr_size , int_size ;
55-
56- ptr_size = sizeof (void * );
57- int_size = sizeof (int );
58- if (ptr_size == int_size ) {
59- thread_func = (void (* )(void * ))(uintptr_t )func_lower ;
60- p_arg = (void * )(uintptr_t )arg_lower ;
61- } else if (ptr_size == int_size * 2 ) {
62- uintptr_t shift_bits = CHAR_BIT * int_size ;
63- uintptr_t mask = ((uintptr_t )1 << shift_bits ) - 1 ;
64- thread_func = (void (* )(void * ))(
65- ((uintptr_t )func_upper << shift_bits ) |
66- ((uintptr_t )func_lower & mask ));
67- p_arg = (void * )(
68- ((uintptr_t )arg_upper << shift_bits ) |
69- ((uintptr_t )arg_lower & mask ));
70- } else {
71- ABTI_ASSERT (0 );
72- }
73-
74- thread_func (p_arg );
75-
76- /* Now, the ULT has finished its job. Terminate the ULT.
77- * We don't need to use the atomic operation here because the ULT will be
78- * terminated regardless of other requests. */
79- ABTI_thread * p_thread = p_local -> p_thread ;
80- p_thread -> request |= ABTI_THREAD_REQ_TERMINATE ;
81- }
82- #endif
8346
8447void ABTD_thread_exit (ABTI_local * p_local , ABTI_thread * p_thread )
8548{
@@ -98,10 +61,9 @@ static inline void ABTDI_thread_terminate(ABTI_local *p_local,
9861 ABTI_thread * p_thread ,
9962 ABT_bool is_sched )
10063{
101- #if defined(ABT_CONFIG_USE_FCONTEXT )
102- ABTD_thread_context * p_fctx = & p_thread -> ctx ;
64+ ABTD_thread_context * p_ctx = & p_thread -> ctx ;
10365 ABTD_thread_context * p_link = (ABTD_thread_context * )
104- ABTD_atomic_load_ptr ((void * * )& p_fctx -> p_link );
66+ ABTD_atomic_load_ptr ((void * * )& p_ctx -> p_link );
10567 if (p_link ) {
10668 /* If p_link is set, it means that other ULT has called the join. */
10769 ABTI_thread * p_joiner = (ABTI_thread * )p_link ;
@@ -150,15 +112,15 @@ static inline void ABTDI_thread_terminate(ABTI_local *p_local,
150112 * blocked. We have to wake up the joiner ULT. */
151113 do {
152114 p_link = (ABTD_thread_context * )
153- ABTD_atomic_load_ptr ((void * * )& p_fctx -> p_link );
115+ ABTD_atomic_load_ptr ((void * * )& p_ctx -> p_link );
154116 } while (!p_link );
155117 ABTI_thread_set_ready (p_local , (ABTI_thread * )p_link );
156118 }
157119 }
158120
159- /* No other ULT is waiting or blocked for this ULT. Since fcontext does
160- * not switch to other fcontext when it finishes, we need to explicitly
161- * switch to the scheduler. */
121+ /* No other ULT is waiting or blocked for this ULT. Since a context does not
122+ * switch to another context when it finishes, we need to explicitly switch
123+ * to the scheduler. */
162124 ABTI_sched * p_sched ;
163125#ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED
164126 if (p_thread -> is_sched ) {
@@ -180,9 +142,6 @@ static inline void ABTDI_thread_terminate(ABTI_local *p_local,
180142#ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED
181143 }
182144#endif
183- #else
184- #error "Not implemented yet"
185- #endif
186145}
187146
188147static inline void ABTD_thread_terminate_thread (ABTI_local * p_local ,
@@ -215,62 +174,33 @@ void ABTD_thread_cancel(ABTI_local *p_local, ABTI_thread *p_thread)
215174 * ULT has finished its execution and calls ABTD_thread_terminate/exit,
216175 * this function is called by the scheduler. Therefore, we should not
217176 * context switch to the joiner ULT and need to always wake it up. */
218- #if defined(ABT_CONFIG_USE_FCONTEXT )
219- ABTD_thread_context * p_fctx = & p_thread -> ctx ;
177+ ABTD_thread_context * p_ctx = & p_thread -> ctx ;
220178
221179 /* acquire load is not needed here. */
222- if (p_fctx -> p_link ) {
180+ if (p_ctx -> p_link ) {
223181 /* If p_link is set, it means that other ULT has called the join. */
224- ABTI_thread * p_joiner = (ABTI_thread * )p_fctx -> p_link ;
182+ ABTI_thread * p_joiner = (ABTI_thread * )p_ctx -> p_link ;
225183 ABTI_thread_set_ready (p_local , p_joiner );
226184 } else {
227185 uint32_t req = ABTD_atomic_fetch_or_uint32 (& p_thread -> request ,
228186 ABTI_THREAD_REQ_JOIN | ABTI_THREAD_REQ_TERMINATE );
229187 if (req & ABTI_THREAD_REQ_JOIN ) {
230188 /* This case means there has been a join request and the joiner has
231189 * blocked. We have to wake up the joiner ULT. */
232- while (ABTD_atomic_load_ptr ((void * * )& p_fctx -> p_link ) == NULL );
233- ABTI_thread * p_joiner = (ABTI_thread * )p_fctx -> p_link ;
190+ while (ABTD_atomic_load_ptr ((void * * )& p_ctx -> p_link ) == NULL );
191+ ABTI_thread * p_joiner = (ABTI_thread * )p_ctx -> p_link ;
234192 ABTI_thread_set_ready (p_local , p_joiner );
235193 }
236194 }
237- #else
238- #error "Not implemented yet"
239- #endif
240195}
241196
242- #if !defined(ABT_CONFIG_USE_FCONTEXT )
243- static inline
244- void print_bytes (size_t size , void * p_val , FILE * p_os ) {
245- size_t i ;
246- for (i = 0 ; i < size ; i ++ ) {
247- uint8_t val = ((uint8_t * )p_val )[i ];
248- fprintf (p_os , "%02" PRIx8 , val );
249- }
250- }
251- #endif
252-
253197void ABTD_thread_print_context (ABTI_thread * p_thread , FILE * p_os , int indent )
254198{
255199 char * prefix = ABTU_get_indent_str (indent );
256200 ABTD_thread_context * p_ctx = & p_thread -> ctx ;
257- #if defined(ABT_CONFIG_USE_FCONTEXT )
258- fprintf (p_os , "%sfctx : %p\n" , prefix , (void * )p_ctx -> fctx );
201+ fprintf (p_os , "%sp_ctx : %p\n" , prefix , p_ctx -> p_ctx );
259202 fprintf (p_os , "%sp_arg : %p\n" , prefix , p_ctx -> p_arg );
260203 fprintf (p_os , "%sp_link : %p\n" , prefix , (void * )p_ctx -> p_link );
261- #else
262- /* TODO: print information in more detail. */
263- fprintf (p_os , "%suc_link : %p\n" , prefix , p_ctx -> uc_link );
264- fprintf (p_os , "%suc_sigmask : " , prefix );
265- print_bytes (sizeof (sigset_t ), & p_ctx -> uc_sigmask , p_os );
266- fprintf (p_os , "\n" );
267- fprintf (p_os , "%suc_stack : " , prefix );
268- print_bytes (sizeof (stack_t ), & p_ctx -> uc_stack , p_os );
269- fprintf (p_os , "\n" );
270- fprintf (p_os , "%suc_mcontext : " , prefix );
271- print_bytes (sizeof (mcontext_t ), & p_ctx -> uc_mcontext , p_os );
272- fprintf (p_os , "\n" );
273- #endif
274204 fflush (p_os );
275205 ABTU_free (prefix );
276206}
0 commit comments