From patchwork Mon Jun 20 08:23:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Chen X-Patchwork-Id: 9186853 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5F5166075F for ; Mon, 20 Jun 2016 08:23:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 482A424B48 for ; Mon, 20 Jun 2016 08:23:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 399BA24EE5; Mon, 20 Jun 2016 08:23:51 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 97C9324B48 for ; Mon, 20 Jun 2016 08:23:50 +0000 (UTC) Received: from localhost ([::1]:42035 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bEuUn-0002Dh-Fa for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jun 2016 04:23:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43294) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bEuUL-0002Bd-PD for qemu-devel@nongnu.org; Mon, 20 Jun 2016 04:23:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bEuUI-0002me-Gb for qemu-devel@nongnu.org; Mon, 20 Jun 2016 04:23:21 -0400 Received: from [59.151.112.132] (port=4520 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bEuUH-0002lm-Ot for qemu-devel@nongnu.org; Mon, 20 Jun 2016 04:23:18 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="7868590" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 20 Jun 2016 16:23:09 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id BABE4498F58D; Mon, 20 Jun 2016 16:23:05 +0800 (CST) Received: from G08FNSTD140215.g08.fujitsu.local (10.167.226.56) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.279.2; Mon, 20 Jun 2016 16:23:05 +0800 From: Zhang Chen To: qemu devel , "Daniel P . Berrange" , Paolo Bonzini Date: Mon, 20 Jun 2016 16:23:12 +0800 Message-ID: <1466410992-10462-1-git-send-email-zhangchen.fnst@cn.fujitsu.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.167.226.56] X-yoursite-MailScanner-ID: BABE4498F58D.A0390 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhangchen.fnst@cn.fujitsu.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 59.151.112.132 Subject: [Qemu-devel] [RFC PATCH] Change g_source_attach(xx, NULL) to g_souce_attach(xx, g_main_context_get_thread_default()) 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: "eddie . dong" , Jason Wang , Li Zhijian , Zhang Chen Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We want to poll and handle chardev in another thread other than main loop. But qemu_chr_add_handlers() can only work for global default context other than thread default context. So we use g_souce_attach(xx, g_main_context_get_thread_default()) replace g_source_attach(xx, NULL) to attach g_source. Comments form jason. Signed-off-by: Zhang Chen Signed-off-by: Jason Wang --- io/channel.c | 2 +- qemu-char.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/io/channel.c b/io/channel.c index 692eb17..cd25677 100644 --- a/io/channel.c +++ b/io/channel.c @@ -146,7 +146,7 @@ guint qio_channel_add_watch(QIOChannel *ioc, g_source_set_callback(source, (GSourceFunc)func, user_data, notify); - id = g_source_attach(source, NULL); + id = g_source_attach(source, g_main_context_get_thread_default()); g_source_unref(source); return id; diff --git a/qemu-char.c b/qemu-char.c index 84f49ac..4340457 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -859,7 +859,7 @@ static gboolean io_watch_poll_prepare(GSource *source, gint *timeout_) iwp->src = qio_channel_create_watch( iwp->ioc, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL); g_source_set_callback(iwp->src, iwp->fd_read, iwp->opaque, NULL); - g_source_attach(iwp->src, NULL); + g_source_attach(iwp->src, g_main_context_get_thread_default()); } else { g_source_destroy(iwp->src); g_source_unref(iwp->src); @@ -918,7 +918,7 @@ static guint io_add_watch_poll(QIOChannel *ioc, iwp->fd_read = (GSourceFunc) fd_read; iwp->src = NULL; - tag = g_source_attach(&iwp->parent, NULL); + tag = g_source_attach(&iwp->parent, g_main_context_get_thread_default()); g_source_unref(&iwp->parent); return tag; } @@ -3982,7 +3982,7 @@ int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond, } g_source_set_callback(src, (GSourceFunc)func, user_data, NULL); - tag = g_source_attach(src, NULL); + tag = g_source_attach(src, g_main_context_get_thread_default()); g_source_unref(src); return tag;