From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:39797) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9vhg-0001Zc-8o for qemu-devel@nongnu.org; Tue, 20 Mar 2012 05:50:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S9vhD-00045X-BO for qemu-devel@nongnu.org; Tue, 20 Mar 2012 05:50:07 -0400 Received: from mail-pz0-f45.google.com ([209.85.210.45]:35577) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9vhD-00044O-25 for qemu-devel@nongnu.org; Tue, 20 Mar 2012 05:49:39 -0400 Received: by mail-pz0-f45.google.com with SMTP id p14so12574898dad.4 for ; Tue, 20 Mar 2012 02:49:38 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Tue, 20 Mar 2012 10:49:17 +0100 Message-Id: <1332236961-22743-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1332236961-22743-1-git-send-email-pbonzini@redhat.com> References: <1332236961-22743-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 2/6] main loop: use msec-based timeout in glib_select_fill List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: sw@weilnetz.de 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 --- 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