event_notifier: add Win32 implementation

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2010-05-24 17:26:13 +02:00
parent 136594f19a
commit fc97a652de
5 changed files with 76 additions and 4 deletions

View File

@ -94,7 +94,8 @@ common-obj-y += bt-host.o bt-vhci.o
common-obj-y += dma-helpers.o
common-obj-y += acl.o
common-obj-$(CONFIG_POSIX) += compatfd.o
common-obj-y += event_notifier.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-y += qtest.o
common-obj-y += vl.o

59
event_notifier-win32.c Normal file
View File

@ -0,0 +1,59 @@
/*
* event notifier support
*
* Copyright Red Hat, Inc. 2010
*
* Authors:
* Michael S. Tsirkin <mst@redhat.com>
*
* This work is licensed under the terms of the GNU GPL, version 2 or later.
* See the COPYING file in the top-level directory.
*/
#include "qemu-common.h"
#include "event_notifier.h"
#include "main-loop.h"
int event_notifier_init(EventNotifier *e, int active)
{
e->event = CreateEvent(NULL, FALSE, FALSE, NULL);
assert(e->event);
return 0;
}
void event_notifier_cleanup(EventNotifier *e)
{
CloseHandle(e->event);
}
HANDLE event_notifier_get_handle(EventNotifier *e)
{
return e->event;
}
int event_notifier_set_handler(EventNotifier *e,
EventNotifierHandler *handler)
{
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)
{
SetEvent(e->event);
return 0;
}
int event_notifier_test_and_clear(EventNotifier *e)
{
int ret = WaitForSingleObject(e->event, 0);
if (ret == WAIT_OBJECT_0) {
ResetEvent(e->event);
return true;
}
return false;
}

View File

@ -15,18 +15,31 @@
#include "qemu-common.h"
#ifdef _WIN32
#include <windows.h>
#endif
struct EventNotifier {
#ifdef _WIN32
HANDLE event;
#else
int fd;
#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

View File

@ -28,7 +28,6 @@
#include <windows.h>
#include <winsock2.h>
#include "main-loop.h"
/* Workaround for older versions of MinGW. */
#ifndef ECONNREFUSED