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


Reply via email to