From patchwork Mon Sep 17 09:02:57 2012 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: 184346 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C024C2C0086 for ; Mon, 17 Sep 2012 19:18:12 +1000 (EST) Received: from localhost ([::1]:33515 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TDXG0-00043X-JZ for incoming@patchwork.ozlabs.org; Mon, 17 Sep 2012 05:04:44 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35677) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TDXFQ-0003Dl-Nf for qemu-devel@nongnu.org; Mon, 17 Sep 2012 05:04:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TDXFJ-0001bP-KB for qemu-devel@nongnu.org; Mon, 17 Sep 2012 05:04:08 -0400 Received: from mail-iy0-f173.google.com ([209.85.210.173]:53565) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TDXFJ-0001a3-FX for qemu-devel@nongnu.org; Mon, 17 Sep 2012 05:04:01 -0400 Received: by mail-iy0-f173.google.com with SMTP id x26so4933478iak.4 for ; Mon, 17 Sep 2012 02:04:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :in-reply-to:references:x-gm-message-state; bh=OI2JUx3SKiE57n0pTmdnI144pOTKP6TCtfPP/N0LR9Y=; b=NXspDmQt7uGVhlF9LkbeykCELZfTS3UN2LbGQXA7DHVCZngYf82kgqZymAASfqjjjg zWUzB+4jVm7HP5ul5/4IdBi1sHUK+iAXy8tEtb2ef1Wt15tjRipcgWEq61P/rvKnQSri p8w0Tf3WXvy5kBgZ9d0peMOpzOxIRPGhYot2wXAp5ofYp20ntlSrbrv8vFUkD7IQnQNp SJM18smTX7B5PUCPTKYPUgzMgBTRtiPex/DAUGw3RZteqx+PlpCquxzpIogtSRZqSTac uqGIa2XTVjCRS88BSVslGDbr1DcCb+T79cb8L3UFuBN3SlQxesKmWE5wRFlBKFd0hduy nf0A== Received: by 10.42.18.8 with SMTP id v8mr8142641ica.16.1347872641205; Mon, 17 Sep 2012 02:04:01 -0700 (PDT) Received: from localhost ([124.148.20.9]) by mx.google.com with ESMTPS id p5sm6900298igm.13.2012.09.17.02.03.58 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 17 Sep 2012 02:04:00 -0700 (PDT) From: "Peter A. G. Crosthwaite" To: qemu-devel@nongnu.org, edgar.iglesias@gmail.com Date: Mon, 17 Sep 2012 19:02:57 +1000 Message-Id: <08c14e2ef3bc304000fc58619f1b60d4d813c00d.1347871922.git.peter.crosthwaite@petalogix.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: References: In-Reply-To: References: X-Gm-Message-State: ALoCoQmxNTC3zwltJ6ZMinfY+3f/BjGxg87Aw3BfQQLf78aDDr+KT0BgmJne+Lna3HAk1Qcz6Uij X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.210.173 Cc: peter.crosthwaite@petalogix.com, crwulff@gmail.com Subject: [Qemu-devel] [RFC v0 05/10] 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 26ad76b..6e343b1 100644 --- a/qemu-coroutine-lock.c +++ b/qemu-coroutine-lock.c @@ -91,6 +91,19 @@ void qemu_co_queue_restart_all(CoQueue *queue) } } +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 34c15d4..d63b103 100644 --- a/qemu-coroutine.h +++ b/qemu-coroutine.h @@ -137,6 +137,15 @@ bool qemu_co_queue_next(CoQueue *queue); void qemu_co_queue_restart_all(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);