Patchwork spice: lock spice worker calls

login
register
mail settings
Submitter Alon Levy
Date July 6, 2011, 12:19 p.m.
Message ID <1309954766-9728-5-git-send-email-alevy@redhat.com>
Download mbox | patch
Permalink /patch/103461/
State New
Headers show

Comments

Alon Levy - July 6, 2011, 12:19 p.m.
From: Gerd Hoffmann <kraxel@redhat.com>

... so we can call them from a thread.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/spice-display.c |   31 +++++++++++++++++++++++++++++++
 ui/spice-display.h |    1 +
 2 files changed, 32 insertions(+), 0 deletions(-)
Gerd Hoffmann - July 7, 2011, 7:40 a.m.
On 07/06/11 14:19, Alon Levy wrote:
> From: Gerd Hoffmann<kraxel@redhat.com>
>
> ... so we can call them from a thread.

Still needed?  I don't think so.

cheers,
   Gerd
Alon Levy - July 7, 2011, 7:52 a.m.
On Thu, Jul 07, 2011 at 09:40:15AM +0200, Gerd Hoffmann wrote:
> On 07/06/11 14:19, Alon Levy wrote:
> >From: Gerd Hoffmann<kraxel@redhat.com>
> >
> >... so we can call them from a thread.
> 
> Still needed?  I don't think so.
> 

Will drop (I wasn't sure we won't want this at a distant future, so I kept it).

> cheers,
>   Gerd
>

Patch

diff --git a/ui/spice-display.c b/ui/spice-display.c
index fef1758..93ebc19 100644
--- a/ui/spice-display.c
+++ b/ui/spice-display.c
@@ -67,80 +67,110 @@  void qemu_spice_update_area(SimpleSpiceDisplay *ssd, uint32_t surface_id,
                             struct QXLRect *area, struct QXLRect *dirty_rects,
                             uint32_t num_dirty_rects, uint32_t clear_dirty_region)
 {
+    qemu_mutex_lock(&ssd->wlock);
     ssd->worker->update_area(ssd->worker, surface_id, area, dirty_rects,
                              num_dirty_rects, clear_dirty_region);
+    qemu_mutex_unlock(&ssd->wlock);
 }
 
 void qemu_spice_add_memslot(SimpleSpiceDisplay *ssd, QXLDevMemSlot *memslot)
 {
+    qemu_mutex_lock(&ssd->wlock);
     ssd->worker->add_memslot(ssd->worker, memslot);
+    qemu_mutex_unlock(&ssd->wlock);
 }
 
 void qemu_spice_del_memslot(SimpleSpiceDisplay *ssd, uint32_t gid, uint32_t sid)
 {
+    qemu_mutex_lock(&ssd->wlock);
     ssd->worker->del_memslot(ssd->worker, gid, sid);
+    qemu_mutex_unlock(&ssd->wlock);
 }
 
 void qemu_spice_create_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id,
                                        QXLDevSurfaceCreate *surface)
 {
+    qemu_mutex_lock(&ssd->wlock);
     ssd->worker->create_primary_surface(ssd->worker, id, surface);
+    qemu_mutex_unlock(&ssd->wlock);
 }
 
 void qemu_spice_destroy_primary_surface(SimpleSpiceDisplay *ssd, uint32_t id)
 {
+    qemu_mutex_lock(&ssd->wlock);
     ssd->worker->destroy_primary_surface(ssd->worker, id);
+    qemu_mutex_unlock(&ssd->wlock);
 }
 
 void qemu_spice_destroy_surface_wait(SimpleSpiceDisplay *ssd, uint32_t id)
 {
+    qemu_mutex_lock(&ssd->wlock);
     ssd->worker->destroy_surface_wait(ssd->worker, id);
+    qemu_mutex_unlock(&ssd->wlock);
 }
 
 void qemu_spice_loadvm_commands(SimpleSpiceDisplay *ssd, struct QXLCommandExt *ext,
                                 uint32_t count)
 {
+    qemu_mutex_lock(&ssd->wlock);
     ssd->worker->loadvm_commands(ssd->worker, ext, count);
+    qemu_mutex_unlock(&ssd->wlock);
 }
 
 void qemu_spice_wakeup(SimpleSpiceDisplay *ssd)
 {
+    qemu_mutex_lock(&ssd->wlock);
     ssd->worker->wakeup(ssd->worker);
+    qemu_mutex_unlock(&ssd->wlock);
 }
 
 void qemu_spice_oom(SimpleSpiceDisplay *ssd)
 {
+    qemu_mutex_lock(&ssd->wlock);
     ssd->worker->oom(ssd->worker);
+    qemu_mutex_unlock(&ssd->wlock);
 }
 
 void qemu_spice_start(SimpleSpiceDisplay *ssd)
 {
+    qemu_mutex_lock(&ssd->wlock);
     ssd->worker->start(ssd->worker);
+    qemu_mutex_unlock(&ssd->wlock);
 }
 
 void qemu_spice_stop(SimpleSpiceDisplay *ssd)
 {
+    qemu_mutex_lock(&ssd->wlock);
     ssd->worker->stop(ssd->worker);
+    qemu_mutex_unlock(&ssd->wlock);
 }
 
 void qemu_spice_reset_memslots(SimpleSpiceDisplay *ssd)
 {
+    qemu_mutex_lock(&ssd->wlock);
     ssd->worker->reset_memslots(ssd->worker);
+    qemu_mutex_unlock(&ssd->wlock);
 }
 
 void qemu_spice_destroy_surfaces(SimpleSpiceDisplay *ssd)
 {
+    qemu_mutex_lock(&ssd->wlock);
     ssd->worker->destroy_surfaces(ssd->worker);
+    qemu_mutex_unlock(&ssd->wlock);
 }
 
 void qemu_spice_reset_image_cache(SimpleSpiceDisplay *ssd)
 {
+    qemu_mutex_lock(&ssd->wlock);
     ssd->worker->reset_image_cache(ssd->worker);
+    qemu_mutex_unlock(&ssd->wlock);
 }
 
 void qemu_spice_reset_cursor(SimpleSpiceDisplay *ssd)
 {
+    qemu_mutex_lock(&ssd->wlock);
     ssd->worker->reset_cursor(ssd->worker);
+    qemu_mutex_unlock(&ssd->wlock);
 }
 
 
@@ -289,6 +319,7 @@  void qemu_spice_display_init_common(SimpleSpiceDisplay *ssd, DisplayState *ds)
 {
     ssd->ds = ds;
     qemu_mutex_init(&ssd->lock);
+    qemu_mutex_init(&ssd->wlock);
     ssd->mouse_x = -1;
     ssd->mouse_y = -1;
     ssd->bufsize = (16 * 1024 * 1024);
diff --git a/ui/spice-display.h b/ui/spice-display.h
index a39b19d..3968d75 100644
--- a/ui/spice-display.h
+++ b/ui/spice-display.h
@@ -41,6 +41,7 @@  struct SimpleSpiceDisplay {
     void *buf;
     int bufsize;
     QXLWorker *worker;
+    QemuMutex wlock;
     QXLInstance qxl;
     uint32_t unique;
     QemuPfConv *conv;