block: Add coroutine support to synchronous I/O functions
[qemu/stefanha.git] / continuation.h
blob112df659abe2ee6b19b98727c8588a56e31c3eea
1 /*
2 * GTK VNC Widget
4 * Copyright (C) 2006 Anthony Liguori <anthony@codemonkey.ws>
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.
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.
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
21 #ifndef _CONTINUATION_H_
22 #define _CONTINUATION_H_
24 #include <ucontext.h>
26 struct continuation
28 char *stack;
29 size_t stack_size;
30 void (*entry)(struct continuation *cc);
31 int (*release)(struct continuation *cc);
33 /* private */
34 ucontext_t uc;
35 ucontext_t last;
36 int exited;
39 int cc_init(struct continuation *cc);
41 int cc_release(struct continuation *cc);
43 /* you can use an uninitialized struct continuation for from if you do not have
44 the current continuation handy. */
45 int cc_swap(struct continuation *from, struct continuation *to);
47 #define offset_of(type, member) ((unsigned long)(&((type *)0)->member))
48 #ifndef container_of
49 #define container_of(obj, type, member) \
50 (type *)(((char *)obj) - offset_of(type, member))
51 #endif
53 #endif
55 * Local variables:
56 * c-indent-level: 8
57 * c-basic-offset: 8
58 * tab-width: 8
59 * End: