alpha: give ISA bus to ISA methods
[qemu/rayw.git] / qemu-coroutine.c
blob600be2643c7cf0efa59fdd7ef1a4266eade30d8e
1 /*
2 * QEMU coroutines
4 * Copyright IBM, Corp. 2011
6 * Authors:
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.
15 #include "trace.h"
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();
23 co->entry = entry;
24 return co;
27 static void coroutine_swap(Coroutine *from, Coroutine *to)
29 CoroutineAction ret;
31 ret = qemu_coroutine_switch(from, to, COROUTINE_YIELD);
33 switch (ret) {
34 case COROUTINE_YIELD:
35 return;
36 case COROUTINE_TERMINATE:
37 trace_qemu_coroutine_terminate(to);
38 qemu_coroutine_delete(to);
39 return;
40 default:
41 abort();
45 void qemu_coroutine_enter(Coroutine *co, void *opaque)
47 Coroutine *self = qemu_coroutine_self();
49 trace_qemu_coroutine_enter(self, co, opaque);
51 if (co->caller) {
52 fprintf(stderr, "Co-routine re-entered recursively\n");
53 abort();
56 co->caller = self;
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);
68 if (!to) {
69 fprintf(stderr, "Co-routine is yielding to no one\n");
70 abort();
73 self->caller = NULL;
74 coroutine_swap(self, to);