[9/9] DDraw: Make IDirectDrawClipperImpl thread safe

Stefan Dösinger stefandoesinger at gmx.at
Sat Aug 19 16:54:14 CDT 2006


-------------- next part --------------
From nobody Mon Sep 17 00:00:00 2001
From: Stefan Dösinger <stefan at codeweavers.com>
Date: Sat Aug 19 09:39:16 2006 +0200
Subject: [PATCH] DDraw: Make IDirectDrawClipperImpl thread safe

---

 dlls/ddraw/clipper.c       |   18 ++++++++++++++++++
 dlls/ddraw/ddraw_private.h |    4 ++--
 2 files changed, 20 insertions(+), 2 deletions(-)

5aaf5478e4a6411504e434f76c7d91bfacbc8b01
diff --git a/dlls/ddraw/clipper.c b/dlls/ddraw/clipper.c
index a5fe15e..1af94dd 100644
--- a/dlls/ddraw/clipper.c
+++ b/dlls/ddraw/clipper.c
@@ -106,6 +106,11 @@ static ULONG WINAPI IDirectDrawClipperIm
 
     if (ref == 0)
     {
+        if(This->hasCrit)
+        {
+            DeleteCriticalSection(&This->crit);
+            This->hasCrit = FALSE;
+        }
 	HeapFree(GetProcessHeap(), 0, This);
 	return 0;
     }
@@ -138,7 +143,9 @@ static HRESULT WINAPI IDirectDrawClipper
 	return DDERR_INVALIDPARAMS;
     }
 
+    DDOBJ_LOCK(This);
     This->hWnd = hWnd;
+    DDOBJ_UNLOCK(This);
     return DD_OK;
 }
 
@@ -168,6 +175,7 @@ static HRESULT WINAPI IDirectDrawClipper
 
     TRACE("(%p,%p,%p,%p)\n", This, lpRect, lpClipList, lpdwSize);
 
+    DDOBJ_LOCK(This);
     if (This->hWnd)
     {
         HDC hDC = GetDCEx(This->hWnd, NULL, DCX_WINDOW);
@@ -195,11 +203,13 @@ static HRESULT WINAPI IDirectDrawClipper
             DeleteObject(hRgn);
             ReleaseDC(This->hWnd, hDC);
         }
+        DDOBJ_UNLOCK(This);
         return DD_OK;
     }
     else
     {
         static int warned = 0;
+        DDOBJ_UNLOCK(This);
         if (warned++ < 10)
             FIXME("(%p,%p,%p,%p),stub!\n",This,lpRect,lpClipList,lpdwSize);
         if (lpdwSize) *lpdwSize=0;
@@ -248,7 +258,9 @@ static HRESULT WINAPI IDirectDrawClipper
     IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
     TRACE("(%p)->(%p)\n", This, hWndPtr);
 
+    DDOBJ_LOCK(This);
     *hWndPtr = This->hWnd;
+    DDOBJ_UNLOCK(This);
 
     return DD_OK;
 }
@@ -279,6 +291,12 @@ static HRESULT WINAPI IDirectDrawClipper
     pOwner = ICOM_OBJECT(IDirectDrawImpl, IDirectDraw, lpDD);
     This->ddraw_owner = pOwner;
 
+    if(pOwner->hasCrit)
+    {
+        InitializeCriticalSection(&This->crit);
+        This->hasCrit = TRUE;
+    }
+
     return DD_OK;
 }
 
diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h
index e0cbbb9..284bd6d 100644
--- a/dlls/ddraw/ddraw_private.h
+++ b/dlls/ddraw/ddraw_private.h
@@ -389,8 +389,8 @@ struct IDirectDrawClipperImpl
     HWND hWnd;
 
     IDirectDrawImpl* ddraw_owner;
-    struct IDirectDrawClipperImpl* prev_ddraw;
-    struct IDirectDrawClipperImpl* next_ddraw;
+    CRITICAL_SECTION crit;
+    BOOL             hasCrit;
 };
 
 const IDirectDrawClipperVtbl IDirectDrawClipper_Vtbl;
-- 
1.2.4



More information about the wine-patches mailing list