From patchwork Tue Sep 27 15:18:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 9352087 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F03A560757 for ; Tue, 27 Sep 2016 15:19:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E32C029272 for ; Tue, 27 Sep 2016 15:19:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7E7629278; Tue, 27 Sep 2016 15:19:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 913BD29272 for ; Tue, 27 Sep 2016 15:19:18 +0000 (UTC) Received: from localhost ([::1]:51709 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bouA9-0002xS-O3 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 27 Sep 2016 11:19:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34438) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bou9c-0002tS-94 for qemu-devel@nongnu.org; Tue, 27 Sep 2016 11:18:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bou9b-0000nr-DI for qemu-devel@nongnu.org; Tue, 27 Sep 2016 11:18:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54624) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bou9Y-0000mJ-WB; Tue, 27 Sep 2016 11:18:41 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (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 88CF67F7AB; Tue, 27 Sep 2016 15:18:40 +0000 (UTC) Received: from localhost (ovpn-112-62.ams2.redhat.com [10.36.112.62]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8RFIdfK026220; Tue, 27 Sep 2016 11:18:40 -0400 From: Stefan Hajnoczi To: qemu-devel@nongnu.org Date: Tue, 27 Sep 2016 16:18:34 +0100 Message-Id: <1474989516-18255-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1474989516-18255-1-git-send-email-stefanha@redhat.com> References: <1474989516-18255-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 27 Sep 2016 15:18:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/3] coroutine: add qemu_coroutine_entered() function 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: Kevin Wolf , Stefan Hajnoczi , Fam Zheng , Roman Pen , qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP See the doc comments for a description of this new coroutine API. Signed-off-by: Stefan Hajnoczi Reviewed-by: Fam Zheng --- include/qemu/coroutine.h | 13 +++++++++++++ util/qemu-coroutine.c | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index 29a2078..e6a60d5 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -92,6 +92,19 @@ Coroutine *coroutine_fn qemu_coroutine_self(void); */ bool qemu_in_coroutine(void); +/** + * Return true if the coroutine is currently entered + * + * A coroutine is "entered" if it has not yielded from the current + * qemu_coroutine_enter() call used to run it. This does not mean that the + * coroutine is currently executing code since it may have transferred control + * to another coroutine using qemu_coroutine_enter(). + * + * When several coroutines enter each other there may be no way to know which + * ones have already been entered. In such situations this function can be + * used to avoid recursively entering coroutines. + */ +bool qemu_coroutine_entered(Coroutine *co); /** diff --git a/util/qemu-coroutine.c b/util/qemu-coroutine.c index 3cbf225..737bffa 100644 --- a/util/qemu-coroutine.c +++ b/util/qemu-coroutine.c @@ -146,3 +146,8 @@ void coroutine_fn qemu_coroutine_yield(void) self->caller = NULL; qemu_coroutine_switch(self, to, COROUTINE_YIELD); } + +bool qemu_coroutine_entered(Coroutine *co) +{ + return co->caller; +}