[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 03/17] event_notifier: add Win32 implementation
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PATCH 03/17] event_notifier: add Win32 implementation |
Date: |
Tue, 25 Sep 2012 14:55:49 +0200 |
Signed-off-by: Paolo Bonzini <address@hidden>
---
Makefile.objs | 4 +-
event_notifier.c => event_notifier-posix.c | 0
event_notifier.c => event_notifier-win32.c | 97 ++++++------------------------
event_notifier.h | 17 +++++-
qemu-os-win32.h | 1 -
5 file modificati, 37 inserzioni(+), 82 rimozioni(-)
copy event_notifier.c => event_notifier-posix.c (100%)
rename event_notifier.c => event_notifier-win32.c (29%)
diff --git a/Makefile.objs b/Makefile.objs
index cf00fd5..a99378c 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -91,7 +91,9 @@ common-obj-y += bt-host.o bt-vhci.o
common-obj-y += acl.o
common-obj-$(CONFIG_POSIX) += compatfd.o
-common-obj-y += notify.o event_notifier.o
+common-obj-y += notify.o
+common-obj-$(CONFIG_POSIX) += event_notifier-posix.o
+common-obj-$(CONFIG_WIN32) += event_notifier-win32.o
common-obj-y += qemu-timer.o qemu-timer-common.o
common-obj-$(CONFIG_SLIRP) += slirp/
diff --git a/event_notifier.c b/event_notifier-posix.c
similarity index 100%
copy from event_notifier.c
copy to event_notifier-posix.c
diff --git a/event_notifier.c b/event_notifier-win32.c
similarity index 29%
rename from event_notifier.c
rename to event_notifier-win32.c
index 88c114b..c723dad 100644
--- a/event_notifier.c
+++ b/event_notifier-win32.c
@@ -12,107 +12,48 @@
#include "qemu-common.h"
#include "event_notifier.h"
-#include "qemu-char.h"
-
-#ifdef CONFIG_EVENTFD
-#include <sys/eventfd.h>
-#endif
-
-void event_notifier_init_fd(EventNotifier *e, int fd)
-{
- e->rfd = fd;
- e->wfd = fd;
-}
+#include "main-loop.h"
int event_notifier_init(EventNotifier *e, int active)
{
- int fds[2];
- int ret;
-
-#ifdef CONFIG_EVENTFD
- ret = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
-#else
- ret = -1;
- errno = ENOSYS;
-#endif
- if (ret >= 0) {
- e->rfd = e->wfd = ret;
- } else {
- if (errno != ENOSYS) {
- return -errno;
- }
- if (qemu_pipe(fds) < 0) {
- return -errno;
- }
- ret = fcntl_setfl(fds[0], O_NONBLOCK);
- if (ret < 0) {
- goto fail;
- }
- ret = fcntl_setfl(fds[1], O_NONBLOCK);
- if (ret < 0) {
- goto fail;
- }
- e->rfd = fds[0];
- e->wfd = fds[1];
- }
- if (active) {
- event_notifier_set(e);
- }
+ e->event = CreateEvent(NULL, FALSE, FALSE, NULL);
+ assert(e->event);
return 0;
-
-fail:
- close(fds[0]);
- close(fds[1]);
- return ret;
}
void event_notifier_cleanup(EventNotifier *e)
{
- if (e->rfd != e->wfd) {
- close(e->rfd);
- }
- close(e->wfd);
+ CloseHandle(e->event);
}
-int event_notifier_get_fd(EventNotifier *e)
+HANDLE event_notifier_get_handle(EventNotifier *e)
{
- return e->rfd;
+ return e->event;
}
int event_notifier_set_handler(EventNotifier *e,
EventNotifierHandler *handler)
{
- return qemu_set_fd_handler(e->rfd, (IOHandler *)handler, NULL, e);
+ if (handler) {
+ return qemu_add_wait_object(e->event, (IOHandler *)handler, e);
+ } else {
+ qemu_del_wait_object(e->event, (IOHandler *)handler, e);
+ return 0;
+ }
}
int event_notifier_set(EventNotifier *e)
{
- static const uint64_t value = 1;
- ssize_t ret;
-
- do {
- ret = write(e->wfd, &value, sizeof(value));
- } while (ret < 0 && errno == EINTR);
-
- /* EAGAIN is fine, a read must be pending. */
- if (ret < 0 && errno != EAGAIN) {
- return -1;
- }
+ SetEvent(e->event);
return 0;
}
int event_notifier_test_and_clear(EventNotifier *e)
{
- int value;
- ssize_t len;
- char buffer[512];
-
- /* Drain the notify pipe. For eventfd, only 8 bytes will be read. */
- value = 0;
- do {
- len = read(e->rfd, buffer, sizeof(buffer));
- value |= (len > 0);
- } while ((len == -1 && errno == EINTR) || len == sizeof(buffer));
-
- return value;
+ int ret = WaitForSingleObject(e->event, 0);
+ if (ret == WAIT_OBJECT_0) {
+ ResetEvent(e->event);
+ return true;
+ }
+ return false;
}
diff --git a/event_notifier.h b/event_notifier.h
index f04d12d..88b57af 100644
--- a/event_notifier.h
+++ b/event_notifier.h
@@ -15,19 +15,32 @@
#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 *);
-void event_notifier_init_fd(EventNotifier *, int fd);
int event_notifier_init(EventNotifier *, int active);
void event_notifier_cleanup(EventNotifier *);
-int event_notifier_get_fd(EventNotifier *);
int event_notifier_set(EventNotifier *);
int event_notifier_test_and_clear(EventNotifier *);
int event_notifier_set_handler(EventNotifier *, EventNotifierHandler *);
+#ifdef CONFIG_POSIX
+void event_notifier_init_fd(EventNotifier *, int fd);
+int event_notifier_get_fd(EventNotifier *);
+#else
+HANDLE event_notifier_get_handle(EventNotifier *);
+#endif
+
#endif
diff --git a/qemu-os-win32.h b/qemu-os-win32.h
index 3b5a35b..400264e 100644
--- a/qemu-os-win32.h
+++ b/qemu-os-win32.h
@@ -28,7 +28,6 @@
#include <windows.h>
#include <winsock2.h>
-#include "main-loop.h"
/* Workaround for older versions of MinGW. */
#ifndef ECONNREFUSED
--
1.7.12
- [Qemu-devel] [RFC PATCH 00/17] Support for multiple "AIO contexts", Paolo Bonzini, 2012/09/25
- [Qemu-devel] [PATCH 01/17] build: do not rely on indirect inclusion of qemu-config.h, Paolo Bonzini, 2012/09/25
- [Qemu-devel] [PATCH 03/17] event_notifier: add Win32 implementation,
Paolo Bonzini <=
- [Qemu-devel] [PATCH 02/17] event_notifier: enable it to use pipes, Paolo Bonzini, 2012/09/25
- [Qemu-devel] [PATCH 04/17] aio: change qemu_aio_set_fd_handler to return void, Paolo Bonzini, 2012/09/25
- [Qemu-devel] [PATCH 06/17] aio: introduce AioContext, move bottom halves there, Paolo Bonzini, 2012/09/25
- [Qemu-devel] [PATCH 05/17] aio: provide platform-independent API, Paolo Bonzini, 2012/09/25
- [Qemu-devel] [PATCH 07/17] aio: add I/O handlers to the AioContext interface, Paolo Bonzini, 2012/09/25
- [Qemu-devel] [PATCH 08/17] aio: add non-blocking variant of aio_wait, Paolo Bonzini, 2012/09/25