From patchwork Wed Jan 23 17:27:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 1030086 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43lC3x6HdXz9s55 for ; Thu, 24 Jan 2019 04:30:37 +1100 (AEDT) Received: from localhost ([127.0.0.1]:39036 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gmMMF-00046j-KP for incoming@patchwork.ozlabs.org; Wed, 23 Jan 2019 12:30:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gmMJh-0002JH-94 for qemu-devel@nongnu.org; Wed, 23 Jan 2019 12:27:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gmMJf-0002SK-Bg for qemu-devel@nongnu.org; Wed, 23 Jan 2019 12:27:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33790) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gmMJd-0002Qj-D4 for qemu-devel@nongnu.org; Wed, 23 Jan 2019 12:27:55 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9C99990C9B; Wed, 23 Jan 2019 17:27:51 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-66.ams2.redhat.com [10.36.112.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0D5A19C7F; Wed, 23 Jan 2019 17:27:48 +0000 (UTC) From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Wed, 23 Jan 2019 17:27:25 +0000 Message-Id: <20190123172740.32452-2-berrange@redhat.com> In-Reply-To: <20190123172740.32452-1-berrange@redhat.com> References: <20190123172740.32452-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 23 Jan 2019 17:27:51 +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 01/16] io: store reference to thread information in the QIOTask struct 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: Laurent Vivier , Thomas Huth , Yongji Xie , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Currently the struct QIOTaskThreadData is only needed by the worker thread, but a subsequent patch will need to access it from another context. Signed-off-by: Daniel P. Berrangé Reviewed-by: Marc-André Lureau --- io/task.c | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/io/task.c b/io/task.c index 2886a2c1bc..d100a754d3 100644 --- a/io/task.c +++ b/io/task.c @@ -24,6 +24,14 @@ #include "qemu/thread.h" #include "trace.h" +struct QIOTaskThreadData { + QIOTaskWorker worker; + gpointer opaque; + GDestroyNotify destroy; + GMainContext *context; +}; + + struct QIOTask { Object *source; QIOTaskFunc func; @@ -32,6 +40,7 @@ struct QIOTask { Error *err; gpointer result; GDestroyNotify destroyResult; + struct QIOTaskThreadData *thread; }; @@ -72,31 +81,23 @@ static void qio_task_free(QIOTask *task) } -struct QIOTaskThreadData { - QIOTask *task; - QIOTaskWorker worker; - gpointer opaque; - GDestroyNotify destroy; - GMainContext *context; -}; - - static gboolean qio_task_thread_result(gpointer opaque) { - struct QIOTaskThreadData *data = opaque; + QIOTask *task = opaque; - trace_qio_task_thread_result(data->task); - qio_task_complete(data->task); + trace_qio_task_thread_result(task); + qio_task_complete(task); - if (data->destroy) { - data->destroy(data->opaque); + if (task->thread->destroy) { + task->thread->destroy(task->thread->opaque); } - if (data->context) { - g_main_context_unref(data->context); + if (task->thread->context) { + g_main_context_unref(task->thread->context); } - g_free(data); + g_free(task->thread); + task->thread = NULL; return FALSE; } @@ -104,22 +105,23 @@ static gboolean qio_task_thread_result(gpointer opaque) static gpointer qio_task_thread_worker(gpointer opaque) { - struct QIOTaskThreadData *data = opaque; + QIOTask *task = opaque; GSource *idle; - trace_qio_task_thread_run(data->task); - data->worker(data->task, data->opaque); + trace_qio_task_thread_run(task); + + task->thread->worker(task, task->thread->opaque); /* We're running in the background thread, and must only * ever report the task results in the main event loop * thread. So we schedule an idle callback to report * the worker results */ - trace_qio_task_thread_exit(data->task); + trace_qio_task_thread_exit(task); idle = g_idle_source_new(); - g_source_set_callback(idle, qio_task_thread_result, data, NULL); - g_source_attach(idle, data->context); + g_source_set_callback(idle, qio_task_thread_result, task, NULL); + g_source_attach(idle, task->thread->context); return NULL; } @@ -138,17 +140,18 @@ void qio_task_run_in_thread(QIOTask *task, g_main_context_ref(context); } - data->task = task; data->worker = worker; data->opaque = opaque; data->destroy = destroy; data->context = context; + task->thread = data; + trace_qio_task_thread_start(task, worker, opaque); qemu_thread_create(&thread, "io-task-worker", qio_task_thread_worker, - data, + task, QEMU_THREAD_DETACHED); }