From patchwork Tue Mar 20 09:49:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 147773 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 1978AB6EEF for ; Tue, 20 Mar 2012 20:50:09 +1100 (EST) Received: from localhost ([::1]:54640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9vhf-00017m-1V for incoming@patchwork.ozlabs.org; Tue, 20 Mar 2012 05:50:07 -0400 Received: from eggs.gnu.org ([208.118.235.92]:39726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9vhQ-0000lj-00 for qemu-devel@nongnu.org; Tue, 20 Mar 2012 05:49:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S9vhN-00046m-Sr for qemu-devel@nongnu.org; Tue, 20 Mar 2012 05:49:51 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:50685) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S9vhN-00046Y-Jh for qemu-devel@nongnu.org; Tue, 20 Mar 2012 05:49:49 -0400 Received: by pbcuo5 with SMTP id uo5so1980552pbc.4 for ; Tue, 20 Mar 2012 02:49:47 -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=ZZFvafvc1sVRgRpKGBFX1MimZHugVEre+qG9wJB6GSo=; b=RE2q69hvP1sRTZ3xMx7IvqGuw9o2LCC4tS4y2AhBSt2earIcGxi7WIJ7o+hNMClZ9a /NWT8Qlrv2kXLgNN6OxrUoh53jBrYQ/udK1UhBsSe0h2YcfovwtaVUhEjdFK4GZXO7qn Z2T7A1hy/xNCmtc5iEABt4lSHphVnmCD5ZnAqCJLtT2+C/8LFIUIDsDnh9tqFuCVDfcN rCOE1ang/82XRUP6GhAGhtnhMyqxSj8PS+A8WPq3fyVb2iAd+FFtdXu8i4eR2k2CQgIc PwDdL8Bw5VneMx1iYw8ntViiDDwhVnD6QvnIaOfVb92Lpv50Fsa8IW4uX8KuefPjO6fE rMuw== Received: by 10.68.130.232 with SMTP id oh8mr3955405pbb.161.1332236987343; Tue, 20 Mar 2012 02:49:47 -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.44 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 20 Mar 2012 02:49:46 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 20 Mar 2012 10:49:20 +0100 Message-Id: <1332236961-22743-6-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.160.45 Cc: sw@weilnetz.de Subject: [Qemu-devel] [PATCH 5/6] main-loop: replace WaitForMultipleObjects with g_poll 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 On w32, glib implements g_poll using WaitForMultipleObjects or MsgWaitForMultipleObjects. This means that we can simplify our code by switching to g_poll, and at the same time prepare for adding back glib sources. Signed-off-by: Paolo Bonzini --- main-loop.c | 40 +++++++++++++++++----------------------- 1 files changed, 17 insertions(+), 23 deletions(-) diff --git a/main-loop.c b/main-loop.c index 7364074..4d02568 100644 --- a/main-loop.c +++ b/main-loop.c @@ -220,9 +220,9 @@ int main_loop_init(void) static fd_set rfds, wfds, xfds; static int nfds; +static GPollFD poll_fds[1024 * 2]; /* this is probably overkill */ #ifndef _WIN32 -static GPollFD poll_fds[1024 * 2]; /* this is probably overkill */ static int n_poll_fds; static int max_priority; @@ -351,6 +351,7 @@ void qemu_del_polling_cb(PollingFunc *func, void *opaque) /* Wait objects support */ typedef struct WaitObjects { int num; + int revents[MAXIMUM_WAIT_OBJECTS + 1]; HANDLE events[MAXIMUM_WAIT_OBJECTS + 1]; WaitObjectFunc *func[MAXIMUM_WAIT_OBJECTS + 1]; void *opaque[MAXIMUM_WAIT_OBJECTS + 1]; @@ -367,6 +368,7 @@ int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) w->events[w->num] = handle; w->func[w->num] = func; w->opaque[w->num] = opaque; + w->revents[w->num] = 0; w->num++; return 0; } @@ -385,6 +387,7 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque) w->events[i] = w->events[i + 1]; w->func[i] = w->func[i + 1]; w->opaque[i] = w->opaque[i + 1]; + w->revents[i] = w->revents[i + 1]; } } if (found) { @@ -400,9 +403,8 @@ void qemu_fd_register(int fd) static int os_host_main_loop_wait(int timeout) { - int ret, ret2, i; + int ret, i; PollingEntry *pe; - int err; WaitObjects *w = &wait_objects; static struct timeval tv0; @@ -422,33 +424,25 @@ static int os_host_main_loop_wait(int timeout) } } + for (i = 0; i < w->num; i++) { + poll_fds[i].fd = (DWORD) w->events[i]; + poll_fds[i].events = G_IO_IN; + } + qemu_mutex_unlock_iothread(); - ret = WaitForMultipleObjects(w->num, w->events, FALSE, timeout); + ret = g_poll(poll_fds, w->num, 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]) { - w->func[ret - WAIT_OBJECT_0](w->opaque[ret - WAIT_OBJECT_0]); + if (ret > 0) { + for (i = 0; i < w->num; i++) { + w->revents[i] = poll_fds[i].revents; } - - /* 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) { - err = GetLastError(); - fprintf(stderr, "WaitForSingleObject error %d %d\n", i, err); + for (i = 0; i < w->num; i++) { + if (w->revents[i] && w->func[i]) { + w->func[i](w->opaque[i]); } } - } else if (ret != WAIT_TIMEOUT) { - err = GetLastError(); - fprintf(stderr, "WaitForMultipleObjects error %d %d\n", ret, err); } - /* If an edge-triggered socket event occurred, select will return a * positive result on the next iteration. We do not need to do anything * here.