]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
coroutine: Introduce qemu_coroutine_enter_if_inactive()
authorKevin Wolf <kwolf@redhat.com>
Mon, 7 Nov 2016 15:34:35 +0000 (16:34 +0100)
committerKevin Wolf <kwolf@redhat.com>
Mon, 9 Jan 2017 12:30:52 +0000 (13:30 +0100)
In the context of asynchronous work, if we have a worker coroutine that
didn't yield, the parent coroutine cannot be reentered because it hasn't
yielded yet. In this case we don't even have to reenter the parent
because it will see that the work is already done and won't even yield.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
include/qemu/coroutine.h
util/qemu-coroutine.c

index e6a60d55fd57e4c8fd664d5562ec2b0911c29a8f..12584ed1b7fa5a5cd7ccec7e990c55f180d8090f 100644 (file)
@@ -70,6 +70,12 @@ Coroutine *qemu_coroutine_create(CoroutineEntry *entry, void *opaque);
  */
 void qemu_coroutine_enter(Coroutine *coroutine);
 
+/**
+ * Transfer control to a coroutine if it's not active (i.e. part of the call
+ * stack of the running coroutine). Otherwise, do nothing.
+ */
+void qemu_coroutine_enter_if_inactive(Coroutine *co);
+
 /**
  * Transfer control back to a coroutine's caller
  *
index 737bffa984a71bd86e37bd51feec87ef5d42a982..a5d2f6c0c32fd0ce57fe3218bcc98509d247c433 100644 (file)
@@ -131,6 +131,13 @@ void qemu_coroutine_enter(Coroutine *co)
     }
 }
 
+void qemu_coroutine_enter_if_inactive(Coroutine *co)
+{
+    if (!qemu_coroutine_entered(co)) {
+        qemu_coroutine_enter(co);
+    }
+}
+
 void coroutine_fn qemu_coroutine_yield(void)
 {
     Coroutine *self = qemu_coroutine_self();