From patchwork Thu Feb 7 13:23:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 10801225 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0CAF513BF for ; Thu, 7 Feb 2019 13:27:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F16332040D for ; Thu, 7 Feb 2019 13:27:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E63CA283AD; Thu, 7 Feb 2019 13:27:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 82E0D2040D for ; Thu, 7 Feb 2019 13:27:36 +0000 (UTC) Received: from localhost ([127.0.0.1]:40038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grjiJ-0003E7-S5 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Feb 2019 08:27:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49446) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grjf6-0001Oo-R5 for qemu-devel@nongnu.org; Thu, 07 Feb 2019 08:24:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grjex-0004Dw-GE for qemu-devel@nongnu.org; Thu, 07 Feb 2019 08:24:16 -0500 Received: from fanzine.igalia.com ([91.117.99.155]:59534) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1grjex-000403-7c for qemu-devel@nongnu.org; Thu, 07 Feb 2019 08:24:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=LPC4W1xvbkiZRcMeKOH76wLQbwsRSf7ZlKa7CN0WuKs=; b=sQx988t48GE2iZB3ooBPf5euhWVd3dOC6DTB1WNtIhIiEFpnkUzCgpiTQMPG2IAKtaiOvwUr0TGMYTAILuNDV9LOjF3Eg8AmqgDrqE5aRL5Li8MkDIHcXBLpyhFluEo4KQLwg4UInSmsHiU8BmGr64lsDF3X0J602M5bm+kBfDJlbaKPwwbJjO6RpIoWeuTiGVRSmsI3cFuYDemAjWh775XHgrB3U8mpneOYTGi5V+fjOs9CZoWCF/WY9G8tvhTzRhKg/keOXrHKtx8Qb6PoSUZETsGOHpSXrVmQNmhxZJ5BZmO0bofXLeKS10YhlJfnzzBxyhCxaI7XQNbdCLifFQ==; 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 1grjeX-0003gn-Mv; Thu, 07 Feb 2019 14:23:41 +0100 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1grjeK-0003A6-PQ; Thu, 07 Feb 2019 15:23:28 +0200 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 7 Feb 2019 15:23:22 +0200 Message-Id: <2c1d9d03c5b3ee26b116db3438caa3df73dffa46.1549545591.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: 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 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_Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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. pty_chr_state() and qio_task_thread_worker() are modified to make use of this new function. Signed-off-by: Alberto Garcia Reviewed-by: Daniel P. Berrangé Reviewed-by: Marc-André Lureau --- chardev/char-pty.c | 8 ++------ include/qemu/main-loop.h | 8 ++++++++ io/task.c | 7 ++----- util/main-loop.c | 9 +++++++++ 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/chardev/char-pty.c b/chardev/char-pty.c index f16a5e8d59..6562c38f39 100644 --- a/chardev/char-pty.c +++ b/chardev/char-pty.c @@ -209,13 +209,9 @@ static void pty_chr_state(Chardev *chr, int connected) pty_chr_timer_cancel(s); if (!s->connected) { g_assert(s->open_source == NULL); - s->open_source = g_idle_source_new(); + s->open_source = qemu_idle_add(qemu_chr_be_generic_open_func, + chr, chr->gcontext); s->connected = 1; - g_source_set_callback(s->open_source, - qemu_chr_be_generic_open_func, - chr, NULL); - g_source_attach(s->open_source, chr->gcontext); - g_source_unref(s->open_source); } if (!chr->gsource) { chr->gsource = io_add_watch_poll(chr, s->ioc, diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h index e59f9ae1e9..1865afd993 100644 --- a/include/qemu/main-loop.h +++ b/include/qemu/main-loop.h @@ -295,6 +295,14 @@ void qemu_mutex_lock_iothread_impl(const char *file, int line); */ void qemu_mutex_unlock_iothread(void); +/** + * 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. + */ +GSource *qemu_idle_add(GSourceFunc func, gpointer data, GMainContext *ctx); + /* internal interfaces */ void qemu_fd_register(int fd); diff --git a/io/task.c b/io/task.c index c8489fb790..bdd395b0ad 100644 --- a/io/task.c +++ b/io/task.c @@ -19,6 +19,7 @@ */ #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "io/task.h" #include "qapi/error.h" #include "qemu/thread.h" @@ -105,7 +106,6 @@ static gboolean qio_task_thread_result(gpointer opaque) static gpointer qio_task_thread_worker(gpointer opaque) { struct QIOTaskThreadData *data = opaque; - GSource *idle; trace_qio_task_thread_run(data->task); data->worker(data->task, data->opaque); @@ -117,10 +117,7 @@ static gpointer qio_task_thread_worker(gpointer opaque) */ trace_qio_task_thread_exit(data->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_unref(idle); + qemu_idle_add(qio_task_thread_result, data, data->context); return NULL; } diff --git a/util/main-loop.c b/util/main-loop.c index 443cb4cfe8..1c68e3bf5f 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -171,6 +171,15 @@ int qemu_init_main_loop(Error **errp) return 0; } +GSource *qemu_idle_add(GSourceFunc func, gpointer data, GMainContext *ctx) +{ + GSource *idle = 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; #ifndef _WIN32