From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:49232) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RR2Cu-0002as-7y for qemu-devel@nongnu.org; Thu, 17 Nov 2011 08:41:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RR2Co-0000x7-JV for qemu-devel@nongnu.org; Thu, 17 Nov 2011 08:40:47 -0500 Received: from mtagate7.uk.ibm.com ([194.196.100.167]:49690) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RR2Co-0000wg-CF for qemu-devel@nongnu.org; Thu, 17 Nov 2011 08:40:42 -0500 Received: from d06nrmr1307.portsmouth.uk.ibm.com (d06nrmr1307.portsmouth.uk.ibm.com [9.149.38.129]) by mtagate7.uk.ibm.com (8.13.1/8.13.1) with ESMTP id pAHDefjx006134 for ; Thu, 17 Nov 2011 13:40:41 GMT Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pAHDee6S1560796 for ; Thu, 17 Nov 2011 13:40:40 GMT Received: from d06av10.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pAHDebQN028121 for ; Thu, 17 Nov 2011 06:40:37 -0700 From: Stefan Hajnoczi Date: Thu, 17 Nov 2011 13:40:26 +0000 Message-Id: <1321537232-799-3-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1321537232-799-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1321537232-799-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v2 2/8] coroutine: add qemu_co_queue_restart_all() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Marcelo Tosatti , Stefan Hajnoczi 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 --- 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 eab35d1..195e1b1 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -514,7 +514,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.7.1