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