From patchwork Sat Jan 22 09:29:23 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 79983 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 32C28B7105 for ; Sat, 22 Jan 2011 20:38:47 +1100 (EST) Received: from localhost ([127.0.0.1]:47341 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PgZvg-0005k0-Ex for incoming@patchwork.ozlabs.org; Sat, 22 Jan 2011 04:38:44 -0500 Received: from [140.186.70.92] (port=56928 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PgZnC-00036C-In for qemu-devel@nongnu.org; Sat, 22 Jan 2011 04:30:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PgZn9-0001mW-Ur for qemu-devel@nongnu.org; Sat, 22 Jan 2011 04:29:58 -0500 Received: from mtagate2.uk.ibm.com ([194.196.100.162]:47126) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PgZn9-0001m1-NT for qemu-devel@nongnu.org; Sat, 22 Jan 2011 04:29:55 -0500 Received: from d06nrmr1707.portsmouth.uk.ibm.com (d06nrmr1707.portsmouth.uk.ibm.com [9.149.39.225]) by mtagate2.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p0M9TtVI009472 for ; Sat, 22 Jan 2011 09:29:55 GMT Received: from d06av07.portsmouth.uk.ibm.com (d06av07.portsmouth.uk.ibm.com [9.149.37.248]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p0M9TvRp1503340 for ; Sat, 22 Jan 2011 09:29:57 GMT Received: from d06av07.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p0M9TsJK028208 for ; Sat, 22 Jan 2011 02:29:54 -0700 Received: from stefanha-thinkpad.ibm.com (gbv82324-009146172195.uk.ibm.com [9.146.172.195]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p0M9TlNc028082; Sat, 22 Jan 2011 02:29:54 -0700 From: Stefan Hajnoczi To: Date: Sat, 22 Jan 2011 09:29:23 +0000 Message-Id: <1295688567-25496-9-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1295688567-25496-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1295688567-25496-1-git-send-email-stefanha@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Kevin Wolf , Anthony Liguori , Stefan Hajnoczi Subject: [Qemu-devel] [RFC][PATCH 08/12] coroutine: Add qemu_in_coroutine() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The qemu_in_coroutine() function checks whether or not we are currently in a user coroutine. This can be used to distinguish between executing normal vcpu or iothread code from executing a coroutine. Signed-off-by: Stefan Hajnoczi --- qemu-coroutine.c | 5 +++++ qemu-coroutine.h | 7 +++++++ 2 files changed, 12 insertions(+), 0 deletions(-) diff --git a/qemu-coroutine.c b/qemu-coroutine.c index e55b7c6..9318600 100644 --- a/qemu-coroutine.c +++ b/qemu-coroutine.c @@ -43,3 +43,8 @@ Coroutine * coroutine_fn qemu_coroutine_self(void) { return (Coroutine*)coroutine_self(); } + +bool qemu_in_coroutine(void) +{ + return !coroutine_is_leader(coroutine_self()); +} diff --git a/qemu-coroutine.h b/qemu-coroutine.h index 41f90bb..1fad3bf 100644 --- a/qemu-coroutine.h +++ b/qemu-coroutine.h @@ -14,6 +14,8 @@ #ifndef QEMU_COROUTINE_H #define QEMU_COROUTINE_H +#include + /** * Mark a function that executes in coroutine context * @@ -78,4 +80,9 @@ void * coroutine_fn qemu_coroutine_yield(void *opaque); */ Coroutine * coroutine_fn qemu_coroutine_self(void); +/** + * Return whether or not currently inside a coroutine + */ +bool qemu_in_coroutine(void); + #endif /* QEMU_COROUTINE_H */