[Spice-devel] [PATCH 11/17] Add semaphore to protect quic_data from concurrent access

alexl at redhat.com alexl at redhat.com
Tue Sep 14 12:09:01 PDT 2010


From: Alexander Larsson <alexl at redhat.com>

---
 display/qxldd.h |    1 +
 display/res.c   |   12 +++++++++++-
 2 files changed, 12 insertions(+), 1 deletions(-)

diff --git a/display/qxldd.h b/display/qxldd.h
index b55ad30..fb39b46 100644
--- a/display/qxldd.h
+++ b/display/qxldd.h
@@ -249,6 +249,7 @@ typedef struct PDev {
     UINT8 *surf_base;
 
     QuicData *quic_data;
+    HSEMAPHORE quic_data_sem;
 
     QXLCommandRing *cmd_ring;
     QXLCursorRing *cursor_ring;
diff --git a/display/res.c b/display/res.c
index 4202daa..9d244a6 100644
--- a/display/res.c
+++ b/display/res.c
@@ -1641,6 +1641,8 @@ static _inline Resource *GetQuicImage(PDev *pdev, SURFOBJ *surf, XLATEOBJ *color
         return NULL;
     }
 
+    EngAcquireSemaphore(pdev->quic_data_sem);
+
     quic_data = pdev->quic_data;
 
     alloc_size = MIN(QUIC_ALLOC_BASE + (height * line_size >> 4), QUIC_ALLOC_BASE + QUIC_BUF_MAX);
@@ -1672,13 +1674,18 @@ static _inline Resource *GetQuicImage(PDev *pdev, SURFOBJ *surf, XLATEOBJ *color
     if (data_size == QUIC_ERROR) {
         FreeQuicImage(pdev, image_res);
         DEBUG_PRINT((pdev, 13, "%s: error\n", __FUNCTION__));
-        return NULL;
+        image_res = NULL;
+        goto out;
     }
 
     quic_data->chunk->data_size = (data_size - quic_data->prev_chunks_io_words) << 2;
     internal->image.quic.data_size = data_size << 2;
     DEBUG_PRINT((pdev, 13, "%s: done. row size %u quic size %u \n", __FUNCTION__,
                  line_size * height, data_size << 2));
+
+ out:
+    EngReleaseSemaphore(pdev->quic_data_sem);
+
     return image_res;
 }
 
@@ -3207,6 +3214,8 @@ BOOL ResInit(PDev *pdev)
         return FALSE;
     }
     pdev->quic_data = usr_data;
+    pdev->quic_data_sem = EngCreateSemaphore();
+
     return TRUE;
 }
 
@@ -3214,6 +3223,7 @@ void ResDestroy(PDev *pdev)
 {
     QuicData *usr_data = pdev->quic_data;
     quic_destroy(usr_data->quic);
+    EngDeleteSemaphore(pdev->quic_data_sem);
     EngFreeMem(usr_data);
 }
 
-- 
1.7.2.2



More information about the Spice-devel mailing list