From patchwork Fri Jun 4 13:24:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jes Sorensen X-Patchwork-Id: 54591 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B4D0AB7D2E for ; Sat, 5 Jun 2010 00:23:03 +1000 (EST) Received: from localhost ([127.0.0.1]:43617 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKXnW-0001fQ-4F for incoming@patchwork.ozlabs.org; Fri, 04 Jun 2010 10:22:58 -0400 Received: from [140.186.70.92] (port=47166 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OKWtc-0005kF-Lh for qemu-devel@nongnu.org; Fri, 04 Jun 2010 09:31:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OKWtS-0001mM-Lv for qemu-devel@nongnu.org; Fri, 04 Jun 2010 09:25:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38100) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OKWtS-0001m5-7U for qemu-devel@nongnu.org; Fri, 04 Jun 2010 09:25:02 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o54DOx1s006817 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 4 Jun 2010 09:24:59 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o54DOm6T005003; Fri, 4 Jun 2010 09:24:57 -0400 From: Jes.Sorensen@redhat.com To: anthony@codemonkey.ws Date: Fri, 4 Jun 2010 15:24:29 +0200 Message-Id: <1275657882-19268-7-git-send-email-Jes.Sorensen@redhat.com> In-Reply-To: <1275657882-19268-1-git-send-email-Jes.Sorensen@redhat.com> References: <1275657882-19268-1-git-send-email-Jes.Sorensen@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Jes Sorensen , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 04/17] vl.c: Move host_main_loop_wait() to OS specific files. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jes Sorensen Move host_main_loop_wait() to OS specific files. Create qemu-os-posix.h and provide empty inline for the POSIX case. Signed-off-by: Jes Sorensen --- os-win32.c | 43 +++++++++++++++++++++++++++++++++++++++++++ qemu-os-posix.h | 33 +++++++++++++++++++++++++++++++++ qemu-os-win32.h | 1 + sysemu.h | 4 ++++ vl.c | 52 +--------------------------------------------------- 5 files changed, 82 insertions(+), 51 deletions(-) create mode 100644 qemu-os-posix.h diff --git a/os-win32.c b/os-win32.c index 5a464cc..1f7e28b 100644 --- a/os-win32.c +++ b/os-win32.c @@ -109,3 +109,46 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) if (found) w->num--; } + +void os_host_main_loop_wait(int *timeout) +{ + int ret, ret2, i; + PollingEntry *pe; + + /* XXX: need to suppress polling by better using win32 events */ + ret = 0; + for(pe = first_polling_entry; pe != NULL; pe = pe->next) { + ret |= pe->func(pe->opaque); + } + if (ret == 0) { + int err; + WaitObjects *w = &wait_objects; + + ret = WaitForMultipleObjects(w->num, w->events, FALSE, *timeout); + if (WAIT_OBJECT_0 + 0 <= ret && ret <= WAIT_OBJECT_0 + w->num - 1) { + if (w->func[ret - WAIT_OBJECT_0]) + w->func[ret - WAIT_OBJECT_0](w->opaque[ret - WAIT_OBJECT_0]); + + /* Check for additional signaled events */ + for(i = (ret - WAIT_OBJECT_0 + 1); i < w->num; i++) { + + /* Check if event is signaled */ + ret2 = WaitForSingleObject(w->events[i], 0); + if(ret2 == WAIT_OBJECT_0) { + if (w->func[i]) + w->func[i](w->opaque[i]); + } else if (ret2 == WAIT_TIMEOUT) { + } else { + err = GetLastError(); + fprintf(stderr, "WaitForSingleObject error %d %d\n", i, err); + } + } + } else if (ret == WAIT_TIMEOUT) { + } else { + err = GetLastError(); + fprintf(stderr, "WaitForMultipleObjects error %d %d\n", ret, err); + } + } + + *timeout = 0; +} diff --git a/qemu-os-posix.h b/qemu-os-posix.h new file mode 100644 index 0000000..96d1036 --- /dev/null +++ b/qemu-os-posix.h @@ -0,0 +1,33 @@ +/* + * posix specific declarations + * + * Copyright (c) 2003-2008 Fabrice Bellard + * Copyright (c) 2010 Jes Sorensen + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef QEMU_OS_POSIX_H +#define QEMU_OS_POSIX_H + +static inline void os_host_main_loop_wait(int *timeout) +{ +} + +#endif diff --git a/qemu-os-win32.h b/qemu-os-win32.h index be108ad..4d1cac8 100644 --- a/qemu-os-win32.h +++ b/qemu-os-win32.h @@ -40,4 +40,5 @@ typedef void WaitObjectFunc(void *opaque); int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque); void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque); +void os_host_main_loop_wait(int *timeout); #endif diff --git a/sysemu.h b/sysemu.h index 13fc9a9..5e4feae 100644 --- a/sysemu.h +++ b/sysemu.h @@ -12,6 +12,10 @@ #include "qemu-os-win32.h" #endif +#ifdef CONFIG_POSIX +#include "qemu-os-posix.h" +#endif + /* vl.c */ extern const char *bios_name; diff --git a/vl.c b/vl.c index afbb26c..c655582 100644 --- a/vl.c +++ b/vl.c @@ -1722,56 +1722,6 @@ void qemu_system_powerdown_request(void) qemu_notify_event(); } -#ifdef _WIN32 -static void host_main_loop_wait(int *timeout) -{ - int ret, ret2, i; - PollingEntry *pe; - - - /* XXX: need to suppress polling by better using win32 events */ - ret = 0; - for(pe = first_polling_entry; pe != NULL; pe = pe->next) { - ret |= pe->func(pe->opaque); - } - if (ret == 0) { - int err; - WaitObjects *w = &wait_objects; - - ret = WaitForMultipleObjects(w->num, w->events, FALSE, *timeout); - if (WAIT_OBJECT_0 + 0 <= ret && ret <= WAIT_OBJECT_0 + w->num - 1) { - if (w->func[ret - WAIT_OBJECT_0]) - w->func[ret - WAIT_OBJECT_0](w->opaque[ret - WAIT_OBJECT_0]); - - /* Check for additional signaled events */ - for(i = (ret - WAIT_OBJECT_0 + 1); i < w->num; i++) { - - /* Check if event is signaled */ - ret2 = WaitForSingleObject(w->events[i], 0); - if(ret2 == WAIT_OBJECT_0) { - if (w->func[i]) - w->func[i](w->opaque[i]); - } else if (ret2 == WAIT_TIMEOUT) { - } else { - err = GetLastError(); - fprintf(stderr, "WaitForSingleObject error %d %d\n", i, err); - } - } - } else if (ret == WAIT_TIMEOUT) { - } else { - err = GetLastError(); - fprintf(stderr, "WaitForMultipleObjects error %d %d\n", ret, err); - } - } - - *timeout = 0; -} -#else -static void host_main_loop_wait(int *timeout) -{ -} -#endif - void main_loop_wait(int nonblocking) { IOHandlerRecord *ioh; @@ -1787,7 +1737,7 @@ void main_loop_wait(int nonblocking) qemu_bh_update_timeout(&timeout); } - host_main_loop_wait(&timeout); + os_host_main_loop_wait(&timeout); /* poll any events */ /* XXX: separate device handlers from system ones */