From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=42239 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PdMn7-0005qI-Mv for qemu-devel@nongnu.org; Thu, 13 Jan 2011 08:00:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PdMn6-0004YJ-Ey for qemu-devel@nongnu.org; Thu, 13 Jan 2011 08:00:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40816) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PdMn6-0004YC-6R for qemu-devel@nongnu.org; Thu, 13 Jan 2011 08:00:36 -0500 From: Amit Shah Date: Thu, 13 Jan 2011 18:30:09 +0530 Message-Id: <49f375dde4a19ec267f82e09137bf4f8df922aa9.1294923288.git.amit.shah@redhat.com> In-Reply-To: References: In-Reply-To: References: Subject: [Qemu-devel] [PATCH 4/5] iohandlers: Enable an iohandler only if the associated handler exists List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu list Cc: Amit Shah , Gerd Hoffmann , Paul Brook 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 a0b14b5..42ec36a 100644 --- a/vl.c +++ b/vl.c @@ -1084,7 +1084,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; } @@ -1098,7 +1102,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; } @@ -1112,7 +1120,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; } @@ -1391,14 +1403,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; @@ -1417,10 +1428,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); } -- 1.7.3.4