main loop: use msec-based timeout in glib_select_fill

The timeval-based timeout is not needed until we actually invoke select,
so compute it only then.  Also group the two calls that modify the
timeout, glib_select_fill and os_host_main_loop_wait.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
This commit is contained in:
Paolo Bonzini 2012-03-20 10:49:17 +01:00 committed by Blue Swirl
parent ab7ab3d74c
commit 4dae83aeac

View File

@ -224,11 +224,11 @@ static int n_poll_fds;
static int max_priority; static int max_priority;
static void glib_select_fill(int *max_fd, fd_set *rfds, fd_set *wfds, static void glib_select_fill(int *max_fd, fd_set *rfds, fd_set *wfds,
fd_set *xfds, struct timeval *tv) fd_set *xfds, int *cur_timeout)
{ {
GMainContext *context = g_main_context_default(); GMainContext *context = g_main_context_default();
int i; int i;
int timeout = 0, cur_timeout; int timeout = 0;
g_main_context_prepare(context, &max_priority); g_main_context_prepare(context, &max_priority);
@ -253,10 +253,8 @@ static void glib_select_fill(int *max_fd, fd_set *rfds, fd_set *wfds,
} }
} }
cur_timeout = (tv->tv_sec * 1000) + ((tv->tv_usec + 500) / 1000); if (timeout >= 0 && timeout < *cur_timeout) {
if (timeout >= 0 && timeout < cur_timeout) { *cur_timeout = timeout;
tv->tv_sec = timeout / 1000;
tv->tv_usec = (timeout % 1000) * 1000;
} }
} }
@ -432,11 +430,6 @@ int main_loop_wait(int nonblocking)
qemu_bh_update_timeout(&timeout); qemu_bh_update_timeout(&timeout);
} }
os_host_main_loop_wait(&timeout);
tv.tv_sec = timeout / 1000;
tv.tv_usec = (timeout % 1000) * 1000;
/* poll any events */ /* poll any events */
/* XXX: separate device handlers from system ones */ /* XXX: separate device handlers from system ones */
nfds = -1; nfds = -1;
@ -448,7 +441,12 @@ int main_loop_wait(int nonblocking)
slirp_select_fill(&nfds, &rfds, &wfds, &xfds); slirp_select_fill(&nfds, &rfds, &wfds, &xfds);
#endif #endif
qemu_iohandler_fill(&nfds, &rfds, &wfds, &xfds); qemu_iohandler_fill(&nfds, &rfds, &wfds, &xfds);
glib_select_fill(&nfds, &rfds, &wfds, &xfds, &tv);
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) { if (timeout > 0) {
qemu_mutex_unlock_iothread(); qemu_mutex_unlock_iothread();