From patchwork Wed May 26 14:09:37 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 53621 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3D95AB7D16 for ; Thu, 27 May 2010 00:52:43 +1000 (EST) Received: from localhost ([127.0.0.1]:39865 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OHHyH-0006nO-Az for incoming@patchwork.ozlabs.org; Wed, 26 May 2010 10:52:37 -0400 Received: from [140.186.70.92] (port=45505 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OHHN6-0003N8-3j for qemu-devel@nongnu.org; Wed, 26 May 2010 10:14:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OHHJ3-00048M-QZ for qemu-devel@nongnu.org; Wed, 26 May 2010 10:10:07 -0400 Received: from mail-wy0-f173.google.com ([74.125.82.173]:38260) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OHHJ3-00046k-L3 for qemu-devel@nongnu.org; Wed, 26 May 2010 10:10:01 -0400 Received: by mail-wy0-f173.google.com with SMTP id 28so1007524wyf.4 for ; Wed, 26 May 2010 07:10:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:from:to:subject:date :message-id:x-mailer:in-reply-to:references; bh=rhDfKmSIlCuTcBx3EwV3xHpMDWQ5JzjlXbF67N4gJTk=; b=hMziV+cQSVffL1456m7caBgP5osK+M0Wy4JwWaq9ysP7HW2WkATqzMaPSe+97duwX0 zIU7Avr57H5S6NkQ+liFH2nVDIJSr9kG9R5x/RNMcAXcQgqUgocQfKNeNSxo2DhWMJca aOrX1XfSG9QrDB0djWJq4smolUtUOCmvU/FNI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; b=ZTsE7rELSnMk5otuxnorVHm/mwTgp+DC2kLCfZuysrolQF7JVcY/iPeSooSG6X53vm bA4WFBYTFqMxIO1OR7eiojr75rok1FF3YkT9UAbmmilrO1vUaz6M2jCAPz3ngG0SrvBw xa6XOE7W1OdblT9o3hOjPVUjLO6S0iVV/j76E= Received: by 10.227.133.132 with SMTP id f4mr8541017wbt.189.1274883001242; Wed, 26 May 2010 07:10:01 -0700 (PDT) Received: from localhost.localdomain (nat-pool-brq-t.redhat.com [209.132.186.34]) by mx.google.com with ESMTPS id u32sm318964wbc.11.2010.05.26.07.09.59 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 26 May 2010 07:10:00 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 26 May 2010 16:09:37 +0200 Message-Id: <1274882978-9875-8-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: <1274882978-9875-1-git-send-email-pbonzini@redhat.com> References: <1274882978-9875-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH 7/8] add Win32 implementation of event notifiers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Paolo Bonzini --- 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(-) 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 +#endif + struct EventNotifier { +#ifdef _WIN32 + HANDLE event; +#else int rfd; int wfd; +#endif }; typedef void EventNotifierHandler(EventNotifier *);