- use Interlocked* functions in AddRef and Release.
- store the result of the Interlocked functions and use only this.
diff --git a/dlls/ddraw/dclipper/main.c b/dlls/ddraw/dclipper/main.c
index 0195ea2..a0f69d7 100644
--- a/dlls/ddraw/dclipper/main.c
+++ b/dlls/ddraw/dclipper/main.c
@@ -114,14 +114,16 @@
ULONG WINAPI Main_DirectDrawClipper_Release(LPDIRECTDRAWCLIPPER iface) {
IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
- TRACE("(%p)->() decrementing from %lu.\n", This, This->ref );
+ ULONG ref = InterlockedDecrement(&This->ref);
- if (--This->ref == 0)
+ TRACE("(%p)->() decrementing from %lu.\n", This, ref + 1);
+
+ if (ref == 0)
{
Main_DirectDrawClipper_Destroy(This);
return 0;
}
- else return This->ref;
+ else return ref;
}
/***********************************************************************
@@ -211,7 +213,7 @@
|| IsEqualGUID(&IID_IDirectDrawClipper, riid))
{
*ppvObj = ICOM_INTERFACE(This, IDirectDrawClipper);
- ++This->ref;
+ InterlockedIncrement(&This->ref);
return S_OK;
}
else
@@ -223,8 +225,11 @@
ULONG WINAPI Main_DirectDrawClipper_AddRef( LPDIRECTDRAWCLIPPER iface )
{
IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
- TRACE("(%p)->() incrementing from %lu.\n", This, This->ref );
- return ++This->ref;
+ ULONG ref = InterlockedIncrement(&This->ref);
+
+ TRACE("(%p)->() incrementing from %lu.\n", This, ref - 1);
+
+ return ref;
}
HRESULT WINAPI Main_DirectDrawClipper_GetHWnd(