From patchwork Tue Aug 7 11:17:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 175600 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 7BBA22C0084 for ; Tue, 7 Aug 2012 21:18:15 +1000 (EST) Received: from localhost ([::1]:33920 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Syhnh-0001R4-DZ for incoming@patchwork.ozlabs.org; Tue, 07 Aug 2012 07:18:13 -0400 Received: from eggs.gnu.org ([208.118.235.92]:56312) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SyhnP-0001HX-Ai for qemu-devel@nongnu.org; Tue, 07 Aug 2012 07:17:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SyhnK-0006aU-TB for qemu-devel@nongnu.org; Tue, 07 Aug 2012 07:17:55 -0400 Received: from mail-gh0-f173.google.com ([209.85.160.173]:53768) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SyhnK-0006Z2-PD for qemu-devel@nongnu.org; Tue, 07 Aug 2012 07:17:50 -0400 Received: by mail-gh0-f173.google.com with SMTP id r17so1872154ghr.4 for ; Tue, 07 Aug 2012 04:17:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=UX68aaZUUxmANjyVQX1u/BQm3TCK9CYqAXbQgRS2EVI=; b=wwiUQxQT4yS3RvM8z06/5z4/qqJ2QBujyFlNVXEmZ3INx+6QCS73uXqchvWGwwY6Jy Mq2LmcTWXL/iexMDRMZ6RkqahtJW+sfHWQTKMa5ynI2BokAdkS4vVaDnTVx6LRLbqOvh dnz6K2tKRUpImACDJcHQldHaPojpB/YN+g1qwUGyodNaa1VWUO9Mu5EynFOEBu0EeKRS 2vow/K3p733oPkPH/SdX7WsywTDysQd91flvmaBhoc5WDuljgg0PlyNV9bjIcnvLbsFu f7nt2eQI5//4ZVs/m7wxYhAv2xDl3su6mRZOxFe9+z+3P7hsfvvpRxr6TAY4+aFaSwpg jdvw== Received: by 10.66.73.69 with SMTP id j5mr25355808pav.8.1344338270287; Tue, 07 Aug 2012 04:17:50 -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 pq1sm11008602pbb.3.2012.08.07.04.17.46 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 07 Aug 2012 04:17:49 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 7 Aug 2012 13:17:17 +0200 Message-Id: <1344338247-17567-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.11.2 In-Reply-To: <1344338247-17567-1-git-send-email-pbonzini@redhat.com> References: <1344338247-17567-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.173 Cc: aliguori@linux.vnet.ibm.com, stefanha@linux.vnet.ibm.com, sw@weilnetz.de Subject: [Qemu-devel] [PATCH v2 02/12] 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-win32.c | 59 ++++++++++++++++++++++++++++++ event_notifier.h | 17 ++++++++- 4 file modificati, 77 inserzioni(+), 3 rimozioni(-) rename event_notifier.c => event_notifier-posix.c (100%) create mode 100644 event_notifier-win32.c diff --git a/Makefile.objs b/Makefile.objs index 5ebbcfa..2d9d0ce 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -45,6 +45,8 @@ block-obj-y = cutils.o iov.o cache-utils.o qemu-option.o module.o async.o block-obj-y += nbd.o block.o aio.o aes.o qemu-config.o qemu-progress.o qemu-sockets.o block-obj-y += $(coroutine-obj-y) $(qobject-obj-y) $(version-obj-y) block-obj-$(CONFIG_POSIX) += posix-aio-compat.o +block-obj-$(CONFIG_POSIX) += event_notifier-posix.o +block-obj-$(CONFIG_WIN32) += event_notifier-win32.o block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o block-obj-y += block/ @@ -90,7 +92,7 @@ common-obj-y += bt-host.o bt-vhci.o common-obj-y += iov.o acl.o common-obj-$(CONFIG_POSIX) += compatfd.o -common-obj-y += notify.o event_notifier.o +common-obj-y += notify.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% rename from event_notifier.c rename to event_notifier-posix.c diff --git a/event_notifier-win32.c b/event_notifier-win32.c new file mode 100644 index 0000000..c723dad --- /dev/null +++ b/event_notifier-win32.c @@ -0,0 +1,59 @@ +/* + * event notifier support + * + * Copyright Red Hat, Inc. 2010 + * + * Authors: + * Michael S. Tsirkin + * + * 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; +} 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