From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:59747) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grmCV-0007jc-FE for qemu-devel@nongnu.org; Thu, 07 Feb 2019 11:06:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grmCO-0006IP-VZ for qemu-devel@nongnu.org; Thu, 07 Feb 2019 11:06:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53940) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grmCO-00060Y-KN for qemu-devel@nongnu.org; Thu, 07 Feb 2019 11:06:48 -0500 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 7 Feb 2019 17:06:00 +0100 Message-Id: <20190207160617.1142-2-marcandre.lureau@redhat.com> In-Reply-To: <20190207160617.1142-1-marcandre.lureau@redhat.com> References: <20190207160617.1142-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 01/18] io: store reference to thread information in the QIOTask struct List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , peter.maydell@linaro.org, =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= From: Daniel P. Berrang=C3=A9 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=C3=A9 Message-Id: <20190123172740.32452-2-berrange@redhat.com> [ Marc-Andr=C3=A9 - applied Daniel fixup ] Signed-off-by: Marc-Andr=C3=A9 Lureau --- io/task.c | 64 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/io/task.c b/io/task.c index 2886a2c1bc..396866b10f 100644 --- a/io/task.c +++ b/io/task.c @@ -24,6 +24,14 @@ #include "qemu/thread.h" #include "trace.h" =20 +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; }; =20 =20 @@ -57,6 +66,18 @@ QIOTask *qio_task_new(Object *source, =20 static void qio_task_free(QIOTask *task) { + if (task->thread) { + if (task->thread->destroy) { + task->thread->destroy(task->thread->opaque); + } + + if (task->thread->context) { + g_main_context_unref(task->thread->context); + } + + g_free(task->thread); + } + if (task->destroy) { task->destroy(task->opaque); } @@ -72,31 +93,12 @@ static void qio_task_free(QIOTask *task) } =20 =20 -struct QIOTaskThreadData { - QIOTask *task; - QIOTaskWorker worker; - gpointer opaque; - GDestroyNotify destroy; - GMainContext *context; -}; - - static gboolean qio_task_thread_result(gpointer opaque) { - struct QIOTaskThreadData *data =3D opaque; + QIOTask *task =3D opaque; =20 - trace_qio_task_thread_result(data->task); - qio_task_complete(data->task); - - if (data->destroy) { - data->destroy(data->opaque); - } - - if (data->context) { - g_main_context_unref(data->context); - } - - g_free(data); + trace_qio_task_thread_result(task); + qio_task_complete(task); =20 return FALSE; } @@ -104,22 +106,23 @@ static gboolean qio_task_thread_result(gpointer opa= que) =20 static gpointer qio_task_thread_worker(gpointer opaque) { - struct QIOTaskThreadData *data =3D opaque; + QIOTask *task =3D opaque; GSource *idle; =20 - 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); =20 /* 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); =20 idle =3D 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); =20 return NULL; } @@ -138,17 +141,18 @@ void qio_task_run_in_thread(QIOTask *task, g_main_context_ref(context); } =20 - data->task =3D task; data->worker =3D worker; data->opaque =3D opaque; data->destroy =3D destroy; data->context =3D context; =20 + task->thread =3D 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); } =20 --=20 2.20.1.519.g8feddda32c