From patchwork Mon Aug 27 22:23:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 962673 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41zmhz2QTBz9s3x for ; Tue, 28 Aug 2018 08:27:15 +1000 (AEST) Received: from localhost ([::1]:35319 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fuPya-00064U-MQ for incoming@patchwork.ozlabs.org; Mon, 27 Aug 2018 18:27:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56498) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fuPv5-0003fF-Me for qemu-devel@nongnu.org; Mon, 27 Aug 2018 18:23:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fuPv4-0005jR-Mb for qemu-devel@nongnu.org; Mon, 27 Aug 2018 18:23:35 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:34112 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fuPv4-0005ij-GZ for qemu-devel@nongnu.org; Mon, 27 Aug 2018 18:23:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3211087A82 for ; Mon, 27 Aug 2018 22:23:34 +0000 (UTC) Received: from localhost (ovpn-112-17.ams2.redhat.com [10.36.112.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 152E36353E; Mon, 27 Aug 2018 22:23:31 +0000 (UTC) From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= To: qemu-devel@nongnu.org Date: Tue, 28 Aug 2018 00:23:16 +0200 Message-Id: <20180827222322.26009-4-marcandre.lureau@redhat.com> In-Reply-To: <20180827222322.26009-1-marcandre.lureau@redhat.com> References: <20180827222322.26009-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 27 Aug 2018 22:23:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 27 Aug 2018 22:23:34 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'marcandre.lureau@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 3/9] chardev: use a child source for qio input source 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, armbru@redhat.com, =?utf-8?q?Marc-Andr=C3=A9_Lure?= =?utf-8?q?au?= Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" GLib child source were added with version 2.28. We can use them now that we bumped our requirement to 2.40. Signed-off-by: Marc-André Lureau Reviewed-by: Daniel P. Berrangé --- chardev/char-io.c | 48 +++++------------------------------------------ 1 file changed, 5 insertions(+), 43 deletions(-) diff --git a/chardev/char-io.c b/chardev/char-io.c index f81052481a..8ced184160 100644 --- a/chardev/char-io.c +++ b/chardev/char-io.c @@ -33,7 +33,6 @@ typedef struct IOWatchPoll { IOCanReadHandler *fd_can_read; GSourceFunc fd_read; void *opaque; - GMainContext *context; } IOWatchPoll; static IOWatchPoll *io_watch_poll_from_source(GSource *source) @@ -55,47 +54,24 @@ static gboolean io_watch_poll_prepare(GSource *source, 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, iwp->context); - } else { - g_source_destroy(iwp->src); + g_source_add_child_source(source, iwp->src); g_source_unref(iwp->src); + } else { + g_source_remove_child_source(source, iwp->src); iwp->src = NULL; } return FALSE; } -static gboolean io_watch_poll_check(GSource *source) -{ - return FALSE; -} - static gboolean io_watch_poll_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) { - abort(); -} - -static void io_watch_poll_finalize(GSource *source) -{ - /* Due to a glib bug, removing the last reference to a source - * inside a finalize callback causes recursive locking (and a - * deadlock). This is not a problem inside other callbacks, - * including dispatch callbacks, so we call io_remove_watch_poll - * to remove this source. At this point, iwp->src must - * be NULL, or we would leak it. - * - * This would be solved much more elegantly by child sources, - * but we support older glib versions that do not have them. - */ - IOWatchPoll *iwp = io_watch_poll_from_source(source); - assert(iwp->src == NULL); + return G_SOURCE_CONTINUE; } static GSourceFuncs io_watch_poll_funcs = { .prepare = io_watch_poll_prepare, - .check = io_watch_poll_check, .dispatch = io_watch_poll_dispatch, - .finalize = io_watch_poll_finalize, }; GSource *io_add_watch_poll(Chardev *chr, @@ -115,7 +91,6 @@ GSource *io_add_watch_poll(Chardev *chr, iwp->ioc = ioc; iwp->fd_read = (GSourceFunc) fd_read; iwp->src = NULL; - iwp->context = context; name = g_strdup_printf("chardev-iowatch-%s", chr->label); g_source_set_name((GSource *)iwp, name); @@ -126,23 +101,10 @@ GSource *io_add_watch_poll(Chardev *chr, return (GSource *)iwp; } -static void io_remove_watch_poll(GSource *source) -{ - IOWatchPoll *iwp; - - iwp = io_watch_poll_from_source(source); - if (iwp->src) { - g_source_destroy(iwp->src); - g_source_unref(iwp->src); - iwp->src = NULL; - } - g_source_destroy(&iwp->parent); -} - void remove_fd_in_watch(Chardev *chr) { if (chr->gsource) { - io_remove_watch_poll(chr->gsource); + g_source_destroy(chr->gsource); chr->gsource = NULL; } }