1 /*
2  * GTK VNC Widget
3  *
4  * Copyright (C) 2006  Anthony Liguori <anthony@codemonkey.ws>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.0 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20 
21 #ifndef _CONTINUATION_H_
22 #define _CONTINUATION_H_
23 
24 #include "spice-common.h"
25 #include <stddef.h>
26 #include <ucontext.h>
27 #include <setjmp.h>
28 
29 struct continuation
30 {
31 	char *stack;
32 	size_t stack_size;
33 	void (*entry)(struct continuation *cc);
34 	int (*release)(struct continuation *cc);
35 
36 	/* private */
37 	ucontext_t uc;
38 	ucontext_t last;
39 	int exited;
40 	jmp_buf jmp;
41 };
42 
43 void cc_init(struct continuation *cc);
44 
45 int cc_release(struct continuation *cc);
46 
47 /* you can use an uninitialized struct continuation for from if you do not have
48    the current continuation handy. */
49 int cc_swap(struct continuation *from, struct continuation *to);
50 
51 #define offset_of(type, member) ((unsigned long)(&((type *)0)->member))
52 #define container_of(obj, type, member)                                 \
53         SPICE_ALIGNED_CAST(type *,                                      \
54                            (((char *)obj) - offset_of(type, member)))
55 
56 #endif
57 /*
58  * Local variables:
59  *  c-indent-level: 8
60  *  c-basic-offset: 8
61  *  tab-width: 8
62  * End:
63  */
64