From patchwork Tue Mar 20 09:49:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 147779 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9DB61B6EF3 for ; Tue, 20 Mar 2012 21:28:38 +1100 (EST) Received: from localhost ([::1]:58584 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9viG-0003Gp-Rj for incoming@patchwork.ozlabs.org; Tue, 20 Mar 2012 05:50:44 -0400 Received: from eggs.gnu.org ([208.118.235.92]:39729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9vhQ-0000oN-RM for qemu-devel@nongnu.org; Tue, 20 Mar 2012 05:50:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S9vhG-00046E-J2 for qemu-devel@nongnu.org; Tue, 20 Mar 2012 05:49:52 -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 1S9vhG-00044O-9s for qemu-devel@nongnu.org; Tue, 20 Mar 2012 05:49:42 -0400 Received: by mail-pz0-f45.google.com with SMTP id p14so12574898dad.4 for ; Tue, 20 Mar 2012 02:49:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=XG9Ln7arrwV/5OTXtIrY7uVcurO4hqyjWmN/Sf8OW3A=; b=HnRDJwruhSjQrxjELHiW39XIIbbeD/QAA1GsyFNHPz451tCa0oW4wval+4ZND0zZ9K 3Ah9IUrDdJUiDfJqlxW1bcJkbtSbk4UbijVaPy/rMcl1O98yoBNSAwkGF9IF5P9t8eLt Nl7Kcx34i9uAGi7jPChAWYlmsJrsHZ75/hqvjmM8ktMaokVYoIT3gxcL/Jvr3mbvJsol JRo4oEnVNZ6hAN8JtnbzUKC2rBR8jlaMjvQo5kkIweWy8yS78vQZExU2L3fgaMwTRfmJ Kc8y/1sc4f+eOnXHNDdvQiDRLx9Uf3CHcYDLbh0BVkHirZR4g9+QdamROo/hy42BBRip TY9A== Received: by 10.68.223.97 with SMTP id qt1mr48147182pbc.6.1332236981235; Tue, 20 Mar 2012 02:49:41 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-182-16.ip50.fastwebnet.it. [93.34.182.16]) by mx.google.com with ESMTPS id d4sm945939pbe.36.2012.03.20.02.49.38 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 20 Mar 2012 02:49:40 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 20 Mar 2012 10:49:18 +0100 Message-Id: <1332236961-22743-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.7.6 In-Reply-To: <1332236961-22743-1-git-send-email-pbonzini@redhat.com> References: <1332236961-22743-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.210.45 Cc: sw@weilnetz.de Subject: [Qemu-devel] [PATCH 3/6] main-loop: disable fd_set-based glib integration under w32 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Using select with glib pollfds is wrong under w32. Restrict the code to the POSIX case. Signed-off-by: Paolo Bonzini --- main-loop.c | 63 ++++++++++++++++++++++++++++++---------------------------- 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));