]> git.proxmox.com Git - qemu.git/commitdiff
coroutine: add qemu_co_queue_restart_all()
authorStefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Thu, 17 Nov 2011 13:40:26 +0000 (13:40 +0000)
committerKevin Wolf <kwolf@redhat.com>
Mon, 5 Dec 2011 13:51:38 +0000 (14:51 +0100)
It's common to wake up all waiting coroutines.  Introduce the
qemu_co_queue_restart_all() function to do this instead of looping over
qemu_co_queue_next() in every caller.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/qcow2.c
qemu-coroutine-lock.c
qemu-coroutine.h

index 5ac9fb482818bbd7023b3ed5ba478337760c1476..a2be7d79490c3ff699e83dd5e3a9935d2d1cba75 100644 (file)
@@ -516,7 +516,7 @@ static void run_dependent_requests(BDRVQcowState *s, QCowL2Meta *m)
     /* Restart all dependent requests */
     if (!qemu_co_queue_empty(&m->dependent_requests)) {
         qemu_co_mutex_unlock(&s->lock);
-        while(qemu_co_queue_next(&m->dependent_requests));
+        qemu_co_queue_restart_all(&m->dependent_requests);
         qemu_co_mutex_lock(&s->lock);
     }
 }
index 9549c075ee7de3ebdef701c2f603a96516a36911..26ad76bf50c349cdedde810b8052aa250002b8a8 100644 (file)
@@ -84,6 +84,13 @@ bool qemu_co_queue_next(CoQueue *queue)
     return (next != NULL);
 }
 
+void qemu_co_queue_restart_all(CoQueue *queue)
+{
+    while (qemu_co_queue_next(queue)) {
+        /* Do nothing */
+    }
+}
+
 bool qemu_co_queue_empty(CoQueue *queue)
 {
     return (QTAILQ_FIRST(&queue->entries) == NULL);
@@ -144,13 +151,7 @@ void qemu_co_rwlock_unlock(CoRwlock *lock)
     assert(qemu_in_coroutine());
     if (lock->writer) {
         lock->writer = false;
-        while (!qemu_co_queue_empty(&lock->queue)) {
-            /*
-             * Wakeup every body. This will include some
-             * writers too.
-             */
-            qemu_co_queue_next(&lock->queue);
-        }
+        qemu_co_queue_restart_all(&lock->queue);
     } else {
         lock->reader--;
         assert(lock->reader >= 0);
index 8a2e5d2a105a7bc2b3c5e06485868e2d8b699cab..8a55fe125ebce06ede28d6f2f8b85c1ac99525c0 100644 (file)
@@ -130,6 +130,11 @@ void coroutine_fn qemu_co_queue_wait_insert_head(CoQueue *queue);
  */
 bool qemu_co_queue_next(CoQueue *queue);
 
+/**
+ * Restarts all coroutines in the CoQueue and leaves the queue empty.
+ */
+void qemu_co_queue_restart_all(CoQueue *queue);
+
 /**
  * Checks if the CoQueue is empty.
  */