From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57121) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSoT5-0005sJ-89 for qemu-devel@nongnu.org; Mon, 08 Feb 2016 11:15:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aSoT1-0002Mw-91 for qemu-devel@nongnu.org; Mon, 08 Feb 2016 11:15:15 -0500 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:34715) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSoT1-0002Mp-27 for qemu-devel@nongnu.org; Mon, 08 Feb 2016 11:15:11 -0500 Received: by mail-wm0-x241.google.com with SMTP id p63so16173764wmp.1 for ; Mon, 08 Feb 2016 08:15:11 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 8 Feb 2016 17:14:52 +0100 Message-Id: <1454948107-11844-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1454948107-11844-1-git-send-email-pbonzini@redhat.com> References: <1454948107-11844-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 01/16] aio: introduce aio_context_in_iothread List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: stefanha@redhat.com This will be used by the synchronous I/O helpers, to choose between aio_poll or QemuEvent. Signed-off-by: Paolo Bonzini --- include/block/aio.h | 7 +++++++ iothread.c | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/include/block/aio.h b/include/block/aio.h index e086e3b..9434665 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -435,6 +435,13 @@ static inline bool aio_node_check(AioContext *ctx, bool is_external) } /** + * @ctx: the aio context + * + * Return whether we are running in the I/O thread that manages @ctx. + */ +bool aio_context_in_iothread(AioContext *ctx); + +/** * aio_context_setup: * @ctx: the aio context * diff --git a/iothread.c b/iothread.c index f183d38..8d40bb0 100644 --- a/iothread.c +++ b/iothread.c @@ -20,6 +20,7 @@ #include "qmp-commands.h" #include "qemu/error-report.h" #include "qemu/rcu.h" +#include "qemu/main-loop.h" typedef ObjectClass IOThreadClass; @@ -28,6 +29,13 @@ typedef ObjectClass IOThreadClass; #define IOTHREAD_CLASS(klass) \ OBJECT_CLASS_CHECK(IOThreadClass, klass, TYPE_IOTHREAD) +static __thread IOThread *my_iothread; + +bool aio_context_in_iothread(AioContext *ctx) +{ + return ctx == (my_iothread ? my_iothread->ctx : qemu_get_aio_context()); +} + static void *iothread_run(void *opaque) { IOThread *iothread = opaque; @@ -35,6 +43,7 @@ static void *iothread_run(void *opaque) rcu_register_thread(); + my_iothread = iothread; qemu_mutex_lock(&iothread->init_done_lock); iothread->thread_id = qemu_get_thread_id(); qemu_cond_signal(&iothread->init_done_cond); -- 2.5.0