From patchwork Tue Nov 2 11:56:59 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 69881 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 57F2D1007D4 for ; Wed, 3 Nov 2010 00:49:17 +1100 (EST) Received: from localhost ([127.0.0.1]:45816 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDHE4-0008T0-Co for incoming@patchwork.ozlabs.org; Tue, 02 Nov 2010 09:48:36 -0400 Received: from [140.186.70.92] (port=34545 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDGw2-0003oe-By for qemu-devel@nongnu.org; Tue, 02 Nov 2010 09:30:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PDFU8-0004vl-V1 for qemu-devel@nongnu.org; Tue, 02 Nov 2010 07:57:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29844) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PDFU8-0004vO-Me for qemu-devel@nongnu.org; Tue, 02 Nov 2010 07:57:04 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oA2Bv3qi021213 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 2 Nov 2010 07:57:03 -0400 Received: from rincewind.home.kraxel.org (vpn1-4-20.ams2.redhat.com [10.36.4.20]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oA2Bv1gO012849; Tue, 2 Nov 2010 07:57:01 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 087944581F; Tue, 2 Nov 2010 12:56:59 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 2 Nov 2010 12:56:59 +0100 Message-Id: <1288699019-18711-4-git-send-email-kraxel@redhat.com> In-Reply-To: <1288699019-18711-1-git-send-email-kraxel@redhat.com> References: <1288699019-18711-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 3/3] spice-display: replace private lock with qemu mutex. 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 qemu_spice_create_update() must aquire the global qemu mutex to make sure DisplayState doesn't change while we are accessing it. Once this is in place the private lock is pretty pointless as everything it protects is covered by the global qemu mutex now. Drop it. Signed-off-by: Gerd Hoffmann --- ui/spice-display.c | 27 ++++++++++++++------------- ui/spice-display.h | 1 - 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ui/spice-display.c b/ui/spice-display.c index 7b4f5c1..020b423 100644 --- a/ui/spice-display.c +++ b/ui/spice-display.c @@ -64,10 +64,10 @@ void qemu_spice_rect_union(QXLRect *dest, const QXLRect *r) /* * Called from spice server thread context (via interface_get_command). - * We do *not* hold the global qemu mutex here, so extra care is needed - * when calling qemu functions. Qemu interfaces used: - * - pflib (is re-entrant). - * - qemu_malloc (underlying glibc malloc is re-entrant). + * + * We must aquire the global qemu mutex here to make sure the + * DisplayState (+DisplaySurface) we are accessing doesn't change + * underneath us. */ SimpleSpiceUpdate *qemu_spice_create_update(SimpleSpiceDisplay *ssd) { @@ -78,11 +78,12 @@ SimpleSpiceUpdate *qemu_spice_create_update(SimpleSpiceDisplay *ssd) uint8_t *src, *dst; int by, bw, bh; + qemu_mutex_lock_iothread(); if (qemu_spice_rect_is_empty(&ssd->dirty)) { + qemu_mutex_unlock_iothread(); return NULL; }; - pthread_mutex_lock(&ssd->lock); dprint(2, "%s: lr %d -> %d, tb -> %d -> %d\n", __FUNCTION__, ssd->dirty.left, ssd->dirty.right, ssd->dirty.top, ssd->dirty.bottom); @@ -140,7 +141,7 @@ SimpleSpiceUpdate *qemu_spice_create_update(SimpleSpiceDisplay *ssd) cmd->data = (intptr_t)drawable; memset(&ssd->dirty, 0, sizeof(ssd->dirty)); - pthread_mutex_unlock(&ssd->lock); + qemu_mutex_unlock_iothread(); return update; } @@ -184,14 +185,19 @@ void qemu_spice_create_host_primary(SimpleSpiceDisplay *ssd) surface.type = 0; surface.mem = (intptr_t)ssd->buf; surface.group_id = MEMSLOT_GROUP_HOST; + + qemu_mutex_unlock_iothread(); ssd->worker->create_primary_surface(ssd->worker, 0, &surface); + qemu_mutex_lock_iothread(); } void qemu_spice_destroy_host_primary(SimpleSpiceDisplay *ssd) { dprint(1, "%s:\n", __FUNCTION__); + qemu_mutex_unlock_iothread(); ssd->worker->destroy_primary_surface(ssd->worker, 0); + qemu_mutex_lock_iothread(); } void qemu_spice_vm_change_state_handler(void *opaque, int running, int reason) @@ -201,7 +207,9 @@ void qemu_spice_vm_change_state_handler(void *opaque, int running, int reason) if (running) { ssd->worker->start(ssd->worker); } else { + qemu_mutex_unlock_iothread(); ssd->worker->stop(ssd->worker); + qemu_mutex_lock_iothread(); } ssd->running = running; } @@ -219,31 +227,25 @@ void qemu_spice_display_update(SimpleSpiceDisplay *ssd, update_area.top = y; update_area.bottom = y + h; - pthread_mutex_lock(&ssd->lock); if (qemu_spice_rect_is_empty(&ssd->dirty)) { ssd->notify++; } qemu_spice_rect_union(&ssd->dirty, &update_area); - pthread_mutex_unlock(&ssd->lock); } void qemu_spice_display_resize(SimpleSpiceDisplay *ssd) { dprint(1, "%s:\n", __FUNCTION__); - pthread_mutex_lock(&ssd->lock); memset(&ssd->dirty, 0, sizeof(ssd->dirty)); qemu_pf_conv_put(ssd->conv); ssd->conv = NULL; - pthread_mutex_unlock(&ssd->lock); qemu_spice_destroy_host_primary(ssd); qemu_spice_create_host_primary(ssd); - pthread_mutex_lock(&ssd->lock); memset(&ssd->dirty, 0, sizeof(ssd->dirty)); ssd->notify++; - pthread_mutex_unlock(&ssd->lock); } void qemu_spice_display_refresh(SimpleSpiceDisplay *ssd) @@ -398,7 +400,6 @@ void qemu_spice_display_init(DisplayState *ds) sdpy.ds = ds; sdpy.bufsize = (16 * 1024 * 1024); sdpy.buf = qemu_malloc(sdpy.bufsize); - pthread_mutex_init(&sdpy.lock, NULL); register_displaychangelistener(ds, &display_listener); sdpy.qxl.base.sif = &dpy_interface.base; diff --git a/ui/spice-display.h b/ui/spice-display.h index e17671c..aef0464 100644 --- a/ui/spice-display.h +++ b/ui/spice-display.h @@ -40,7 +40,6 @@ typedef struct SimpleSpiceDisplay { uint32_t unique; QemuPfConv *conv; - pthread_mutex_t lock; QXLRect dirty; int notify; int running;