qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [RFC][PATCH 01/12] coroutine: Add gtk-vnc coroutines li


From: Avi Kivity
Subject: Re: [Qemu-devel] [RFC][PATCH 01/12] coroutine: Add gtk-vnc coroutines library
Date: Wed, 26 Jan 2011 18:13:58 +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/26/2011 06:00 PM, Anthony Liguori wrote:
On 01/26/2011 09:25 AM, Avi Kivity wrote:
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.

Yeah, there are further optimizations that can be had but really, it's not important here. In fact, I'd rather start with the threaded version just because it's far more portable than ucontext.


What do you mean by threaded version?

--
error compiling committee.c: too many arguments to function




reply via email to

[Prev in Thread] Current Thread [Next in Thread]