From patchwork Thu Jan 13 15:00:41 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 78764 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 83792B6EEB for ; Fri, 14 Jan 2011 02:08:59 +1100 (EST) Received: from localhost ([127.0.0.1]:42414 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PdOnH-00073c-KP for incoming@patchwork.ozlabs.org; Thu, 13 Jan 2011 10:08:55 -0500 Received: from [140.186.70.92] (port=59233 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PdOfj-0002fE-Mu for qemu-devel@nongnu.org; Thu, 13 Jan 2011 10:01:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PdOfi-00020V-BJ for qemu-devel@nongnu.org; Thu, 13 Jan 2011 10:01:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:17081) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PdOfi-00020P-2P for qemu-devel@nongnu.org; Thu, 13 Jan 2011 10:01:06 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p0DF0uxB030061 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 13 Jan 2011 10:00:57 -0500 Received: from localhost (dhcp193-64.pnq.redhat.com [10.65.193.64]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p0DF0tmc008920; Thu, 13 Jan 2011 10:00:56 -0500 From: Amit Shah To: qemu list Date: Thu, 13 Jan 2011 20:30:41 +0530 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Amit Shah , Gerd Hoffmann , Paul Brook Subject: [Qemu-devel] [PATCH v2 4/5] iohandlers: Enable an iohandler only if the associated handler exists X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If an iohandler is asked to be enabled but the handler doesn't exist, don't enable the handler. This can be used to simplify the conditions in main_loop_wait(). Signed-off-by: Amit Shah --- vl.c | 29 ++++++++++++++++++++--------- 1 files changed, 20 insertions(+), 9 deletions(-) diff --git a/vl.c b/vl.c index b9c902a..4aa4158 100644 --- a/vl.c +++ b/vl.c @@ -1049,7 +1049,11 @@ int set_read_poll_fd_action(int fd, bool enable) if (!ioh) { return -1; } - ioh->read_poll_enabled = enable; + + ioh->read_poll_enabled = false; + if (enable && ioh->fd_read_poll) { + ioh->read_poll_enabled = true; + } return 0; } @@ -1066,7 +1070,11 @@ int set_read_fd_action(int fd, bool enable) if (!ioh) { return -1; } - ioh->read_enabled = enable; + + ioh->read_enabled = false; + if (enable && ioh->fd_read) { + ioh->read_enabled = true; + } return 0; } @@ -1083,7 +1091,11 @@ int set_write_fd_action(int fd, bool enable) if (!ioh) { return -1; } - ioh->write_enabled = enable; + + ioh->write_enabled = false; + if (enable && ioh->fd_write) { + ioh->write_enabled = true; + } return 0; } @@ -1421,14 +1433,13 @@ void main_loop_wait(int nonblocking) QLIST_FOREACH(ioh, &io_handlers, next) { if (ioh->deleted) continue; - if (ioh->fd_read && ioh->read_enabled && - (!ioh->fd_read_poll || - (!ioh->read_poll_enabled || ioh->fd_read_poll(ioh->opaque) != 0))) { + if (ioh->read_enabled && + (!ioh->read_poll_enabled || ioh->fd_read_poll(ioh->opaque) != 0)) { FD_SET(ioh->fd, &rfds); if (ioh->fd > nfds) nfds = ioh->fd; } - if (ioh->fd_write && ioh->write_enabled) { + if (ioh->write_enabled) { FD_SET(ioh->fd, &wfds); if (ioh->fd > nfds) nfds = ioh->fd; @@ -1447,10 +1458,10 @@ void main_loop_wait(int nonblocking) IOHandlerRecord *pioh; QLIST_FOREACH_SAFE(ioh, &io_handlers, next, pioh) { - if (!ioh->deleted && ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) { + if (!ioh->deleted && ioh->read_enabled && FD_ISSET(ioh->fd, &rfds)) { ioh->fd_read(ioh->opaque); } - if (!ioh->deleted && ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) { + if (!ioh->deleted && ioh->write_enabled && FD_ISSET(ioh->fd, &wfds)) { ioh->fd_write(ioh->opaque); }