[5/9] DDraw: Make IDirect3DLightImpl thread safe

Stefan Dösinger stefandoesinger at gmx.at
Sat Aug 19 16:51:11 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:29:45 2006 +0200
Subject: [PATCH] DDraw: Make IDirectDrawLightImpl thread safe

---

 dlls/ddraw/ddraw_private.h |    4 ++++
 dlls/ddraw/direct3d.c      |    6 ++++++
 dlls/ddraw/light.c         |   30 ++++++++++++++++++++++++------
 3 files changed, 34 insertions(+), 6 deletions(-)

c28218aa6e374e96ca3f301fa91e0b712806ace6
diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h
index 871c0cd..36f2c63 100644
--- a/dlls/ddraw/ddraw_private.h
+++ b/dlls/ddraw/ddraw_private.h
@@ -458,6 +458,10 @@ struct IDirect3DLightImpl
     void                      (*activate)(IDirect3DLightImpl*);
     void                      (*desactivate)(IDirect3DLightImpl*);
     void                      (*update)(IDirect3DLightImpl*);
+
+    /* Thread synchronisation */
+    CRITICAL_SECTION          crit;
+    BOOL                      hasCrit;
 };
 
 /* Vtable */
diff --git a/dlls/ddraw/direct3d.c b/dlls/ddraw/direct3d.c
index f7b93a8..c02d04c 100644
--- a/dlls/ddraw/direct3d.c
+++ b/dlls/ddraw/direct3d.c
@@ -419,6 +419,12 @@ IDirect3DImpl_3_CreateLight(IDirect3D3 *
     object->update = light_desactivate;
     object->active_viewport = NULL;
 
+    if(This->hasCrit)
+    {
+        InitializeCriticalSection(&object->crit);
+        object->hasCrit = TRUE;
+    }
+
     *Light = ICOM_INTERFACE(object, IDirect3DLight);
 
     TRACE("(%p) creating implementation at %p.\n", This, object);
diff --git a/dlls/ddraw/light.c b/dlls/ddraw/light.c
index d5b7dd6..ee4bb46 100644
--- a/dlls/ddraw/light.c
+++ b/dlls/ddraw/light.c
@@ -112,8 +112,13 @@ IDirect3DLightImpl_Release(IDirect3DLigh
     TRACE("(%p)->() decrementing from %lu.\n", This, ref + 1);
 
     if (!ref) {
+        if(This->hasCrit)
+        {
+            DeleteCriticalSection(&This->crit);
+            This->hasCrit = FALSE;
+        }
         HeapFree(GetProcessHeap(), 0, This);
-	return 0;
+        return 0;
     }
     return ref;
 }
@@ -181,7 +186,9 @@ IDirect3DLightImpl_SetLight(IDirect3DLig
 
     if ( (lpLight->dltType == 0) || (lpLight->dltType > D3DLIGHT_PARALLELPOINT) )
          return DDERR_INVALIDPARAMS;
-    
+
+    DDOBJ_LOCK(This);
+
     if ( lpLight->dltType == D3DLIGHT_PARALLELPOINT )
 	 FIXME("D3DLIGHT_PARALLELPOINT no supported\n");
     
@@ -204,8 +211,10 @@ IDirect3DLightImpl_SetLight(IDirect3DLig
     light7->dvPhi          = lpLight->dvPhi;
 
     memcpy(&This->light, lpLight, lpLight->dwSize);
+    DDOBJ_UNLOCK(This);
+
     if ((This->light.dwFlags & D3DLIGHT_ACTIVE) != 0) {
-        This->update(This);        
+        This->update(This);
     }
     return D3D_OK;
 }
@@ -232,7 +241,9 @@ IDirect3DLightImpl_GetLight(IDirect3DLig
         TRACE("  Returning light definition :\n");
 	dump_light(&This->light);
     }
+    DDOBJ_LOCK(This);
     memcpy(lpLight, &This->light, lpLight->dwSize);
+    DDOBJ_UNLOCK(This);
     return DD_OK;
 }
 
@@ -250,9 +261,12 @@ void light_update(IDirect3DLightImpl* Th
 
     if (!This->active_viewport || !This->active_viewport->active_device)
         return;
-    device =  This->active_viewport->active_device;
+
+    DDOBJ_LOCK(This);
+    device = This->active_viewport->active_device;
 
     IDirect3DDevice7_SetLight(ICOM_INTERFACE(device,IDirect3DDevice7), This->dwLightIndex, &(This->light7));
+    DDOBJ_UNLOCK(This);
 }
 
 /*****************************************************************************
@@ -270,13 +284,15 @@ void light_activate(IDirect3DLightImpl* 
     if (!This->active_viewport || !This->active_viewport->active_device)
         return;
     device =  This->active_viewport->active_device;
-    
+
+    DDOBJ_LOCK(This);
     light_update(This);
     /* If was not active, activate it */
     if ((This->light.dwFlags & D3DLIGHT_ACTIVE) == 0) {
         IDirect3DDevice7_LightEnable(ICOM_INTERFACE(device,IDirect3DDevice7), This->dwLightIndex, TRUE);
 	This->light.dwFlags |= D3DLIGHT_ACTIVE;
     }
+    DDOBJ_UNLOCK(This);
 }
 
 /*****************************************************************************
@@ -295,12 +311,14 @@ void light_desactivate(IDirect3DLightImp
     if (!This->active_viewport || !This->active_viewport->active_device)
         return;
     device =  This->active_viewport->active_device;
-    
+
+    DDOBJ_LOCK(This);
     /* If was not active, activate it */
     if ((This->light.dwFlags & D3DLIGHT_ACTIVE) != 0) {
         IDirect3DDevice7_LightEnable(ICOM_INTERFACE(device,IDirect3DDevice7), This->dwLightIndex, FALSE);
 	This->light.dwFlags &= ~D3DLIGHT_ACTIVE;
     }
+    DDOBJ_UNLOCK(This);
 }
 
 const IDirect3DLightVtbl IDirect3DLight_Vtbl =
-- 
1.2.4



More information about the wine-patches mailing list