[Spice-devel] [PATCH 04/17] Protect all references to cmd_ring with cmd_sem

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


From: Alexander Larsson <alexl at redhat.com>

---
 display/res.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/display/res.c b/display/res.c
index 807f94a..c1d0cb5 100644
--- a/display/res.c
+++ b/display/res.c
@@ -74,12 +74,10 @@ static BOOL SetClip(PDev *pdev, CLIPOBJ *clip, QXLDrawable *drawable);
 
 #define PUSH_CMD(pdev) do {                             \
     int notify;                                         \
-    EngAcquireSemaphore(pdev->Res->cmd_sem);            \
     SPICE_RING_PUSH(pdev->cmd_ring, notify);            \
     if (notify) {                                       \
         WRITE_PORT_UCHAR(pdev->notify_cmd_port, 0);     \
     }                                                   \
-    EngReleaseSemaphore(pdev->Res->cmd_sem);            \
 } while (0);
 
 #define PUSH_CURSOR_CMD(pdev) do {                      \
@@ -192,6 +190,7 @@ static void WaitForCursorRing(PDev* pdev)
     }
 }
 
+/* Called with cmd_sem held */
 static void WaitForCmdRing(PDev* pdev)
 {
     int wait;
@@ -577,11 +576,13 @@ void PushDrawable(PDev *pdev, QXLDrawable *drawable)
 {
     QXLCommand *cmd;
 
+    EngAcquireSemaphore(pdev->Res->cmd_sem);            \
     WaitForCmdRing(pdev);
     cmd = SPICE_RING_PROD_ITEM(pdev->cmd_ring);
     cmd->type = QXL_CMD_DRAW;
     cmd->data = PA(pdev, drawable, pdev->main_mem_slot);
     PUSH_CMD(pdev);
+    EngReleaseSemaphore(pdev->Res->cmd_sem);            \
 }
 
 static QXLSurfaceCmd *GetSurfaceCmd(PDev *pdev)
@@ -614,11 +615,13 @@ void PushSurfaceCmd(PDev *pdev, QXLSurfaceCmd *surface_cmd)
 {
     QXLCommand *cmd;
 
+    EngAcquireSemaphore(pdev->Res->cmd_sem);            \
     WaitForCmdRing(pdev);
     cmd = SPICE_RING_PROD_ITEM(pdev->cmd_ring);
     cmd->type = QXL_CMD_SURFACE;
     cmd->data = PA(pdev, surface_cmd, pdev->main_mem_slot);
     PUSH_CMD(pdev);
+    EngReleaseSemaphore(pdev->Res->cmd_sem);            \
 }
 
 
@@ -2422,11 +2425,13 @@ void UpdateArea(PDev *pdev, RECTL *area, UINT32 surface_id)
     updat_cmd->update_id = ++pdev->Res->update_id;
     updat_cmd->surface_id = surface_id;
 
+    EngAcquireSemaphore(pdev->Res->cmd_sem);            \
     WaitForCmdRing(pdev);
     cmd = SPICE_RING_PROD_ITEM(pdev->cmd_ring);
     cmd->type = QXL_CMD_UPDATE;
     cmd->data = PA(pdev, updat_cmd, pdev->main_mem_slot);
     PUSH_CMD(pdev);
+    EngReleaseSemaphore(pdev->Res->cmd_sem);            \
     do {
 #ifdef DBG
         {
-- 
1.7.2.2



More information about the Spice-devel mailing list