Patchwork [RFC,08/12] coroutine: Add qemu_in_coroutine()

login
register
mail settings
Submitter Stefan Hajnoczi
Date Jan. 22, 2011, 9:29 a.m.
Message ID <1295688567-25496-9-git-send-email-stefanha@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/79983/
State New
Headers show

Comments

Stefan Hajnoczi - Jan. 22, 2011, 9:29 a.m.
The qemu_in_coroutine() function checks whether or not we are currently
in a user coroutine.  This can be used to distinguish between executing
normal vcpu or iothread code from executing a coroutine.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 qemu-coroutine.c |    5 +++++
 qemu-coroutine.h |    7 +++++++
 2 files changed, 12 insertions(+), 0 deletions(-)

Patch

diff --git a/qemu-coroutine.c b/qemu-coroutine.c
index e55b7c6..9318600 100644
--- a/qemu-coroutine.c
+++ b/qemu-coroutine.c
@@ -43,3 +43,8 @@  Coroutine * coroutine_fn qemu_coroutine_self(void)
 {
     return (Coroutine*)coroutine_self();
 }
+
+bool qemu_in_coroutine(void)
+{
+    return !coroutine_is_leader(coroutine_self());
+}
diff --git a/qemu-coroutine.h b/qemu-coroutine.h
index 41f90bb..1fad3bf 100644
--- a/qemu-coroutine.h
+++ b/qemu-coroutine.h
@@ -14,6 +14,8 @@ 
 #ifndef QEMU_COROUTINE_H
 #define QEMU_COROUTINE_H
 
+#include <stdbool.h>
+
 /**
  * Mark a function that executes in coroutine context
  *
@@ -78,4 +80,9 @@  void * coroutine_fn qemu_coroutine_yield(void *opaque);
  */
 Coroutine * coroutine_fn qemu_coroutine_self(void);
 
+/**
+ * Return whether or not currently inside a coroutine
+ */
+bool qemu_in_coroutine(void);
+
 #endif /* QEMU_COROUTINE_H */