From patchwork Tue Nov 22 12:23:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 697671 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tNPpd3xHXz9srZ for ; Tue, 22 Nov 2016 23:26:33 +1100 (AEDT) Received: from localhost ([::1]:55028 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c9A9e-0001Ob-D3 for incoming@patchwork.ozlabs.org; Tue, 22 Nov 2016 07:26:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c9A7R-0007h2-QD for qemu-devel@nongnu.org; Tue, 22 Nov 2016 07:24:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c9A7Q-0001Yc-Pu for qemu-devel@nongnu.org; Tue, 22 Nov 2016 07:24:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51096) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c9A7N-0001Vp-VB; Tue, 22 Nov 2016 07:24:10 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 02BB6F44DC; Tue, 22 Nov 2016 12:24:09 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-88.ams2.redhat.com [10.36.116.88]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uAMCO5hU009746; Tue, 22 Nov 2016 07:24:07 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 22 Nov 2016 13:23:56 +0100 Message-Id: <1479817444-6880-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1479817444-6880-1-git-send-email-kwolf@redhat.com> References: <1479817444-6880-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 22 Nov 2016 12:24:09 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/9] coroutine: Introduce qemu_coroutine_enter_if_inactive() 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, qemu-devel@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" In the context of asynchronous work, if we have a worker coroutine that didn't yield, the parent coroutine cannot be reentered because it hasn't yielded yet. In this case we don't even have to reenter the parent because it will see that the work is already done and won't even yield. Signed-off-by: Kevin Wolf Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia --- include/qemu/coroutine.h | 6 ++++++ util/qemu-coroutine.c | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index e6a60d5..12584ed 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -71,6 +71,12 @@ Coroutine *qemu_coroutine_create(CoroutineEntry *entry, void *opaque); void qemu_coroutine_enter(Coroutine *coroutine); /** + * Transfer control to a coroutine if it's not active (i.e. part of the call + * stack of the running coroutine). Otherwise, do nothing. + */ +void qemu_coroutine_enter_if_inactive(Coroutine *co); + +/** * Transfer control back to a coroutine's caller * * This function does not return until the coroutine is re-entered using diff --git a/util/qemu-coroutine.c b/util/qemu-coroutine.c index 737bffa..a5d2f6c 100644 --- a/util/qemu-coroutine.c +++ b/util/qemu-coroutine.c @@ -131,6 +131,13 @@ void qemu_coroutine_enter(Coroutine *co) } } +void qemu_coroutine_enter_if_inactive(Coroutine *co) +{ + if (!qemu_coroutine_entered(co)) { + qemu_coroutine_enter(co); + } +} + void coroutine_fn qemu_coroutine_yield(void) { Coroutine *self = qemu_coroutine_self();