From nobody Wed Nov 5 09:04:39 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499671484720845.6594177558562; Mon, 10 Jul 2017 00:24:44 -0700 (PDT) Received: from localhost ([::1]:38967 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUT3j-00038k-8Y for importer@patchew.org; Mon, 10 Jul 2017 03:24:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33636) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUSzw-0000P9-79 for qemu-devel@nongnu.org; Mon, 10 Jul 2017 03:20:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUSzt-0000rs-1c for qemu-devel@nongnu.org; Mon, 10 Jul 2017 03:20:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUSzs-0000qN-NS for qemu-devel@nongnu.org; Mon, 10 Jul 2017 03:20:44 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A98B44DD49 for ; Mon, 10 Jul 2017 07:20:43 +0000 (UTC) Received: from lemon.redhat.com (ovpn-12-94.pek2.redhat.com [10.72.12.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1A8777DC4; Mon, 10 Jul 2017 07:20:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A98B44DD49 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=famz@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A98B44DD49 From: Fam Zheng To: qemu-devel@nongnu.org Date: Mon, 10 Jul 2017 15:20:25 +0800 Message-Id: <20170710072027.7948-4-famz@redhat.com> In-Reply-To: <20170710072027.7948-1-famz@redhat.com> References: <20170710072027.7948-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 10 Jul 2017 07:20:43 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC 3/5] iothread: Extract iothread_start 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: pbonzini@redhat.com, Fam Zheng , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is the "create and start the thread" part of iothread spawning. Signed-off-by: Fam Zheng Reviewed-by: Stefan Hajnoczi --- include/sysemu/iothread.h | 1 + iothread.c | 33 +++++++++++++++++++-------------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/include/sysemu/iothread.h b/include/sysemu/iothread.h index 37f033b..a3a03e8 100644 --- a/include/sysemu/iothread.h +++ b/include/sysemu/iothread.h @@ -36,6 +36,7 @@ typedef struct { OBJECT_CHECK(IOThread, obj, TYPE_IOTHREAD) =20 char *iothread_get_id(IOThread *iothread); +void iothread_start(IOThread *iothread, const char *thread_name, Error **e= rrp); AioContext *iothread_get_aio_context(IOThread *iothread); void iothread_stop_all(void); =20 diff --git a/iothread.c b/iothread.c index ce56724..8d703db 100644 --- a/iothread.c +++ b/iothread.c @@ -76,6 +76,10 @@ static void iothread_instance_init(Object *obj) IOThread *iothread =3D IOTHREAD(obj); =20 iothread->poll_params.max_ns =3D IOTHREAD_POLL_MAX_NS_DEFAULT; + iothread->stopping =3D false; + iothread->thread_id =3D -1; + qemu_mutex_init(&iothread->init_done_lock); + qemu_cond_init(&iothread->init_done_cond); } =20 static void iothread_instance_finalize(Object *obj) @@ -91,14 +95,26 @@ static void iothread_instance_finalize(Object *obj) aio_context_unref(iothread->ctx); } =20 +void iothread_start(IOThread *iothread, const char *thread_name, Error **e= rrp) +{ + qemu_thread_create(&iothread->thread, thread_name, iothread_run, + iothread, QEMU_THREAD_JOINABLE); + + /* Wait for initialization to complete */ + qemu_mutex_lock(&iothread->init_done_lock); + while (iothread->thread_id =3D=3D -1) { + qemu_cond_wait(&iothread->init_done_cond, + &iothread->init_done_lock); + } + qemu_mutex_unlock(&iothread->init_done_lock); +} + static void iothread_complete(UserCreatable *obj, Error **errp) { Error *local_error =3D NULL; IOThread *iothread =3D IOTHREAD(obj); char *name, *thread_name; =20 - iothread->stopping =3D false; - iothread->thread_id =3D -1; iothread->ctx =3D aio_context_new(&local_error); if (!iothread->ctx) { error_propagate(errp, local_error); @@ -114,26 +130,15 @@ static void iothread_complete(UserCreatable *obj, Err= or **errp) return; } =20 - qemu_mutex_init(&iothread->init_done_lock); - qemu_cond_init(&iothread->init_done_cond); =20 /* This assumes we are called from a thread with useful CPU affinity f= or us * to inherit. */ name =3D object_get_canonical_path_component(OBJECT(obj)); thread_name =3D g_strdup_printf("IO %s", name); - qemu_thread_create(&iothread->thread, thread_name, iothread_run, - iothread, QEMU_THREAD_JOINABLE); + iothread_start(iothread, thread_name, errp); g_free(thread_name); g_free(name); - - /* Wait for initialization to complete */ - qemu_mutex_lock(&iothread->init_done_lock); - while (iothread->thread_id =3D=3D -1) { - qemu_cond_wait(&iothread->init_done_cond, - &iothread->init_done_lock); - } - qemu_mutex_unlock(&iothread->init_done_lock); } =20 typedef struct { --=20 2.9.4