This allows GSources to be used to register callback events in QEMU.
This is
useful as it allows us to take greater advantage of glib and also because
it
allows us to write code that is more easily testable outside of QEMU
since we
can make use of glib's main loop in unit tests.
All new code should use glib's callback mechanisms for registering fd
events
which are very well documented at:
http://developer.gnome.org/glib/stable/glib-The-Main-Event-Loop.html
And:
http://developer.gnome.org/gio/stable/
Signed-off-by: Anthony Liguori<address@hidden>
---
vl.c | 74
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 74 insertions(+), 0 deletions(-)
diff --git a/vl.c b/vl.c
index 4b6688b..19774ac 100644
--- a/vl.c
+++ b/vl.c
@@ -111,6 +111,8 @@ int main(int argc, char **argv)
#define main qemu_main
#endif /* CONFIG_COCOA */
+#include<glib.h>
+
#include "hw/hw.h"
#include "hw/boards.h"
#include "hw/usb.h"
@@ -1309,6 +1311,75 @@ void qemu_system_vmstop_request(int reason)
qemu_notify_event();
}
+static GPollFD poll_fds[1024 * 2]; /* this is probably overkill */
+static int n_poll_fds;
+static int max_priority;
+
+static void glib_select_fill(int *max_fd, fd_set *rfds, fd_set *wfds,
+ fd_set *xfds, struct timeval *tv)
+{
+ GMainContext *context = g_main_context_default();
+ int i;
+ int timeout = 0, cur_timeout;
+
+ g_main_context_prepare(context,&max_priority);
+
+ n_poll_fds = g_main_context_query(context, max_priority,&timeout,
+ poll_fds, ARRAY_SIZE(poll_fds));
+ g_assert(n_poll_fds<= ARRAY_SIZE(poll_fds));