|
| From: | Avi Kivity |
| Subject: | Re: [Qemu-devel] [RFC][PATCH 01/12] coroutine: Add gtk-vnc coroutines library |
| Date: | Wed, 26 Jan 2011 17:25:39 +0200 |
| User-agent: | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Lightning/1.0b3pre Thunderbird/3.1.7 |
On 01/22/2011 11:29 AM, Stefan Hajnoczi wrote:
Asynchronous image format code is becoming very complex. Let's try
using coroutines to write sequential code without callbacks but use
coroutines to switch stacks under the hood.
+
+int cc_swap(struct continuation *from, struct continuation *to)
+{
+ to->exited = 0;
+ if (getcontext(&to->last) == -1)
+ return -1;
+ else if (to->exited == 0)
+ to->exited = 1;
+ else if (to->exited == 1)
+ return 1;
+
+ return swapcontext(&from->uc,&to->uc);
+}
swapcontext() is very slow, involving the fpu and a syscall.A nice trick I've used in the past is to use getcontext/makecontext for the initial setup and setjmp/longjmp for switching. Of course this can be done later, as an optimization.
-- error compiling committee.c: too many arguments to function
| [Prev in Thread] | Current Thread | [Next in Thread] |