From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:48185) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RTBZh-0005iT-UM for qemu-devel@nongnu.org; Wed, 23 Nov 2011 07:05:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RTBKA-0002Hb-D2 for qemu-devel@nongnu.org; Wed, 23 Nov 2011 06:49:16 -0500 Received: from mtagate7.uk.ibm.com ([194.196.100.167]:36839) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RTBK9-00023d-TO for qemu-devel@nongnu.org; Wed, 23 Nov 2011 06:49:10 -0500 Received: from d06nrmr1507.portsmouth.uk.ibm.com (d06nrmr1507.portsmouth.uk.ibm.com [9.149.38.233]) by mtagate7.uk.ibm.com (8.13.1/8.13.1) with ESMTP id pANBm4MV009469 for ; Wed, 23 Nov 2011 11:48:04 GMT Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by d06nrmr1507.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pANBm3gu2502798 for ; Wed, 23 Nov 2011 11:48:03 GMT Received: from d06av03.portsmouth.uk.ibm.com (localhost.localdomain [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pANBm332030843 for ; Wed, 23 Nov 2011 04:48:03 -0700 From: Stefan Hajnoczi Date: Wed, 23 Nov 2011 11:47:52 +0000 Message-Id: <1322048878-26348-3-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1322048878-26348-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1322048878-26348-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v4 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