7 typedef void * fcontext_t
;
9 typedef struct uFcontext_stack_t
{
15 typedef struct transfer_t
{
20 extern void CthStartThread(transfer_t
);
21 typedef void (*uFcontext_fn_t
)(transfer_t
);
23 typedef struct data_t
{
28 typedef struct uFcontext_t
{
30 void (* func
)(void *);
31 uFcontext_stack_t uc_stack
;
32 struct uFcontext_t
*uc_link
;
37 transfer_t
jump_fcontext(fcontext_t
const to
, void *vp
);
38 fcontext_t
make_fcontext(void *sp
, size_t size
, void (*fn
)(transfer_t
));
39 transfer_t
ontop_fcontext(fcontext_t
const to
, void *vp
, transfer_t (*fn
)(transfer_t
));
41 /* Get user context and store it in variable pointed to by UCP. */
42 extern int getJcontext (uFcontext_t
*__ucp
);
44 /* Set user context from information of variable pointed to by UCP. */
45 extern int setJcontext (uFcontext_t
*__ucp
);
47 /* Save current context in context variable pointed to by OUCP and set
48 context from variable pointed to by UCP. */
49 extern int swapJcontext (uFcontext_t
*__oucp
, uFcontext_t
*__ucp
);
51 extern void makeJcontext(uFcontext_t
*__ucp
, uFcontext_fn_t
, void (*fn
)(void*), void *arg
);
52 /* To keep the interface of uFcontext the same as the ucontext and uJcontext*/
53 int getJcontext (uFcontext_t
*__ucp
) {
57 int setJcontext (uFcontext_t
*__ucp
) {
58 return swapJcontext(NULL
, __ucp
);
61 void makeJcontext (uFcontext_t
*__ucp
, uFcontext_fn_t __func
, void (*fn
)(void *), void *arg
) {
63 __ucp
->uc_link
= NULL
;
65 fcontext_t t
= make_fcontext(__ucp
->uc_stack
.ss_sp
, __ucp
->uc_stack
.ss_size
, __func
);
69 int swapJcontext(uFcontext_t
*old_ucp
, uFcontext_t
*new_ucp
) {
70 new_ucp
->param
.from
= old_ucp
;
71 new_ucp
->param
.data
= new_ucp
;
72 transfer_t t
= jump_fcontext(new_ucp
->fctx
, &(new_ucp
->param
));
73 data_t
*old_data
= (data_t
*)t
.data
;
74 uFcontext_t
*prev_ucp
= (uFcontext_t
*)old_data
->from
;
76 prev_ucp
->fctx
= t
.fctx
;