4 * Copyright IBM, Corp. 2011
7 * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
8 * Kevin Wolf <kwolf@redhat.com>
10 * This work is licensed under the terms of the GNU LGPL, version 2 or later.
11 * See the COPYING.LIB file in the top-level directory.
16 #include "qemu-common.h"
17 #include "qemu-coroutine.h"
18 #include "qemu-coroutine-int.h"
20 Coroutine
*qemu_coroutine_create(CoroutineEntry
*entry
)
22 Coroutine
*co
= qemu_coroutine_new();
27 static void coroutine_swap(Coroutine
*from
, Coroutine
*to
)
31 ret
= qemu_coroutine_switch(from
, to
, COROUTINE_YIELD
);
36 case COROUTINE_TERMINATE
:
37 trace_qemu_coroutine_terminate(to
);
38 qemu_coroutine_delete(to
);
45 void qemu_coroutine_enter(Coroutine
*co
, void *opaque
)
47 Coroutine
*self
= qemu_coroutine_self();
49 trace_qemu_coroutine_enter(self
, co
, opaque
);
52 fprintf(stderr
, "Co-routine re-entered recursively\n");
57 co
->entry_arg
= opaque
;
58 coroutine_swap(self
, co
);
61 void coroutine_fn
qemu_coroutine_yield(void)
63 Coroutine
*self
= qemu_coroutine_self();
64 Coroutine
*to
= self
->caller
;
66 trace_qemu_coroutine_yield(self
, to
);
69 fprintf(stderr
, "Co-routine is yielding to no one\n");
74 coroutine_swap(self
, to
);