Cleanup #1489: Delete GPU dummy mempool
[charm.git] / src / util / uFcontext.h
blob5723dd2d9f7f2c086e5eadeeb962e0f090cbf3d2
1 #ifndef CMK_FCONTEXT_H
2 #define CMK_FCONTEXT_H
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 typedef void * fcontext_t;
9 typedef struct uFcontext_stack_t {
10 void *ss_sp;
11 int ss_flags;
12 size_t ss_size;
13 } uFcontext_stack_t;
15 typedef struct transfer_t {
16 fcontext_t fctx;
17 void * data;
18 } transfer_t;
20 extern void CthStartThread(transfer_t);
21 typedef void (*uFcontext_fn_t)(transfer_t);
23 typedef struct data_t {
24 void * from;
25 void * data;
26 } data_t;
28 typedef struct uFcontext_t {
29 fcontext_t fctx;
30 void (* func)(void *);
31 uFcontext_stack_t uc_stack;
32 struct uFcontext_t *uc_link;
33 void *arg;
34 data_t param;
35 } uFcontext_t;
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) {
54 return 0;
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) {
62 __ucp->arg = arg;
63 __ucp->uc_link = NULL;
64 __ucp->func = fn;
65 fcontext_t t = make_fcontext(__ucp->uc_stack.ss_sp, __ucp->uc_stack.ss_size, __func);
66 __ucp->fctx = t;
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;
75 if (prev_ucp)
76 prev_ucp->fctx = t.fctx;
77 return 0;
79 #ifdef __cplusplus
81 #endif
82 #endif