[Spice-devel] [PATCH 1/7] Make malloc_sem global

alexl at redhat.com alexl at redhat.com
Tue Aug 24 01:41:08 PDT 2010


From: Alexander Larsson <alexl at redhat.com>

It protects shared data (mspaces info) so it needs to be shared.
---
 display/driver.c |   22 ++++++----------------
 display/qxldd.h  |    2 +-
 display/res.c    |   13 +++++++++++--
 3 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/display/driver.c b/display/driver.c
index 742348c..46df8f2 100644
--- a/display/driver.c
+++ b/display/driver.c
@@ -505,24 +505,19 @@ DHPDEV DrvEnablePDEV(DEVMODEW *dev_mode, PWSTR ignore1, ULONG ignore2, HSURF *ig
         goto err1;
     }
 
-    if (!(pdev->malloc_sem = EngCreateSemaphore())) {
-        DEBUG_PRINT((NULL, 0, "%s: create malloc sem failed\n", __FUNCTION__));
-        goto err2;
-    }
-
     if (!(pdev->print_sem = EngCreateSemaphore())) {
-        DEBUG_PRINT((NULL, 0, "%s: create malloc sem failed\n", __FUNCTION__));
-        goto err3;
+        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 err4;
+        goto err3;
     }
 
     if (!ResInit(pdev)) {
         DEBUG_PRINT((NULL, 0, "%s: init res failed\n", __FUNCTION__));
-        goto err5;
+        goto err4;
     }
 
     RtlCopyMemory(dev_caps, &gdi_info, dev_caps_size);
@@ -531,14 +526,10 @@ DHPDEV DrvEnablePDEV(DEVMODEW *dev_mode, PWSTR ignore1, ULONG ignore2, HSURF *ig
     DEBUG_PRINT((NULL, 1, "%s: 0x%lx\n", __FUNCTION__, pdev));
     return(DHPDEV)pdev;
 
-err5:
-    EngDeleteSemaphore(pdev->cmd_sem);
 err4:
-    EngDeleteSemaphore(pdev->print_sem);
-
+    EngDeleteSemaphore(pdev->cmd_sem);
 err3:
-    EngDeleteSemaphore(pdev->malloc_sem);
-
+    EngDeleteSemaphore(pdev->print_sem);
 err2:
     DestroyPalette(pdev);
 
@@ -556,7 +547,6 @@ VOID DrvDisablePDEV(DHPDEV in_pdev)
     ResDestroy(pdev);
     DestroyPalette(pdev);
     EngDeleteSemaphore(pdev->cmd_sem);
-    EngDeleteSemaphore(pdev->malloc_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 7d22a0d..868a1a9 100644
--- a/display/qxldd.h
+++ b/display/qxldd.h
@@ -176,6 +176,7 @@ typedef struct SurfaceInfo {
 
 typedef struct DevRes {   
     MspaceInfo mspaces[NUM_MSPACES];
+    HSEMAPHORE malloc_sem;
 
     BOOL need_init;
     UINT64 free_outputs;
@@ -258,7 +259,6 @@ typedef struct PDev {
     UINT8 *log_buf;
     UINT32 *log_level;
 
-    HSEMAPHORE malloc_sem;
     HSEMAPHORE print_sem;
     HSEMAPHORE cmd_sem;
 
diff --git a/display/res.c b/display/res.c
index 15e14ae..1f67dbf 100644
--- a/display/res.c
+++ b/display/res.c
@@ -295,7 +295,7 @@ static void *__AllocMem(PDev* pdev, UINT32 mspace_type, size_t size,
     ASSERT(pdev, pdev && pdev->Res.mspaces[mspace_type]._mspace);
     DEBUG_PRINT((pdev, 12, "%s: 0x%lx size %u\n", __FUNCTION__, pdev, size));
 
-    EngAcquireSemaphore(pdev->malloc_sem);
+    EngAcquireSemaphore(pdev->Res.malloc_sem);
     while (!(ptr = mspace_malloc(pdev->Res.mspaces[mspace_type]._mspace, size))) {
         int notify;
         int num_to_release = release_bunch;
@@ -325,7 +325,7 @@ static void *__AllocMem(PDev* pdev, UINT32 mspace_type, size_t size,
             num_to_release--;
         }
     }
-    EngReleaseSemaphore(pdev->malloc_sem);
+    EngReleaseSemaphore(pdev->Res.malloc_sem);
     ASSERT(pdev, (!ptr && !force) || (ptr >= pdev->Res.mspaces[mspace_type].mspace_start &&
                                       ptr < pdev->Res.mspaces[mspace_type].mspace_end));
     DEBUG_PRINT((pdev, 13, "%s: 0x%lx done 0x%x\n", __FUNCTION__, pdev, ptr));
@@ -362,6 +362,10 @@ void CleanGlobalRes()
                 EngFreeMem(global_res[i].surfaces_info);
                 global_res[i].surfaces_info = NULL;
             }
+            if (global_res[i].malloc_sem) {
+                EngDeleteSemaphore(global_res[i].malloc_sem);
+                global_res[i].malloc_sem = NULL;
+            }
         }
         EngFreeMem(global_res);
         global_res = NULL;
@@ -412,6 +416,11 @@ static void InitRes(PDev *pdev)
     }
 
     pdev->Res.free_outputs = 0;
+    pdev->Res.malloc_sem = EngCreateSemaphore();
+    if (!pdev->Res.malloc_sem) {
+        PANIC(pdev, "Res malloc 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);
     pdev->Res.update_id = *pdev->dev_update_id;
-- 
1.7.2.1



More information about the Spice-devel mailing list