From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: sw@weilnetz.de
Subject: [Qemu-devel] [PATCH 2/6] main loop: use msec-based timeout in glib_select_fill
Date: Tue, 20 Mar 2012 10:49:17 +0100 [thread overview]
Message-ID: <1332236961-22743-3-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1332236961-22743-1-git-send-email-pbonzini@redhat.com>
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>
---
main-loop.c | 22 ++++++++++------------
1 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/main-loop.c b/main-loop.c
index db23de0..a3fd993 100644
--- a/main-loop.c
+++ b/main-loop.c
@@ -224,11 +224,11 @@ 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)
+ fd_set *xfds, int *cur_timeout)
{
GMainContext *context = g_main_context_default();
int i;
- int timeout = 0, cur_timeout;
+ int timeout = 0;
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) {
- tv->tv_sec = timeout / 1000;
- tv->tv_usec = (timeout % 1000) * 1000;
+ if (timeout >= 0 && timeout < *cur_timeout) {
+ *cur_timeout = timeout;
}
}
@@ -432,11 +430,6 @@ int main_loop_wait(int nonblocking)
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 */
/* XXX: separate device handlers from system ones */
nfds = -1;
@@ -448,7 +441,12 @@ 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, &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) {
qemu_mutex_unlock_iothread();
--
1.7.7.6
next prev parent reply other threads:[~2012-03-20 9:50 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-20 9:49 [Qemu-devel] [PATCH 0/6] fix w32 sockets Paolo Bonzini
2012-03-20 9:49 ` [Qemu-devel] [PATCH 1/6] slirp: use socket_set_nonblock Paolo Bonzini
2012-03-20 23:14 ` Stefan Weil
2012-03-21 6:04 ` Paolo Bonzini
2012-03-20 9:49 ` Paolo Bonzini [this message]
2012-03-20 9:49 ` [Qemu-devel] [PATCH 3/6] main-loop: disable fd_set-based glib integration under w32 Paolo Bonzini
2012-03-20 9:49 ` [Qemu-devel] [PATCH 4/6] main-loop: interrupt wait when data arrives on a socket Paolo Bonzini
2012-03-20 9:49 ` [Qemu-devel] [PATCH 5/6] main-loop: replace WaitForMultipleObjects with g_poll Paolo Bonzini
2012-04-04 20:44 ` Blue Swirl
2012-04-04 21:07 ` Peter Maydell
2012-04-05 8:12 ` Paolo Bonzini
2012-04-05 8:48 ` Peter Maydell
2012-04-05 8:56 ` Paolo Bonzini
2012-03-20 9:49 ` [Qemu-devel] [PATCH 6/6] main-loop: integrate glib sources for w32 Paolo Bonzini
2012-03-20 23:32 ` [Qemu-devel] [PATCH 0/6] fix w32 sockets Stefan Weil
2012-04-03 11:06 ` Paolo Bonzini
2012-04-03 20:24 ` Stefan Weil
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=1332236961-22743-3-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sw@weilnetz.de \
/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).