From: Amit Shah <amit.shah@redhat.com>
To: qemu list <qemu-devel@nongnu.org>
Cc: Amit Shah <amit.shah@redhat.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Paul Brook <paul@codesourcery.com>
Subject: [Qemu-devel] [PATCH 1/5] iohandlers: Avoid code duplication
Date: Thu, 13 Jan 2011 18:30:06 +0530 [thread overview]
Message-ID: <dd607fe272c093989512a1856a6a1fb0eb81e3b5.1294923288.git.amit.shah@redhat.com> (raw)
In-Reply-To: <cover.1294923288.git.amit.shah@redhat.com>
In-Reply-To: <cover.1294923288.git.amit.shah@redhat.com>
Add a get_iohandler() function instead of looking up the ioh twice in
qemu_set_fd_handler2().
Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
vl.c | 44 ++++++++++++++++++++++++++------------------
1 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/vl.c b/vl.c
index 0292184..9e365f6 100644
--- a/vl.c
+++ b/vl.c
@@ -1022,6 +1022,17 @@ typedef struct IOHandlerRecord {
static QLIST_HEAD(, IOHandlerRecord) io_handlers =
QLIST_HEAD_INITIALIZER(io_handlers);
+static IOHandlerRecord *get_iohandler(int fd)
+{
+ IOHandlerRecord *ioh;
+
+ QLIST_FOREACH(ioh, &io_handlers, next) {
+ if (ioh->fd == fd) {
+ return ioh;
+ }
+ }
+ return NULL;
+}
/* XXX: fd_read_poll should be suppressed, but an API change is
necessary in the character devices to suppress fd_can_read(). */
@@ -1033,28 +1044,25 @@ int qemu_set_fd_handler2(int fd,
{
IOHandlerRecord *ioh;
- if (!fd_read && !fd_write) {
- QLIST_FOREACH(ioh, &io_handlers, next) {
- if (ioh->fd == fd) {
- ioh->deleted = 1;
- break;
- }
- }
- } else {
- QLIST_FOREACH(ioh, &io_handlers, next) {
- if (ioh->fd == fd)
- goto found;
- }
+ ioh = get_iohandler(fd);
+
+ if (ioh && !fd_read && !fd_write) {
+ ioh->deleted = 1;
+ return 0;
+ }
+
+ if (!ioh) {
ioh = qemu_mallocz(sizeof(IOHandlerRecord));
QLIST_INSERT_HEAD(&io_handlers, ioh, next);
- found:
+
ioh->fd = fd;
- ioh->fd_read_poll = fd_read_poll;
- ioh->fd_read = fd_read;
- ioh->fd_write = fd_write;
- ioh->opaque = opaque;
- ioh->deleted = 0;
}
+ ioh->fd_read_poll = fd_read_poll;
+ ioh->fd_read = fd_read;
+ ioh->fd_write = fd_write;
+ ioh->opaque = opaque;
+ ioh->deleted = 0;
+
return 0;
}
--
1.7.3.4
next prev parent reply other threads:[~2011-01-13 13:00 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-13 13:00 [Qemu-devel] [PATCH 0/5] iohandlers: Add support for enabling/disabling individual handlers Amit Shah
2011-01-13 13:00 ` Amit Shah [this message]
2011-01-13 13:00 ` [Qemu-devel] [PATCH 2/5] iohandlers: Introduce assign_fd_handlers() and remove_fd_handlers Amit Shah
2011-01-13 13:59 ` [Qemu-devel] " Gerd Hoffmann
2011-01-13 14:10 ` Amit Shah
2011-01-13 13:00 ` [Qemu-devel] [PATCH 3/5] iohandlers: Allow each iohandler to be enabled/disabled individually Amit Shah
2011-01-13 13:55 ` [Qemu-devel] " Gerd Hoffmann
2011-01-13 14:00 ` Amit Shah
2011-01-13 14:08 ` Gerd Hoffmann
2011-01-13 14:18 ` Amit Shah
2011-01-13 14:53 ` Gerd Hoffmann
2011-01-13 13:00 ` [Qemu-devel] [PATCH 4/5] iohandlers: Enable an iohandler only if the associated handler exists Amit Shah
2011-01-13 13:00 ` [Qemu-devel] [PATCH 5/5] iohandlers: Add IOHandlerOps struct Amit Shah
2011-01-13 14:02 ` [Qemu-devel] " Gerd Hoffmann
2011-01-13 14:09 ` Amit Shah
2011-01-13 14:04 ` [Qemu-devel] Re: [PATCH 0/5] iohandlers: Add support for enabling/disabling individual handlers Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dd607fe272c093989512a1856a6a1fb0eb81e3b5.1294923288.git.amit.shah@redhat.com \
--to=amit.shah@redhat.com \
--cc=kraxel@redhat.com \
--cc=paul@codesourcery.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).