aboutsummaryrefslogtreecommitdiff
path: root/qemu-coroutine.c
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2013-05-17 15:51:26 +0200
committerStefan Hajnoczi <stefanha@redhat.com>2013-05-24 16:17:56 +0200
commit02ffb504485f0920cfc75a0982a602f824a9a4f4 (patch)
tree036ffed1e7ca8bed9042bcaf19f439b1065dbf01 /qemu-coroutine.c
parentb84c4586234b26ccc875595713f6f4491e5b3385 (diff)
coroutine: stop using AioContext in CoQueue
qemu_co_queue_next(&queue) arranges that the next queued coroutine is run at a later point in time. This deferred restart is useful because the caller may not want to transfer control yet. This behavior was implemented using QEMUBH in the past, which meant that CoQueue (and hence CoMutex and CoRwlock) had a dependency on the AioContext event loop. This hidden dependency causes trouble when we move to a world with multiple event loops - now qemu_co_queue_next() needs to know which event loop to schedule the QEMUBH in. After pondering how to stash AioContext I realized the best solution is to not use AioContext at all. This patch implements the deferred restart behavior purely in terms of coroutines and no longer uses QEMUBH. Here is how it works: Each Coroutine has a wakeup queue that starts out empty. When qemu_co_queue_next() is called, the next coroutine is added to our wakeup queue. The wakeup queue is processed when we yield or terminate. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'qemu-coroutine.c')
-rw-r--r--qemu-coroutine.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/qemu-coroutine.c b/qemu-coroutine.c
index 60ac79e680..423430d3a0 100644
--- a/qemu-coroutine.c
+++ b/qemu-coroutine.c
@@ -45,6 +45,7 @@ Coroutine *qemu_coroutine_create(CoroutineEntry *entry)
}
co->entry = entry;
+ QTAILQ_INIT(&co->co_queue_wakeup);
return co;
}
@@ -87,6 +88,8 @@ static void coroutine_swap(Coroutine *from, Coroutine *to)
ret = qemu_coroutine_switch(from, to, COROUTINE_YIELD);
+ qemu_co_queue_run_restart(to);
+
switch (ret) {
case COROUTINE_YIELD:
return;