aboutsummaryrefslogtreecommitdiff
path: root/vl.c
diff options
context:
space:
mode:
Diffstat (limited to 'vl.c')
-rw-r--r--vl.c74
1 files changed, 58 insertions, 16 deletions
diff --git a/vl.c b/vl.c
index 9f7143cd83..118a1e2119 100644
--- a/vl.c
+++ b/vl.c
@@ -1014,7 +1014,7 @@ static void init_timers(void)
perror("failed CreateEvent");
exit(1);
}
- ResetEvent(host_alarm);
+ qemu_add_wait_object(host_alarm, NULL, NULL);
}
pit_min_timer_count = ((uint64_t)10000 * PIT_FREQ) / 1000000;
#else
@@ -3962,6 +3962,51 @@ void qemu_del_polling_cb(PollingFunc *func, void *opaque)
}
}
+#ifdef _WIN32
+/***********************************************************/
+/* Wait objects support */
+typedef struct WaitObjects {
+ int num;
+ HANDLE events[MAXIMUM_WAIT_OBJECTS + 1];
+ WaitObjectFunc *func[MAXIMUM_WAIT_OBJECTS + 1];
+ void *opaque[MAXIMUM_WAIT_OBJECTS + 1];
+} WaitObjects;
+
+static WaitObjects wait_objects = {0};
+
+int qemu_add_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
+{
+ WaitObjects *w = &wait_objects;
+
+ if (w->num >= MAXIMUM_WAIT_OBJECTS)
+ return -1;
+ w->events[w->num] = handle;
+ w->func[w->num] = func;
+ w->opaque[w->num] = opaque;
+ w->num++;
+ return 0;
+}
+
+void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque)
+{
+ int i, found;
+ WaitObjects *w = &wait_objects;
+
+ found = 0;
+ for (i = 0; i < w->num; i++) {
+ if (w->events[i] == handle)
+ found = 1;
+ if (found) {
+ w->events[i] = w->events[i + 1];
+ w->func[i] = w->func[i + 1];
+ w->opaque[i] = w->opaque[i + 1];
+ }
+ }
+ if (found)
+ w->num--;
+}
+#endif
+
/***********************************************************/
/* savevm/loadvm support */
@@ -4838,21 +4883,18 @@ void main_loop_wait(int timeout)
}
#ifdef _WIN32
if (ret == 0 && timeout > 0) {
- int err;
- HANDLE hEvents[1];
-
- hEvents[0] = host_alarm;
- ret = WaitForMultipleObjects(1, hEvents, FALSE, timeout);
- switch(ret) {
- case WAIT_OBJECT_0 + 0:
- break;
- case WAIT_TIMEOUT:
- break;
- default:
- err = GetLastError();
- fprintf(stderr, "Wait error %d %d\n", ret, err);
- break;
- }
+ 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]);
+ } else if (ret == WAIT_TIMEOUT) {
+ } else {
+ err = GetLastError();
+ fprintf(stderr, "Wait error %d %d\n", ret, err);
+ }
}
#endif
/* poll any events */