From patchwork Fri Apr 15 11:32:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8850441 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B32E0C0553 for ; Fri, 15 Apr 2016 11:37:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F299A20256 for ; Fri, 15 Apr 2016 11:37:13 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4431720295 for ; Fri, 15 Apr 2016 11:37:13 +0000 (UTC) Received: from localhost ([::1]:60522 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar23k-00060A-Jq for patchwork-qemu-devel@patchwork.kernel.org; Fri, 15 Apr 2016 07:37:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar1zC-00064s-CR for qemu-devel@nongnu.org; Fri, 15 Apr 2016 07:32:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ar1z7-0008VB-SA for qemu-devel@nongnu.org; Fri, 15 Apr 2016 07:32:30 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:36065) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ar1z7-0008UQ-Jx for qemu-devel@nongnu.org; Fri, 15 Apr 2016 07:32:25 -0400 Received: by mail-wm0-x243.google.com with SMTP id l6so5402815wml.3 for ; Fri, 15 Apr 2016 04:32:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=/N2eVns+oLlxAUdCa8r/LyQEGrmHADAH7j60PMg8hD0=; b=bV9MQqFjUdkcUaYFU9WScjEPFdyNPQwNJ5esEQBpItMjoARsZv3EXE1JPdn5tQeRyA Oj8z4SPiIS7MeVd5FCSocigXO8VR4o765Yp221eOpoKd4U93KLngJ3ORgkKmpmI+iehQ 0cxl6TEilU4n39hvVJVC4DGsqYKgRcOa0futw0jklV9YcS8PCy3ouAiVc+HZl3rrqazv OxQm/93Aw22q8reJcQ7Hl1sgPIuxEsnihueCoWBxJPZv104TgYrbOGaO4g1skcfBPBLg dPrqUHYwhK5mwRwz1I/t6ZHJ3hv1XS8tcsfwoO7PBmV9xr5M4fRtZerwcqTP0eeydy6e /65g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=/N2eVns+oLlxAUdCa8r/LyQEGrmHADAH7j60PMg8hD0=; b=j6U9wseAuZfeCPemnJ0zI9KDwnNluDDD3gyofsfOYVACuIuWvEyOliH0YI7ndyjk8r HkSAs3C50buvmPU9MfZdWtQXoC70mPOwS+saazzXNlkSBXFOWxZdbeu3/8nxVFyeByKe D9IgB/pB6LQHEd8chl8MhQ9rqphXofEPXgouTYAbKwJMjVu498cV1Cc9lFkIZMk6V48g r10NGUFwvWoAj/L259mIOdHtaCHaU/qHxkhaC9qaJgowBVg5V5o6OoHO30qN3fKF+6l1 yN9Rxvz1E3xxlIZniZi8KacJqRuvzZPir3k3KYZvlunOx11iFQ97sTcmuTN5r7PiT23t 15uw== X-Gm-Message-State: AOPr4FWzq5yTUhPhwDeKUpQdCp7ZgGH8/r/F8sG6H2aIOP7EqRVCz/ZSEx0HjIcReYcifA== X-Received: by 10.28.73.66 with SMTP id w63mr4058322wma.53.1460719945059; Fri, 15 Apr 2016 04:32:25 -0700 (PDT) Received: from donizetti.redhat.com (94-39-141-76.adsl-ull.clienti.tiscali.it. [94.39.141.76]) by smtp.gmail.com with ESMTPSA id qt3sm15217493wjc.32.2016.04.15.04.32.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Apr 2016 04:32:24 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 15 Apr 2016 13:32:04 +0200 Message-Id: <1460719926-12950-10-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1460719926-12950-1-git-send-email-pbonzini@redhat.com> References: <1460719926-12950-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::243 Subject: [Qemu-devel] [PATCH 09/11] coroutine-lock: place CoMutex before CoQueue in header X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, berto@igalia.com, famz@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This will avoid forward references in the next patch. It is also more logical because CoQueue is not anymore the basic primitive. Signed-off-by: Paolo Bonzini --- include/qemu/coroutine.h | 79 ++++++++++++++++++++++++------------------------ 1 file changed, 39 insertions(+), 40 deletions(-) diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index d15a09a..e8e3431 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -113,46 +113,6 @@ Coroutine *coroutine_fn qemu_coroutine_self(void); bool qemu_in_coroutine(void); - -/** - * CoQueues are a mechanism to queue coroutines in order to continue executing - * them later. They provide the fundamental primitives on which coroutine locks - * are built. - */ -typedef struct CoQueue { - QSIMPLEQ_HEAD(, Coroutine) entries; -} CoQueue; - -/** - * Initialise a CoQueue. This must be called before any other operation is used - * on the CoQueue. - */ -void qemu_co_queue_init(CoQueue *queue); - -/** - * Adds the current coroutine to the CoQueue and transfers control to the - * caller of the coroutine. - */ -void coroutine_fn qemu_co_queue_wait(CoQueue *queue); - -/** - * Restarts the next coroutine in the CoQueue and removes it from the queue. - * - * Returns true if a coroutine was restarted, false if the queue is empty. - */ -bool coroutine_fn qemu_co_queue_next(CoQueue *queue); - -/** - * Restarts all coroutines in the CoQueue and leaves the queue empty. - */ -void coroutine_fn qemu_co_queue_restart_all(CoQueue *queue); - -/** - * Checks if the CoQueue is empty. - */ -bool qemu_co_queue_empty(CoQueue *queue); - - /** * Provides a mutex that can be used to synchronise coroutines */ @@ -196,6 +156,45 @@ void coroutine_fn qemu_co_mutex_lock(CoMutex *mutex); */ void coroutine_fn qemu_co_mutex_unlock(CoMutex *mutex); + +/** + * CoQueues are a mechanism to queue coroutines in order to continue executing + * them later. + */ +typedef struct CoQueue { + QSIMPLEQ_HEAD(, Coroutine) entries; +} CoQueue; + +/** + * Initialise a CoQueue. This must be called before any other operation is used + * on the CoQueue. + */ +void qemu_co_queue_init(CoQueue *queue); + +/** + * Adds the current coroutine to the CoQueue and transfers control to the + * caller of the coroutine. + */ +void coroutine_fn qemu_co_queue_wait(CoQueue *queue); + +/** + * Restarts the next coroutine in the CoQueue and removes it from the queue. + * + * Returns true if a coroutine was restarted, false if the queue is empty. + */ +bool coroutine_fn qemu_co_queue_next(CoQueue *queue); + +/** + * Restarts all coroutines in the CoQueue and leaves the queue empty. + */ +void coroutine_fn qemu_co_queue_restart_all(CoQueue *queue); + +/** + * Checks if the CoQueue is empty. + */ +bool qemu_co_queue_empty(CoQueue *queue); + + typedef struct CoRwlock { bool writer; int reader;