[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 3/5] iohandlers: Allow each iohandler to be enabl
From: |
Amit Shah |
Subject: |
[Qemu-devel] [PATCH v2 3/5] iohandlers: Allow each iohandler to be enabled/disabled individually |
Date: |
Thu, 13 Jan 2011 20:30:40 +0530 |
Each iohandler for an fd can now be individually enabled or disabled.
Signed-off-by: Amit Shah <address@hidden>
---
qemu-char.h | 4 +++
vl.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 79 insertions(+), 3 deletions(-)
diff --git a/qemu-char.h b/qemu-char.h
index 0ef83f4..e88a108 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -115,6 +115,10 @@ int assign_fd_handlers(int fd,
IOHandler *fd_write,
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);
+int set_write_fd_action(int fd, bool enable);
+
int qemu_set_fd_handler2(int fd,
IOCanReadHandler *fd_read_poll,
IOHandler *fd_read,
diff --git a/vl.c b/vl.c
index 30256e1..b9c902a 100644
--- a/vl.c
+++ b/vl.c
@@ -1014,6 +1014,9 @@ typedef struct IOHandlerRecord {
IOHandler *fd_write;
int deleted;
void *opaque;
+ bool read_poll_enabled;
+ bool read_enabled;
+ bool write_enabled;
/* temporary data */
struct pollfd *ufd;
QLIST_ENTRY(IOHandlerRecord) next;
@@ -1035,6 +1038,57 @@ static IOHandlerRecord *get_iohandler(int fd)
}
/*
+ * Enable the fd_read_poll handler for fd if the fd_read_poll handler exists.
+ */
+int set_read_poll_fd_action(int fd, bool enable)
+{
+ IOHandlerRecord *ioh;
+
+ ioh = get_iohandler(fd);
+
+ if (!ioh) {
+ return -1;
+ }
+ ioh->read_poll_enabled = enable;
+
+ return 0;
+}
+
+/*
+ * Enable the fd_read handler for fd if the fd_read handler exists.
+ */
+int set_read_fd_action(int fd, bool enable)
+{
+ IOHandlerRecord *ioh;
+
+ ioh = get_iohandler(fd);
+
+ if (!ioh) {
+ return -1;
+ }
+ ioh->read_enabled = enable;
+
+ return 0;
+}
+
+/*
+ * Enable the fd_write handler for fd if the fd_write handler exists.
+ */
+int set_write_fd_action(int fd, bool enable)
+{
+ IOHandlerRecord *ioh;
+
+ ioh = get_iohandler(fd);
+
+ if (!ioh) {
+ return -1;
+ }
+ ioh->write_enabled = enable;
+
+ return 0;
+}
+
+/*
* Specify function pointers for the various IOHandlers for an fd here.
*
* XXX: fd_read_poll should be suppressed, but an API change is
@@ -1067,6 +1121,20 @@ int assign_fd_handlers(int fd,
ioh->opaque = opaque;
ioh->deleted = 0;
+ /*
+ * To maintain compatibility with the callers that expect all
+ * handlers to be enabled. Callers that wish for some handlers
+ * not to be enabled right away should ensure they call
+ * set_xx_fd_action(fd, false) after this call.
+ *
+ * Note: if gets threading and one day is capable of running
+ * main_loop_wait() in parallel to this function, ensure this call
+ * and any later set_xx_fd_action() calls can execute atomically.
+ */
+ set_read_poll_fd_action(fd, true);
+ set_read_fd_action(fd, true);
+ set_write_fd_action(fd, true);
+
return 0;
}
@@ -1079,6 +1147,10 @@ void remove_fd_handlers(int fd)
assign_fd_handlers(fd, NULL, NULL, NULL, NULL);
}
+/*
+ * TODO: Deprecate these two function calls in favour of
+ * assign_fd_handlers().
+ */
int qemu_set_fd_handler2(int fd,
IOCanReadHandler *fd_read_poll,
IOHandler *fd_read,
@@ -1349,14 +1421,14 @@ void main_loop_wait(int nonblocking)
QLIST_FOREACH(ioh, &io_handlers, next) {
if (ioh->deleted)
continue;
- if (ioh->fd_read &&
+ if (ioh->fd_read && ioh->read_enabled &&
(!ioh->fd_read_poll ||
- ioh->fd_read_poll(ioh->opaque) != 0)) {
+ (!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) {
+ if (ioh->fd_write && ioh->write_enabled) {
FD_SET(ioh->fd, &wfds);
if (ioh->fd > nfds)
nfds = ioh->fd;
--
1.7.3.4
- [Qemu-devel] [PATCH v2 0/5] iohandlers: Add support for enabling/disabling individual handlers, Amit Shah, 2011/01/13
- [Qemu-devel] [PATCH v2 1/5] iohandlers: Avoid code duplication, Amit Shah, 2011/01/13
- [Qemu-devel] [PATCH v2 2/5] iohandlers: Introduce assign_fd_handlers() and remove_fd_handlers, Amit Shah, 2011/01/13
- [Qemu-devel] [PATCH v2 3/5] iohandlers: Allow each iohandler to be enabled/disabled individually,
Amit Shah <=
- [Qemu-devel] [PATCH v2 4/5] iohandlers: Enable an iohandler only if the associated handler exists, Amit Shah, 2011/01/13
- [Qemu-devel] [PATCH v2 5/5] iohandlers: Add IOHandlerOps struct, Amit Shah, 2011/01/13
- [Qemu-devel] Re: [PATCH v2 0/5] iohandlers: Add support for enabling/disabling individual handlers, Gerd Hoffmann, 2011/01/13
- [Qemu-devel] Re: [PATCH v2 0/5] iohandlers: Add support for enabling/disabling individual handlers, Anthony Liguori, 2011/01/13