block: Add coroutine support to synchronous I/O functions
[qemu/stefanha.git] / coroutine.h
blob3aca19a0b0a8ba236be99cf3e1acc8bfe3def007
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 _COROUTINE_H_
22 #define _COROUTINE_H_
24 #define WITH_UCONTEXT 1
26 #if WITH_UCONTEXT
27 #include "continuation.h"
28 #else
29 #include <glib.h>
30 #endif
32 struct coroutine
34 size_t stack_size;
35 void *(*entry)(void *);
36 int (*release)(struct coroutine *);
38 /* read-only */
39 int exited;
41 /* private */
42 struct coroutine *caller;
43 void *data;
45 #if WITH_UCONTEXT
46 struct continuation cc;
47 #else
48 GThread *thread;
49 gboolean runnable;
50 #endif
53 int coroutine_init(struct coroutine *co);
55 int coroutine_release(struct coroutine *co);
57 void *coroutine_swap(struct coroutine *from, struct coroutine *to, void *arg);
59 struct coroutine *coroutine_self(void);
61 int coroutine_is_leader(struct coroutine *co);
63 void *coroutine_yieldto(struct coroutine *to, void *arg);
65 void *coroutine_yield(void *arg);
67 #endif
69 * Local variables:
70 * c-indent-level: 8
71 * c-basic-offset: 8
72 * tab-width: 8
73 * End: