From nobody Sun Nov 9 14:50:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1550843539273276.6193113753544; Fri, 22 Feb 2019 05:52:19 -0800 (PST) Received: from localhost ([127.0.0.1]:51006 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxBFQ-0001kE-89 for importer@patchew.org; Fri, 22 Feb 2019 08:52:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:55244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gxBBX-0007Kc-4e for qemu-devel@nongnu.org; Fri, 22 Feb 2019 08:48:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gxBBV-0001jV-Fa for qemu-devel@nongnu.org; Fri, 22 Feb 2019 08:48:14 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:56216) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gxBBU-0000iU-Qy for qemu-devel@nongnu.org; Fri, 22 Feb 2019 08:48:13 -0500 Received: from 62-165-147-230.co.dnainternet.fi ([62.165.147.230] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1gxBAX-0007yq-5h; Fri, 22 Feb 2019 14:47:13 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1gxBAJ-0006PR-Bp; Fri, 22 Feb 2019 15:46:59 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=f3BhRVPQ3hGls1rc/lcSFfieFOOaV3dzTmMRC/Io8+0=; b=JqetLdTvbSLip6u+h8kHgFTfYv9bg00V3n6V8KdG9ma9aEQpW8vtvZkkLh0jYIPK169FYixsKn1ma2ocK+8rRFo7G+mqG40raHMZpMSRMcU8v5r48RTVoGSLJATpFMg8kPBKD6CQ80JmuH8Jo2XOPBk8y441DXWjYFpyJG41lIG5eo2/k7ejWRj+NhC+FV0cCsMLTAiR/42B3vndR6x3ayIxBCFftA9eyFogQm9INL3DtqPmX2f7dvF+yv7Z6jI1bSxoa0VihFfI14SthB4GKBTmtRboL0vnIKmQUOqkiWnd8vd0jij0+ompLQ57GvzX8VIqZXCmoprgjfc2BSP9gQ==; From: Alberto Garcia To: qemu-devel@nongnu.org Date: Fri, 22 Feb 2019 15:46:25 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v3 2/3] main-loop: Add qemu_idle_add() 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: Paolo Bonzini , Alberto Garcia , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This works like g_idle_add() but allows specifying a different GMainContext. It also returns the GSource directly instead of its ID number for convenience. qio_task_thread_worker() is modified to make use of this new function. Signed-off-by: Alberto Garcia Reviewed-by: Daniel P. Berrang=C3=A9 --- include/qemu/main-loop.h | 12 ++++++++++++ io/task.c | 10 +++------- util/main-loop.c | 9 +++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h index f6ba78ea73..f966c015d0 100644 --- a/include/qemu/main-loop.h +++ b/include/qemu/main-loop.h @@ -295,6 +295,18 @@ void qemu_mutex_lock_iothread_impl(const char *file, i= nt line); */ void qemu_mutex_unlock_iothread(void); =20 +/** + * qemu_idle_add: Add an idle function to a GMainContext + * + * This function is similar to GLib's g_idle_add() but it allows + * specifying a GMainContext instead of using the global one. + * + * The returned GSource is owned by the GMainContext and is deleted + * automatically after @func returns false. It can also be deleted by + * removing it from the GMainContext using g_source_destroy(). + */ +GSource *qemu_idle_add(GSourceFunc func, gpointer data, GMainContext *ctx); + /* internal interfaces */ =20 void qemu_fd_register(int fd); diff --git a/io/task.c b/io/task.c index 1ae7b86488..16754e22ba 100644 --- a/io/task.c +++ b/io/task.c @@ -19,6 +19,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "io/task.h" #include "qapi/error.h" #include "qemu/thread.h" @@ -130,13 +131,8 @@ static gpointer qio_task_thread_worker(gpointer opaque) trace_qio_task_thread_exit(task); =20 qemu_mutex_lock(&task->thread_lock); - - task->thread->completion =3D g_idle_source_new(); - g_source_set_callback(task->thread->completion, - qio_task_thread_result, task, NULL); - g_source_attach(task->thread->completion, - task->thread->context); - g_source_unref(task->thread->completion); + task->thread->completion =3D qemu_idle_add(qio_task_thread_result, tas= k, + task->thread->context); trace_qio_task_thread_source_attach(task, task->thread->completion); =20 qemu_cond_signal(&task->thread_cond); diff --git a/util/main-loop.c b/util/main-loop.c index d4a521caeb..e23eda68cc 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -171,6 +171,15 @@ int qemu_init_main_loop(Error **errp) return 0; } =20 +GSource *qemu_idle_add(GSourceFunc func, gpointer data, GMainContext *ctx) +{ + GSource *idle =3D g_idle_source_new(); + g_source_set_callback(idle, func, data, NULL); + g_source_attach(idle, ctx); + g_source_unref(idle); + return idle; +} + static int max_priority; =20 #ifndef _WIN32 --=20 2.11.0