Skip to content

Commit 5c387f1

Browse files
context: clean up
This patch does the following: - changes fctx to ctx/p_ctx if "fctx" is not fcontext specific. - fixes up white spaces. - updates comments that mention fcontext.
1 parent df593cb commit 5c387f1

File tree

7 files changed

+44
-43
lines changed

7 files changed

+44
-43
lines changed

src/arch/abtd_thread.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ static inline void ABTD_thread_terminate_sched(ABTI_local *p_local,
1212

1313
void ABTD_thread_func_wrapper_thread(void *p_arg)
1414
{
15-
ABTD_thread_context *p_fctx = (ABTD_thread_context *)p_arg;
16-
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;
1717

18-
thread_func(p_fctx->p_arg);
18+
thread_func(p_ctx->p_arg);
1919

2020
/* NOTE: ctx is located in the beginning of ABTI_thread */
21-
ABTI_thread *p_thread = (ABTI_thread *)p_fctx;
21+
ABTI_thread *p_thread = (ABTI_thread *)p_ctx;
2222
#ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED
2323
ABTI_ASSERT(p_thread->is_sched == NULL);
2424
#endif
@@ -29,13 +29,13 @@ void ABTD_thread_func_wrapper_thread(void *p_arg)
2929

3030
void ABTD_thread_func_wrapper_sched(void *p_arg)
3131
{
32-
ABTD_thread_context *p_fctx = (ABTD_thread_context *)p_arg;
33-
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;
3434

35-
thread_func(p_fctx->p_arg);
35+
thread_func(p_ctx->p_arg);
3636

3737
/* NOTE: ctx is located in the beginning of ABTI_thread */
38-
ABTI_thread *p_thread = (ABTI_thread *)p_fctx;
38+
ABTI_thread *p_thread = (ABTI_thread *)p_ctx;
3939
#ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED
4040
ABTI_ASSERT(p_thread->is_sched != NULL);
4141
#endif
@@ -61,9 +61,9 @@ static inline void ABTDI_thread_terminate(ABTI_local *p_local,
6161
ABTI_thread *p_thread,
6262
ABT_bool is_sched)
6363
{
64-
ABTD_thread_context *p_fctx = &p_thread->ctx;
64+
ABTD_thread_context *p_ctx = &p_thread->ctx;
6565
ABTD_thread_context *p_link = (ABTD_thread_context *)
66-
ABTD_atomic_load_ptr((void **)&p_fctx->p_link);
66+
ABTD_atomic_load_ptr((void **)&p_ctx->p_link);
6767
if (p_link) {
6868
/* If p_link is set, it means that other ULT has called the join. */
6969
ABTI_thread *p_joiner = (ABTI_thread *)p_link;
@@ -112,15 +112,15 @@ static inline void ABTDI_thread_terminate(ABTI_local *p_local,
112112
* blocked. We have to wake up the joiner ULT. */
113113
do {
114114
p_link = (ABTD_thread_context *)
115-
ABTD_atomic_load_ptr((void **)&p_fctx->p_link);
115+
ABTD_atomic_load_ptr((void **)&p_ctx->p_link);
116116
} while (!p_link);
117117
ABTI_thread_set_ready(p_local, (ABTI_thread *)p_link);
118118
}
119119
}
120120

121-
/* No other ULT is waiting or blocked for this ULT. Since fcontext does
122-
* not switch to other fcontext when it finishes, we need to explicitly
123-
* 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. */
124124
ABTI_sched *p_sched;
125125
#ifndef ABT_CONFIG_DISABLE_STACKABLE_SCHED
126126
if (p_thread->is_sched) {
@@ -174,21 +174,21 @@ void ABTD_thread_cancel(ABTI_local *p_local, ABTI_thread *p_thread)
174174
* ULT has finished its execution and calls ABTD_thread_terminate/exit,
175175
* this function is called by the scheduler. Therefore, we should not
176176
* context switch to the joiner ULT and need to always wake it up. */
177-
ABTD_thread_context *p_fctx = &p_thread->ctx;
177+
ABTD_thread_context *p_ctx = &p_thread->ctx;
178178

179179
/* acquire load is not needed here. */
180-
if (p_fctx->p_link) {
180+
if (p_ctx->p_link) {
181181
/* If p_link is set, it means that other ULT has called the join. */
182-
ABTI_thread *p_joiner = (ABTI_thread *)p_fctx->p_link;
182+
ABTI_thread *p_joiner = (ABTI_thread *)p_ctx->p_link;
183183
ABTI_thread_set_ready(p_local, p_joiner);
184184
} else {
185185
uint32_t req = ABTD_atomic_fetch_or_uint32(&p_thread->request,
186186
ABTI_THREAD_REQ_JOIN | ABTI_THREAD_REQ_TERMINATE);
187187
if (req & ABTI_THREAD_REQ_JOIN) {
188188
/* This case means there has been a join request and the joiner has
189189
* blocked. We have to wake up the joiner ULT. */
190-
while (ABTD_atomic_load_ptr((void **)&p_fctx->p_link) == NULL);
191-
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;
192192
ABTI_thread_set_ready(p_local, p_joiner);
193193
}
194194
}
@@ -198,7 +198,7 @@ void ABTD_thread_print_context(ABTI_thread *p_thread, FILE *p_os, int indent)
198198
{
199199
char *prefix = ABTU_get_indent_str(indent);
200200
ABTD_thread_context *p_ctx = &p_thread->ctx;
201-
fprintf(p_os, "%sfctx : %p\n", prefix, (void *)p_ctx->fctx);
201+
fprintf(p_os, "%sp_ctx : %p\n", prefix, p_ctx->p_ctx);
202202
fprintf(p_os, "%sp_arg : %p\n", prefix, p_ctx->p_arg);
203203
fprintf(p_os, "%sp_link : %p\n", prefix, (void *)p_ctx->p_link);
204204
fflush(p_os);

src/include/Makefile.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ noinst_HEADERS = \
99
include/abt_config.h \
1010
include/abtd.h \
1111
include/abtd_atomic.h \
12+
include/abtd_context.h \
1213
include/abtd_fcontext.h \
1314
include/abtd_thread.h \
1415
include/abtd_ucontext.h \
15-
include/abtd_context.h \
1616
include/abti.h \
1717
include/abti_barrier.h \
1818
include/abti_cond.h \

src/include/abtd_context.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
#include <ucontext.h>
1414
#endif
1515

16-
typedef void * fcontext_t;
17-
1816
typedef struct ABTD_thread_context {
19-
fcontext_t fctx; /* actual context */
20-
void (*f_thread)(void *); /* ULT function */
21-
void * p_arg; /* ULT function argument */
17+
void * p_ctx; /* actual context of fcontext, or a
18+
* pointer to uctx */
19+
void (*f_thread)(void *); /* ULT function */
20+
void * p_arg; /* ULT function argument */
2221
struct ABTD_thread_context *p_link; /* pointer to scheduler context */
2322
#ifndef ABT_CONFIG_USE_FCONTEXT
24-
ucontext_t uctx; /* ucontext entity pointed by fctx */
23+
ucontext_t uctx; /* ucontext entity pointed by p_ctx */
2524
void (*f_uctx_thread)(void *); /* root function called by ucontext */
2625
void * p_uctx_arg; /* argument for root function */
2726
#endif

src/include/abtd_fcontext.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef ABTD_FCONTEXT_H_INCLUDED
77
#define ABTD_FCONTEXT_H_INCLUDED
88

9+
typedef void *fcontext_t;
10+
911
#if defined(ABT_C_HAVE_VISIBILITY)
1012
#define ABT_API_PRIVATE __attribute__((visibility ("hidden")))
1113
#else
@@ -25,29 +27,29 @@ static inline
2527
void ABTD_thread_context_make(ABTD_thread_context *p_ctx, void *sp, size_t size,
2628
void (*thread_func)(void *))
2729
{
28-
p_ctx->fctx = make_fcontext(sp, size, thread_func);
30+
p_ctx->p_ctx = make_fcontext(sp, size, thread_func);
2931
}
3032

3133
static inline
3234
void ABTD_thread_context_jump(ABTD_thread_context *p_old,
3335
ABTD_thread_context *p_new, void *arg)
3436
{
35-
jump_fcontext(&p_old->fctx, p_new->fctx, arg);
37+
jump_fcontext(&p_old->p_ctx, p_new->p_ctx, arg);
3638
}
3739

3840
static inline
3941
void ABTD_thread_context_take(ABTD_thread_context *p_old,
4042
ABTD_thread_context *p_new, void *arg)
4143
{
42-
take_fcontext(&p_old->fctx, p_new->fctx, arg);
44+
take_fcontext(&p_old->p_ctx, p_new->p_ctx, arg);
4345
}
4446

4547
#if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION
4648
static inline
4749
void ABTD_thread_context_init_and_call(ABTD_thread_context *p_ctx, void *sp,
4850
void (*thread_func)(void *), void *arg)
4951
{
50-
init_and_call_fcontext(arg, thread_func, sp, &p_ctx->fctx);
52+
init_and_call_fcontext(arg, thread_func, sp, &p_ctx->p_ctx);
5153
}
5254
#endif
5355

src/include/abtd_thread.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int ABTDI_thread_context_create(ABTD_thread_context *p_link,
2828
int abt_errno = ABT_SUCCESS;
2929
void *p_stacktop;
3030

31-
/* fcontext uses the top address of stack.
31+
/* ABTD_thread_context_make uses the top address of stack.
3232
Note that the parameter, p_stack, points to the bottom of stack. */
3333
p_stacktop = (void *)(((char *)p_stack) + stacksize);
3434

@@ -67,11 +67,11 @@ int ABTD_thread_context_invalidate(ABTD_thread_context *p_newctx)
6767
{
6868
int abt_errno = ABT_SUCCESS;
6969
#if ABT_CONFIG_THREAD_TYPE == ABT_THREAD_TYPE_DYNAMIC_PROMOTION
70-
/* fctx is used to check whether the context requires dynamic promotion is
70+
/* p_ctx is used to check whether the context requires dynamic promotion is
7171
* necessary or not, so this value must not be NULL. */
72-
p_newctx->fctx = (void *)((intptr_t)0x1);
72+
p_newctx->p_ctx = (void *)((intptr_t)0x1);
7373
#else
74-
p_newctx->fctx = NULL;
74+
p_newctx->p_ctx = NULL;
7575
#endif
7676
p_newctx->f_thread = NULL;
7777
p_newctx->p_arg = NULL;
@@ -86,7 +86,7 @@ int ABTD_thread_context_init(ABTD_thread_context *p_link,
8686
ABTD_thread_context *p_newctx)
8787
{
8888
int abt_errno = ABT_SUCCESS;
89-
p_newctx->fctx = NULL;
89+
p_newctx->p_ctx = NULL;
9090
p_newctx->f_thread = f_thread;
9191
p_newctx->p_arg = p_arg;
9292
p_newctx->p_link = p_link;
@@ -100,9 +100,9 @@ int ABTD_thread_context_arm_thread(size_t stacksize, void *p_stack,
100100
/* This function *arms* the dynamic promotion thread (initialized by
101101
* ABTD_thread_context_init) as if it were created by
102102
* ABTD_thread_context_create; this function fully creates the context
103-
* so that the thread can be run by jump_fcontext. */
103+
* so that the thread can be run by ABTD_thread_context_jump. */
104104
int abt_errno = ABT_SUCCESS;
105-
/* fcontext uses the top address of stack.
105+
/* ABTD_thread_context_make uses the top address of stack.
106106
Note that the parameter, p_stack, points to the bottom of stack. */
107107
void *p_stacktop = (void *)(((char *)p_stack) + stacksize);
108108
ABTD_thread_context_make(p_newctx, p_stacktop, stacksize,
@@ -142,7 +142,7 @@ ABT_bool ABTD_thread_context_is_dynamic_promoted(ABTD_thread_context *p_ctx)
142142
{
143143
/* Check if the ULT has been dynamically promoted; internally, it checks if
144144
* the context is NULL. */
145-
return p_ctx->fctx ? ABT_TRUE : ABT_FALSE;
145+
return p_ctx->p_ctx ? ABT_TRUE : ABT_FALSE;
146146
}
147147

148148
static inline

src/include/abtd_ucontext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void ABTD_thread_context_make(ABTD_thread_context *p_ctx, void *sp, size_t size,
2828
void (*thread_func)(void *))
2929
{
3030
getcontext(&p_ctx->uctx);
31-
p_ctx->fctx = &p_ctx->uctx;
31+
p_ctx->p_ctx = &p_ctx->uctx;
3232

3333
/* uc_link is not used. */
3434
p_ctx->uctx.uc_link = NULL;

src/include/abti_thread.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ void ABTI_thread_context_switch_sched_to_thread_internal(ABTI_local *p_local,
222222
ABTI_ASSERT(p_prev == p_new);
223223
/* See ABTDI_thread_terminate for details.
224224
* TODO: avoid making a copy of the code. */
225-
ABTD_thread_context *p_fctx = &p_prev->ctx;
225+
ABTD_thread_context *p_ctx = &p_prev->ctx;
226226
ABTD_thread_context *p_link = (ABTD_thread_context *)
227-
ABTD_atomic_load_ptr((void **)&p_fctx->p_link);
227+
ABTD_atomic_load_ptr((void **)&p_ctx->p_link);
228228
if (p_link) {
229229
/* If p_link is set, it means that other ULT has called the
230230
* join. */
@@ -246,7 +246,7 @@ void ABTI_thread_context_switch_sched_to_thread_internal(ABTI_local *p_local,
246246
*/
247247
do {
248248
p_link = (ABTD_thread_context *)
249-
ABTD_atomic_load_ptr((void **)&p_fctx->p_link);
249+
ABTD_atomic_load_ptr((void **)&p_ctx->p_link);
250250
} while (!p_link);
251251
ABTI_thread_set_ready(p_local, (ABTI_thread *)p_link);
252252
}

0 commit comments

Comments
 (0)