From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:58753) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qw8Mr-0006jM-6l for qemu-devel@nongnu.org; Wed, 24 Aug 2011 03:59:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qw8Mq-0007dY-7i for qemu-devel@nongnu.org; Wed, 24 Aug 2011 03:59:21 -0400 Received: from mail-yw0-f45.google.com ([209.85.213.45]:62565) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qw8Mq-0007dT-43 for qemu-devel@nongnu.org; Wed, 24 Aug 2011 03:59:20 -0400 Received: by ywf9 with SMTP id 9so769204ywf.4 for ; Wed, 24 Aug 2011 00:59:19 -0700 (PDT) From: "Peter A. G. Crosthwaite" Date: Wed, 24 Aug 2011 17:57:51 +1000 Message-Id: <1314172671-13123-1-git-send-email-peter.crosthwaite@petalogix.com> Subject: [Qemu-devel] [PATCH] qemu-coroutine: Add simple work queue support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com, kwolf@redhat.com Cc: "Peter A. G. Crosthwaite" Add a function co_queue_yield_to_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 restart queued routines one at a time. Signed-off-by: Peter A. G. Crosthwaite --- qemu-coroutine-lock.c | 13 +++++++++++++ qemu-coroutine.h | 9 +++++++++ 2 files changed, 22 insertions(+), 0 deletions(-) diff --git a/qemu-coroutine-lock.c b/qemu-coroutine-lock.c index a80f437..de2fc21 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_yield_to_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..dbc3610 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_yield_to_next(CoQueue *queue) + +/** * Checks if the CoQueue is empty. */ bool qemu_co_queue_empty(CoQueue *queue); -- 1.7.3.2