From patchwork Thu Aug 25 06:41:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peter A. G. Crosthwaite" X-Patchwork-Id: 111467 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 44C41B6F70 for ; Thu, 25 Aug 2011 16:43:14 +1000 (EST) Received: from localhost ([::1]:37857 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwTeh-0006t3-5c for incoming@patchwork.ozlabs.org; Thu, 25 Aug 2011 02:43:11 -0400 Received: from eggs.gnu.org ([140.186.70.92]:46755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwTeY-0006lQ-MQ for qemu-devel@nongnu.org; Thu, 25 Aug 2011 02:43:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QwTeW-0003uN-OW for qemu-devel@nongnu.org; Thu, 25 Aug 2011 02:43:02 -0400 Received: from mail-gw0-f45.google.com ([74.125.83.45]:48703) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwTeW-0003uJ-Ke for qemu-devel@nongnu.org; Thu, 25 Aug 2011 02:43:00 -0400 Received: by gwb19 with SMTP id 19so1694034gwb.4 for ; Wed, 24 Aug 2011 23:42:59 -0700 (PDT) Received: by 10.150.73.31 with SMTP id v31mr485752yba.55.1314254579722; Wed, 24 Aug 2011 23:42:59 -0700 (PDT) Received: from localhost ([124.148.20.9]) by mx.google.com with ESMTPS id m3sm964371ybg.11.2011.08.24.23.42.56 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 24 Aug 2011 23:42:59 -0700 (PDT) From: "Peter A. G. Crosthwaite" To: qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com, edgar.iglesias@gmail.com, john.williams@petalogix.com, michal.simek@petalogix.com Date: Thu, 25 Aug 2011 16:41:07 +1000 Message-Id: <1314254480-22438-2-git-send-email-peter.crosthwaite@petalogix.com> X-Mailer: git-send-email 1.7.3.2 In-Reply-To: <1314254480-22438-1-git-send-email-peter.crosthwaite@petalogix.com> References: <1314254480-22438-1-git-send-email-peter.crosthwaite@petalogix.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 74.125.83.45 Cc: "Peter A. G. Crosthwaite" Subject: [Qemu-devel] [RFC PATCH V1 01/14] qemu-coroutine: Add simple work queue support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add a function co_queue_enter_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 enter 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..4da670d 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_enter_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..65776e5 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_enter_next(CoQueue *queue); + +/** * Checks if the CoQueue is empty. */ bool qemu_co_queue_empty(CoQueue *queue);