[Spice-devel] [PATCH 03/17] Move cmd_sem and print_sem to global device info

alexl at redhat.com alexl at redhat.com
Tue Sep 14 12:08:53 PDT 2010


From: Alexander Larsson <alexl at redhat.com>

The cmd and print semaphores protect hardware instances that exist
one per device, so we can't really use per-pdev locks to protect them.
---
 display/driver.c |   22 +++-------------------
 display/qxldd.h  |    6 +++---
 display/res.c    |   20 ++++++++++++++++++--
 3 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/display/driver.c b/display/driver.c
index 26c5686..44eaa5f 100644
--- a/display/driver.c
+++ b/display/driver.c
@@ -104,12 +104,12 @@ static CallCounterInfo counters_info[NUM_CALL_COUNTERS] = {
 void DebugPrintV(PDev *pdev, const char *message, va_list ap)
 {
     if (pdev && pdev->log_buf) {
-        EngAcquireSemaphore(pdev->print_sem);
+        EngAcquireSemaphore(pdev->Res->print_sem);
         _snprintf(pdev->log_buf, QXL_LOG_BUF_SIZE, QXLDD_DEBUG_PREFIX);
         _vsnprintf(pdev->log_buf + strlen(QXLDD_DEBUG_PREFIX),
                    QXL_LOG_BUF_SIZE - strlen(QXLDD_DEBUG_PREFIX), message, ap);
         WRITE_PORT_UCHAR(pdev->log_port, 0);
-        EngReleaseSemaphore(pdev->print_sem);
+        EngReleaseSemaphore(pdev->Res->print_sem);
     } else {
         EngDebugPrint(QXLDD_DEBUG_PREFIX, (PCHAR)message, ap);
     }
@@ -505,19 +505,9 @@ DHPDEV DrvEnablePDEV(DEVMODEW *dev_mode, PWSTR ignore1, ULONG ignore2, HSURF *ig
         goto err1;
     }
 
-    if (!(pdev->print_sem = EngCreateSemaphore())) {
-        DEBUG_PRINT((NULL, 0, "%s: create print sem failed\n", __FUNCTION__));
-        goto err2;
-    }
-
-    if (!(pdev->cmd_sem = EngCreateSemaphore())) {
-        DEBUG_PRINT((NULL, 0, "%s: create cmd sem failed\n", __FUNCTION__));
-        goto err3;
-    }
-
     if (!ResInit(pdev)) {
         DEBUG_PRINT((NULL, 0, "%s: init res failed\n", __FUNCTION__));
-        goto err4;
+        goto err2;
     }
 
     RtlCopyMemory(dev_caps, &gdi_info, dev_caps_size);
@@ -526,10 +516,6 @@ DHPDEV DrvEnablePDEV(DEVMODEW *dev_mode, PWSTR ignore1, ULONG ignore2, HSURF *ig
     DEBUG_PRINT((NULL, 1, "%s: 0x%lx\n", __FUNCTION__, pdev));
     return(DHPDEV)pdev;
 
-err4:
-    EngDeleteSemaphore(pdev->cmd_sem);
-err3:
-    EngDeleteSemaphore(pdev->print_sem);
 err2:
     DestroyPalette(pdev);
 
@@ -546,8 +532,6 @@ VOID DrvDisablePDEV(DHPDEV in_pdev)
     DEBUG_PRINT((NULL, 1, "%s: 0x%lx\n", __FUNCTION__, pdev));
     ResDestroy(pdev);
     DestroyPalette(pdev);
-    EngDeleteSemaphore(pdev->cmd_sem);
-    EngDeleteSemaphore(pdev->print_sem);
     EngFreeMem(pdev);
     DEBUG_PRINT((NULL, 1, "%s: 0x%lx exit\n", __FUNCTION__, pdev));
 }
diff --git a/display/qxldd.h b/display/qxldd.h
index 0b07f23..ad373ae 100644
--- a/display/qxldd.h
+++ b/display/qxldd.h
@@ -179,6 +179,9 @@ typedef struct DevRes {
     UINT64 free_outputs;
     UINT32 update_id;
 
+    HSEMAPHORE print_sem;
+    HSEMAPHORE cmd_sem;
+
     CacheImage cache_image_pool[IMAGE_POOL_SIZE];
     Ring cache_image_lru;
     Ring cursors_lru;
@@ -259,9 +262,6 @@ typedef struct PDev {
     UINT8 *log_buf;
     UINT32 *log_level;
 
-    HSEMAPHORE print_sem;
-    HSEMAPHORE cmd_sem;
-
     PMemSlot *mem_slots;
     UINT8 num_mem_slot;
     UINT8 main_mem_slot;
diff --git a/display/res.c b/display/res.c
index 26e43c9..807f94a 100644
--- a/display/res.c
+++ b/display/res.c
@@ -74,12 +74,12 @@ static BOOL SetClip(PDev *pdev, CLIPOBJ *clip, QXLDrawable *drawable);
 
 #define PUSH_CMD(pdev) do {                             \
     int notify;                                         \
-    EngAcquireSemaphore(pdev->cmd_sem);                 \
+    EngAcquireSemaphore(pdev->Res->cmd_sem);            \
     SPICE_RING_PUSH(pdev->cmd_ring, notify);            \
     if (notify) {                                       \
         WRITE_PORT_UCHAR(pdev->notify_cmd_port, 0);     \
     }                                                   \
-    EngReleaseSemaphore(pdev->cmd_sem);                 \
+    EngReleaseSemaphore(pdev->Res->cmd_sem);            \
 } while (0);
 
 #define PUSH_CURSOR_CMD(pdev) do {                      \
@@ -387,6 +387,14 @@ void CleanGlobalRes()
                     EngDeleteSemaphore(res->malloc_sem);
                     res->malloc_sem = NULL;
                 }
+                if (res->cmd_sem) {
+                    EngDeleteSemaphore(res->cmd_sem);
+                    res->cmd_sem = NULL;
+                }
+                if (res->print_sem) {
+                    EngDeleteSemaphore(res->print_sem);
+                    res->print_sem = NULL;
+                }
                 EngFreeMem(res);
             }
         }
@@ -436,6 +444,14 @@ static void InitRes(PDev *pdev)
     if (!pdev->Res->malloc_sem) {
         PANIC(pdev, "Res malloc sem creation failed\n");
     }
+    pdev->Res->cmd_sem = EngCreateSemaphore();
+    if (!pdev->Res->cmd_sem) {
+        PANIC(pdev, "Res cmd sem creation failed\n");
+    }
+    pdev->Res->print_sem = EngCreateSemaphore();
+    if (!pdev->Res->print_sem) {
+        PANIC(pdev, "Res print sem creation failed\n");
+    }
 
     InitMspace(pdev->Res, MSPACE_TYPE_DEVRAM, pdev->io_pages_virt, pdev->num_io_pages * PAGE_SIZE);
     InitMspace(pdev->Res, MSPACE_TYPE_VRAM, pdev->fb, pdev->fb_size);
-- 
1.7.2.2



More information about the Spice-devel mailing list