From patchwork Thu Jan 13 15:00:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 78761 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 598BBB70A9 for ; Fri, 14 Jan 2011 02:05:10 +1100 (EST) Received: from localhost ([127.0.0.1]:44004 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PdOjZ-0004Y2-TH for incoming@patchwork.ozlabs.org; Thu, 13 Jan 2011 10:05:06 -0500 Received: from [140.186.70.92] (port=59277 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PdOfr-0002lP-Ei for qemu-devel@nongnu.org; Thu, 13 Jan 2011 10:01:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PdOfp-00021g-BQ for qemu-devel@nongnu.org; Thu, 13 Jan 2011 10:01:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41484) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PdOfo-00021P-Tc for qemu-devel@nongnu.org; Thu, 13 Jan 2011 10:01:13 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p0DF0xRv022872 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 13 Jan 2011 10:00:59 -0500 Received: from localhost (dhcp193-64.pnq.redhat.com [10.65.193.64]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p0DF0vH5001883; Thu, 13 Jan 2011 10:00:58 -0500 From: Amit Shah To: qemu list Date: Thu, 13 Jan 2011 20:30:42 +0530 Message-Id: <58d72648d2e4fe51a697ea9a6d99bbab8a3a9afa.1294930723.git.amit.shah@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 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 5/5] iohandlers: Add IOHandlerOps struct 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 Collect all the handlers in a IOHandlerOps struct instead of being passed one at a time to each function. Signed-off-by: Amit Shah --- qemu-char.h | 7 ++----- vl.c | 56 ++++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/qemu-char.h b/qemu-char.h index e88a108..ebf9cd1 100644 --- a/qemu-char.h +++ b/qemu-char.h @@ -108,12 +108,9 @@ QString *qemu_chr_mem_to_qs(CharDriverState *chr); size_t qemu_chr_mem_osize(const CharDriverState *chr); /* async I/O support */ +typedef struct IOHandlerOps IOHandlerOps; -int assign_fd_handlers(int fd, - IOCanReadHandler *fd_read_poll, - IOHandler *fd_read, - IOHandler *fd_write, - void *opaque); +int assign_fd_handlers(int fd, const IOHandlerOps *ops, void *opaque); void remove_fd_handlers(int fd); int set_read_poll_fd_action(int fd, bool enable); int set_read_fd_action(int fd, bool enable); diff --git a/vl.c b/vl.c index 4aa4158..a98256c 100644 --- a/vl.c +++ b/vl.c @@ -1007,11 +1007,20 @@ void pcmcia_info(Monitor *mon) /***********************************************************/ /* I/O handling */ -typedef struct IOHandlerRecord { - int fd; +struct IOHandlerOps { IOCanReadHandler *fd_read_poll; IOHandler *fd_read; IOHandler *fd_write; +}; + +typedef struct IOHandlerRecord { + int fd; + /* + * TODO: once the users of qemu_set_fd_handler*() functions have + * been removed, just store the ops pointer instead of copying + * over each element here. + */ + IOHandlerOps ops; int deleted; void *opaque; bool read_poll_enabled; @@ -1025,6 +1034,10 @@ typedef struct IOHandlerRecord { static QLIST_HEAD(, IOHandlerRecord) io_handlers = QLIST_HEAD_INITIALIZER(io_handlers); +static const IOHandlerOps null_ioh_ops = { + /* All ops are NULL */ +}; + static IOHandlerRecord *get_iohandler(int fd) { IOHandlerRecord *ioh; @@ -1051,7 +1064,7 @@ int set_read_poll_fd_action(int fd, bool enable) } ioh->read_poll_enabled = false; - if (enable && ioh->fd_read_poll) { + if (enable && ioh->ops.fd_read_poll) { ioh->read_poll_enabled = true; } @@ -1072,7 +1085,7 @@ int set_read_fd_action(int fd, bool enable) } ioh->read_enabled = false; - if (enable && ioh->fd_read) { + if (enable && ioh->ops.fd_read) { ioh->read_enabled = true; } @@ -1093,7 +1106,7 @@ int set_write_fd_action(int fd, bool enable) } ioh->write_enabled = false; - if (enable && ioh->fd_write) { + if (enable && ioh->ops.fd_write) { ioh->write_enabled = true; } @@ -1106,17 +1119,16 @@ int set_write_fd_action(int fd, bool enable) * XXX: fd_read_poll should be suppressed, but an API change is * necessary in the character devices to suppress fd_can_read(). */ -int assign_fd_handlers(int fd, - IOCanReadHandler *fd_read_poll, - IOHandler *fd_read, - IOHandler *fd_write, - void *opaque) +int assign_fd_handlers(int fd, const IOHandlerOps *ops, void *opaque) { IOHandlerRecord *ioh; ioh = get_iohandler(fd); - if (ioh && !fd_read && !fd_write) { + if (!ops) { + ops = &null_ioh_ops; + } + if (ioh && !ops->fd_read && !ops->fd_write) { ioh->deleted = 1; return 0; } @@ -1127,9 +1139,7 @@ int assign_fd_handlers(int fd, ioh->fd = fd; } - ioh->fd_read_poll = fd_read_poll; - ioh->fd_read = fd_read; - ioh->fd_write = fd_write; + ioh->ops = *ops; ioh->opaque = opaque; ioh->deleted = 0; @@ -1156,12 +1166,13 @@ int assign_fd_handlers(int fd, */ void remove_fd_handlers(int fd) { - assign_fd_handlers(fd, NULL, NULL, NULL, NULL); + assign_fd_handlers(fd, NULL, NULL); } /* * TODO: Deprecate these two function calls in favour of - * assign_fd_handlers(). + * assign_fd_handlers(). When that happens, also see the TODO in the + * IOHandlerRecord struct above. */ int qemu_set_fd_handler2(int fd, IOCanReadHandler *fd_read_poll, @@ -1169,7 +1180,12 @@ int qemu_set_fd_handler2(int fd, IOHandler *fd_write, void *opaque) { - return assign_fd_handlers(fd, fd_read_poll, fd_read, fd_write, opaque); + IOHandlerOps ops; + + ops.fd_read_poll = fd_read_poll; + ops.fd_read = fd_read; + ops.fd_write = fd_write; + return assign_fd_handlers(fd, &ops, opaque); } int qemu_set_fd_handler(int fd, @@ -1434,7 +1450,7 @@ void main_loop_wait(int nonblocking) if (ioh->deleted) continue; if (ioh->read_enabled && - (!ioh->read_poll_enabled || ioh->fd_read_poll(ioh->opaque) != 0)) { + (!ioh->read_poll_enabled || ioh->ops.fd_read_poll(ioh->opaque) != 0)) { FD_SET(ioh->fd, &rfds); if (ioh->fd > nfds) nfds = ioh->fd; @@ -1459,10 +1475,10 @@ void main_loop_wait(int nonblocking) QLIST_FOREACH_SAFE(ioh, &io_handlers, next, pioh) { if (!ioh->deleted && ioh->read_enabled && FD_ISSET(ioh->fd, &rfds)) { - ioh->fd_read(ioh->opaque); + ioh->ops.fd_read(ioh->opaque); } if (!ioh->deleted && ioh->write_enabled && FD_ISSET(ioh->fd, &wfds)) { - ioh->fd_write(ioh->opaque); + ioh->ops.fd_write(ioh->opaque); } /* Do this last in case read/write handlers marked it for deletion */