[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 30/41] coroutine: add qemu_co_queue_restart_all()
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 30/41] coroutine: add qemu_co_queue_restart_all() |
Date: |
Mon, 5 Dec 2011 15:21:07 +0100 |
From: Stefan Hajnoczi <address@hidden>
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 <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
block/qcow2.c | 2 +-
qemu-coroutine-lock.c | 15 ++++++++-------
qemu-coroutine.h | 5 +++++
3 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/block/qcow2.c b/block/qcow2.c
index 5ac9fb4..a2be7d7 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -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);
}
}
diff --git a/qemu-coroutine-lock.c b/qemu-coroutine-lock.c
index 9549c07..26ad76b 100644
--- a/qemu-coroutine-lock.c
+++ b/qemu-coroutine-lock.c
@@ -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);
diff --git a/qemu-coroutine.h b/qemu-coroutine.h
index 8a2e5d2..8a55fe1 100644
--- a/qemu-coroutine.h
+++ b/qemu-coroutine.h
@@ -131,6 +131,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.
*/
bool qemu_co_queue_empty(CoQueue *queue);
--
1.7.6.4
- [Qemu-devel] [PATCH 22/41] qed: convert to .bdrv_co_is_allocated(), (continued)
- [Qemu-devel] [PATCH 22/41] qed: convert to .bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 26/41] cow: convert to .bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 27/41] block: drop .bdrv_is_allocated() interface, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 24/41] vvfat: convert to .bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 20/41] block: use public bdrv_is_allocated() interface, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 23/41] block: convert qcow2, qcow2, and vmdk to .bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 21/41] block: add .bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 25/41] vdi: convert to .bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 29/41] qemu-common: add QEMU_ALIGN_DOWN() and QEMU_ALIGN_UP() macros, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 31/41] block: add request tracking, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 30/41] coroutine: add qemu_co_queue_restart_all(),
Kevin Wolf <=
- [Qemu-devel] [PATCH 28/41] block: add bdrv_co_is_allocated() interface, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 32/41] block: add interface to toggle copy-on-read, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 39/41] block: implement bdrv_co_is_allocated() boundary cases, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 37/41] cow: use bdrv_co_is_allocated(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 35/41] block: core copy-on-read logic, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 36/41] block: add -drive copy-on-read=on|off, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 34/41] block: request overlap detection, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 40/41] block: wait_for_overlapping_requests() deadlock detection, Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 41/41] block: convert qemu_aio_flush() calls to bdrv_drain_all(), Kevin Wolf, 2011/12/05
- [Qemu-devel] [PATCH 33/41] block: wait for overlapping requests, Kevin Wolf, 2011/12/05