summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2016-09-27 16:18:34 +0100
committerStefan Hajnoczi <stefanha@redhat.com>2016-09-28 17:11:23 +0100
commitf643e469f31df735fd5c42ab317f96ebfe749871 (patch)
treedc93c449d6963efb3e5c553442348c390f76d83f
parent844c82296f8bd6ceff8d170f3740740f3ce84b73 (diff)
downloadqemu-f643e469f31df735fd5c42ab317f96ebfe749871.tar.gz
coroutine: add qemu_coroutine_entered() function
See the doc comments for a description of this new coroutine API. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Message-id: 1474989516-18255-2-git-send-email-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
-rw-r--r--include/qemu/coroutine.h13
-rw-r--r--util/qemu-coroutine.c5
2 files changed, 18 insertions, 0 deletions
diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h
index 29a20782f0..e6a60d55fd 100644
--- a/include/qemu/coroutine.h
+++ b/include/qemu/coroutine.h
@@ -92,6 +92,19 @@ Coroutine *coroutine_fn qemu_coroutine_self(void);
*/
bool qemu_in_coroutine(void);
+/**
+ * Return true if the coroutine is currently entered
+ *
+ * A coroutine is "entered" if it has not yielded from the current
+ * qemu_coroutine_enter() call used to run it. This does not mean that the
+ * coroutine is currently executing code since it may have transferred control
+ * to another coroutine using qemu_coroutine_enter().
+ *
+ * When several coroutines enter each other there may be no way to know which
+ * ones have already been entered. In such situations this function can be
+ * used to avoid recursively entering coroutines.
+ */
+bool qemu_coroutine_entered(Coroutine *co);
/**
diff --git a/util/qemu-coroutine.c b/util/qemu-coroutine.c
index 3cbf225487..737bffa984 100644
--- a/util/qemu-coroutine.c
+++ b/util/qemu-coroutine.c
@@ -146,3 +146,8 @@ void coroutine_fn qemu_coroutine_yield(void)
self->caller = NULL;
qemu_coroutine_switch(self, to, COROUTINE_YIELD);
}
+
+bool qemu_coroutine_entered(Coroutine *co)
+{
+ return co->caller;
+}