aboutsummaryrefslogtreecommitdiff
path: root/main-loop.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-03-20 10:49:18 +0100
committerBlue Swirl <blauwirbel@gmail.com>2012-04-07 08:34:15 +0000
commit15455536df5ef652759ccf465d5e6f73acb493df (patch)
tree75001135bb4bab3119c17ee862dafe81ca22c669 /main-loop.c
parent4dae83aeac63863af6b59f58552da68b35b1a40d (diff)
downloadqemu-15455536df5ef652759ccf465d5e6f73acb493df.zip
qemu-15455536df5ef652759ccf465d5e6f73acb493df.tar.gz
qemu-15455536df5ef652759ccf465d5e6f73acb493df.tar.bz2
main-loop: disable fd_set-based glib integration under w32
Using select with glib pollfds is wrong under w32. Restrict the code to the POSIX case. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Diffstat (limited to 'main-loop.c')
-rw-r--r--main-loop.c63
1 files changed, 33 insertions, 30 deletions
diff --git a/main-loop.c b/main-loop.c
index a3fd993..dc6bdb5 100644
--- a/main-loop.c
+++ b/main-loop.c
@@ -218,7 +218,10 @@ int main_loop_init(void)
return 0;
}
+static fd_set rfds, wfds, xfds;
+static int nfds;
+#ifndef _WIN32
static GPollFD poll_fds[1024 * 2]; /* this is probably overkill */
static int n_poll_fds;
static int max_priority;
@@ -286,7 +289,29 @@ static void glib_select_poll(fd_set *rfds, fd_set *wfds, fd_set *xfds,
}
}
-#ifdef _WIN32
+static int os_host_main_loop_wait(int timeout)
+{
+ struct timeval tv;
+ int ret;
+
+ glib_select_fill(&nfds, &rfds, &wfds, &xfds, &timeout);
+
+ if (timeout > 0) {
+ qemu_mutex_unlock_iothread();
+ }
+
+ tv.tv_sec = timeout / 1000;
+ tv.tv_usec = (timeout % 1000) * 1000;
+ ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
+
+ if (timeout > 0) {
+ qemu_mutex_lock_iothread();
+ }
+
+ glib_select_poll(&rfds, &wfds, &xfds, (ret < 0));
+ return ret;
+}
+#else
/***********************************************************/
/* Polling handling */
@@ -367,10 +392,11 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
}
}
-static void os_host_main_loop_wait(int *timeout)
+static int os_host_main_loop_wait(int timeout)
{
int ret, ret2, i;
PollingEntry *pe;
+ static struct timeval tv0;
/* XXX: need to suppress polling by better using win32 events */
ret = 0;
@@ -382,7 +408,7 @@ static void os_host_main_loop_wait(int *timeout)
WaitObjects *w = &wait_objects;
qemu_mutex_unlock_iothread();
- ret = WaitForMultipleObjects(w->num, w->events, FALSE, *timeout);
+ ret = WaitForMultipleObjects(w->num, w->events, FALSE, timeout);
qemu_mutex_lock_iothread();
if (WAIT_OBJECT_0 + 0 <= ret && ret <= WAIT_OBJECT_0 + w->num - 1) {
if (w->func[ret - WAIT_OBJECT_0]) {
@@ -408,20 +434,14 @@ static void os_host_main_loop_wait(int *timeout)
}
}
- *timeout = 0;
-}
-#else
-static inline void os_host_main_loop_wait(int *timeout)
-{
+ ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv0);
+ return ret;
}
#endif
int main_loop_wait(int nonblocking)
{
- fd_set rfds, wfds, xfds;
- int ret, nfds;
- struct timeval tv;
- int timeout;
+ int ret, timeout;
if (nonblocking) {
timeout = 0;
@@ -441,24 +461,7 @@ int main_loop_wait(int nonblocking)
slirp_select_fill(&nfds, &rfds, &wfds, &xfds);
#endif
qemu_iohandler_fill(&nfds, &rfds, &wfds, &xfds);
-
- glib_select_fill(&nfds, &rfds, &wfds, &xfds, &timeout);
- os_host_main_loop_wait(&timeout);
-
- tv.tv_sec = timeout / 1000;
- tv.tv_usec = (timeout % 1000) * 1000;
-
- if (timeout > 0) {
- qemu_mutex_unlock_iothread();
- }
-
- ret = select(nfds + 1, &rfds, &wfds, &xfds, &tv);
-
- if (timeout > 0) {
- qemu_mutex_lock_iothread();
- }
-
- glib_select_poll(&rfds, &wfds, &xfds, (ret < 0));
+ ret = os_host_main_loop_wait(timeout);
qemu_iohandler_poll(&rfds, &wfds, &xfds, ret);
#ifdef CONFIG_SLIRP
slirp_select_poll(&rfds, &wfds, &xfds, (ret < 0));