From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: sw@weilnetz.de
Subject: [Qemu-devel] [PATCH 5/6] main-loop: replace WaitForMultipleObjects with g_poll
Date: Tue, 20 Mar 2012 10:49:20 +0100 [thread overview]
Message-ID: <1332236961-22743-6-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1332236961-22743-1-git-send-email-pbonzini@redhat.com>
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 <pbonzini@redhat.com>
---
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.
--
1.7.7.6
next prev parent reply other threads:[~2012-03-20 9:49 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 ` [Qemu-devel] [PATCH 2/6] main loop: use msec-based timeout in glib_select_fill Paolo Bonzini
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 ` Paolo Bonzini [this message]
2012-04-04 20:44 ` [Qemu-devel] [PATCH 5/6] main-loop: replace WaitForMultipleObjects with g_poll 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-6-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).