Patchwork [RFC,V1,01/14] qemu-coroutine: Add simple work queue support

login
register
mail settings
Submitter Peter A. G. Crosthwaite
Date Aug. 25, 2011, 6:41 a.m.
Message ID <1314254480-22438-2-git-send-email-peter.crosthwaite@petalogix.com>
Download mbox | patch
Permalink /patch/111467/
State New
Headers show

Comments

Peter A. G. Crosthwaite - Aug. 25, 2011, 6:41 a.m.
Add a function co_queue_enter_next() which will immediately transfer
control to the coroutine at the head of a co queue. This can be used for
implementing simple work queues where the manager of a co-queue only
needs to enter queued routines one at a time.

Signed-off-by: Peter A. G. Crosthwaite <peter.crosthwaite@petalogix.com>
---
 qemu-coroutine-lock.c |   13 +++++++++++++
 qemu-coroutine.h      |    9 +++++++++
 2 files changed, 22 insertions(+), 0 deletions(-)

Patch

diff --git a/qemu-coroutine-lock.c b/qemu-coroutine-lock.c
index a80f437..4da670d 100644
--- a/qemu-coroutine-lock.c
+++ b/qemu-coroutine-lock.c
@@ -75,6 +75,19 @@  bool qemu_co_queue_next(CoQueue *queue)
     return (next != NULL);
 }
 
+bool qemu_co_queue_enter_next(CoQueue *queue)
+{
+    Coroutine *next;
+
+    next = QTAILQ_FIRST(&queue->entries);
+    if (next) {
+        QTAILQ_REMOVE(&queue->entries, next, co_queue_next);
+        qemu_coroutine_enter(next, NULL);
+    }
+
+    return (next != NULL);
+}
+
 bool qemu_co_queue_empty(CoQueue *queue)
 {
     return (QTAILQ_FIRST(&queue->entries) == NULL);
diff --git a/qemu-coroutine.h b/qemu-coroutine.h
index 2f2fd95..65776e5 100644
--- a/qemu-coroutine.h
+++ b/qemu-coroutine.h
@@ -125,6 +125,15 @@  void coroutine_fn qemu_co_queue_wait(CoQueue *queue);
 bool qemu_co_queue_next(CoQueue *queue);
 
 /**
+ * Transfers control to the next coroutine in the CoQueue and removes it from
+ * the queue.
+ *
+ * Returns true once after control transfers back to caller, or false
+ * immediately if the queue is empty.
+ */
+bool qemu_co_queue_enter_next(CoQueue *queue);
+
+/**
  * Checks if the CoQueue is empty.
  */
 bool qemu_co_queue_empty(CoQueue *queue);