From patchwork Tue Sep 25 12:55:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 186804 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5C7062C008A for ; Tue, 25 Sep 2012 22:56:47 +1000 (EST) Received: from localhost ([::1]:60825 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGUgv-00031C-DQ for incoming@patchwork.ozlabs.org; Tue, 25 Sep 2012 08:56:45 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48530) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGUgf-0002nv-9r for qemu-devel@nongnu.org; Tue, 25 Sep 2012 08:56:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TGUgb-00010n-1J for qemu-devel@nongnu.org; Tue, 25 Sep 2012 08:56:29 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:65329) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGUga-0000zu-QD for qemu-devel@nongnu.org; Tue, 25 Sep 2012 08:56:24 -0400 Received: by mail-pb0-f45.google.com with SMTP id rp2so67620pbb.4 for ; Tue, 25 Sep 2012 05:56:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=MuIRlGeVCHaKiUH1aZY0VNUe5CXnT5x9mQVBxXni2TE=; b=x7xDU0i4WbON6b6rcMvDR6jJvCoMwPbKOnjg/aCaluu/HP4fV8jZLKzVQldtnbHNEE G7GahAQ5c7cNFe/EDtLVNW3mKu21amCHUlfuk93l9H4FndApXoALOOMLtXXrh5HSgh+Q ubjqBo90GuJaXLKOdP7D4zq+MB8K9feDq+tuAqDnW5kh3Fk6hvbMavV7Mfe3H0EKWqN4 RHd/UrIdH5mqDNvVYk2l1+h/qMlqwcO4RdM7+Qc7pP56Suf7+Dv/QTAjahAEW68ZN4gS AQJAYNWLvS+4VHWoPFLAUR+PUBV4SyS+kuwIp8C/E9Y2vWsdfK78UvTs2HoiDXi68mO3 cfPA== Received: by 10.68.242.97 with SMTP id wp1mr46218900pbc.159.1348577784304; Tue, 25 Sep 2012 05:56:24 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-169-1.ip50.fastwebnet.it. [93.34.169.1]) by mx.google.com with ESMTPS id py9sm309335pbb.20.2012.09.25.05.56.21 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 25 Sep 2012 05:56:23 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 25 Sep 2012 14:55:49 +0200 Message-Id: <1348577763-12920-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.12 In-Reply-To: <1348577763-12920-1-git-send-email-pbonzini@redhat.com> References: <1348577763-12920-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Subject: [Qemu-devel] [PATCH 03/17] event_notifier: add Win32 implementation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Paolo Bonzini --- 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 -#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 +#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 #include -#include "main-loop.h" /* Workaround for older versions of MinGW. */ #ifndef ECONNREFUSED