Patchwork [7/8] add Win32 implementation of event notifiers

login
register
mail settings
Submitter Paolo Bonzini
Date May 26, 2010, 2:09 p.m.
Message ID <1274882978-9875-8-git-send-email-pbonzini@redhat.com>
Download mbox | patch
Permalink /patch/53621/
State New
Headers show

Comments

Paolo Bonzini - May 26, 2010, 2:09 p.m.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
        Compile-tested only.  iothread is broken anyway on Win32
        due to missing implementation of qemu-threads.

 event_notifier.c |   33 +++++++++++++++++++++++++++++++++
 event_notifier.h |    8 ++++++++
 2 files changed, 41 insertions(+), 0 deletions(-)

Patch

diff --git a/event_notifier.c b/event_notifier.c
index a33f3c5..0705dc5 100644
--- a/event_notifier.c
+++ b/event_notifier.c
@@ -11,11 +11,13 @@ 
  */
 
 #include "qemu-common.h"
+#include "sysemu.h"
 #include "event_notifier.h"
 #include "qemu-char.h"
 
 int event_notifier_init(EventNotifier *e, int active)
 {
+#ifndef _WIN32
     int fds[2];
     int err;
     if (qemu_eventfd (fds) < 0)
@@ -39,27 +41,50 @@  fail:
     close(fds[0]);
     close(fds[1]);
     return err;
+#else
+    e->event = CreateEvent(NULL, FALSE, FALSE, NULL);
+    assert(e->event);
+    return 0;
+#endif
 }
 
 void event_notifier_cleanup(EventNotifier *e)
 {
+#ifndef _WIN32
     close(e->rfd);
     close(e->wfd);
+#else
+    CloseHandle(e->event);
+#endif
 }
 
 int event_notifier_get_fd(EventNotifier *e)
 {
+#ifndef _WIN32
     return e->wfd;
+#else
+    abort();
+#endif
 }
 
 int event_notifier_set_handler(EventNotifier *e,
                                EventNotifierHandler *handler)
 {
+#ifndef _WIN32
     return qemu_set_fd_handler(e->rfd, (IOHandler *)handler, NULL, e);
+#else
+    if (handler) {
+        return qemu_add_wait_object(e->event, (IOHandler *)handler, e);
+    } else {
+        qemu_del_wait_object(e->event, (IOHandler *)handler, e);
+        return 0;
+    }
+#endif
 }
 
 int event_notifier_set(EventNotifier *e)
 {
+#ifndef _WIN32
     static const uint64_t value = 1;
     ssize_t ret;
 
@@ -72,10 +97,15 @@  int event_notifier_set(EventNotifier *e)
         return -1;
     }
     return 0;
+#else
+    SetEvent(e->event);
+    return 0;
+#endif
 }
 
 int event_notifier_test_and_clear(EventNotifier *e)
 {
+#ifndef _WIN32
     int value;
     ssize_t len;
     char buffer[512];
@@ -88,4 +118,7 @@  int event_notifier_test_and_clear(EventNotifier *e)
     } while ((len == -1 && errno == EINTR) || len == sizeof(buffer));
 
     return value;
+#else
+    return WaitForSingleObject(e->event, 0) == WAIT_OBJECT_0;
+#endif
 }
diff --git a/event_notifier.h b/event_notifier.h
index ff9d6f2..f3c272a 100644
--- a/event_notifier.h
+++ b/event_notifier.h
@@ -3,9 +3,17 @@ 
 
 #include "qemu-common.h"
 
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
 struct EventNotifier {
+#ifdef _WIN32
+    HANDLE event;
+#else
     int rfd;
     int wfd;
+#endif
 };
 
 typedef void EventNotifierHandler(EventNotifier *);