From 11db0ea655ceba02e85d1a1b59e6f36acafc146e Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Wed, 12 Jan 2005 19:50:22 +0000 Subject: [PATCH] Use only stored result of Interlocked* in AddRef/Release. --- dlls/wined3d/device.c | 17 ++++++++++------- dlls/wined3d/directx.c | 17 ++++++++++------- dlls/wined3d/stateblock.c | 17 ++++++++++------- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 7b66f1cae7c..ed93fef5b79 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -2998,21 +2998,24 @@ HRESULT WINAPI IWineD3DDeviceImpl_QueryInterface(IWineD3DDevice *iface,REFIID ri ULONG WINAPI IWineD3DDeviceImpl_AddRef(IWineD3DDevice *iface) { IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; - TRACE("(%p) : AddRef increasing from %ld\n", This, This->ref); - return InterlockedIncrement(&This->ref); + ULONG refCount = InterlockedIncrement(&This->ref); + + TRACE("(%p) : AddRef increasing from %ld\n", This, refCount - 1); + return refCount; } ULONG WINAPI IWineD3DDeviceImpl_Release(IWineD3DDevice *iface) { IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; - ULONG ref; - TRACE("(%p) : Releasing from %ld\n", This, This->ref); - ref = InterlockedDecrement(&This->ref); - if (ref == 0) { + ULONG refCount = InterlockedDecrement(&This->ref); + + TRACE("(%p) : Releasing from %ld\n", This, refCount + 1); + + if (!refCount) { IWineD3DStateBlock_Release((IWineD3DStateBlock *)This->stateBlock); IWineD3D_Release(This->wineD3D); HeapFree(GetProcessHeap(), 0, This); } - return ref; + return refCount; } /********************************************************** diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index 2be14bf09a6..5d06ead2e05 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -1613,17 +1613,20 @@ HRESULT WINAPI IWineD3DImpl_QueryInterface(IWineD3D *iface,REFIID riid,LPVOID *p ULONG WINAPI IWineD3DImpl_AddRef(IWineD3D *iface) { IWineD3DImpl *This = (IWineD3DImpl *)iface; - TRACE("(%p) : AddRef increasing from %ld\n", This, This->ref); - return InterlockedIncrement(&This->ref); + ULONG refCount = InterlockedIncrement(&This->ref); + + TRACE("(%p) : AddRef increasing from %ld\n", This, refCount - 1); + return refCount; } ULONG WINAPI IWineD3DImpl_Release(IWineD3D *iface) { IWineD3DImpl *This = (IWineD3DImpl *)iface; - ULONG ref; - TRACE("(%p) : Releasing from %ld\n", This, This->ref); - ref = InterlockedDecrement(&This->ref); - if (ref == 0) HeapFree(GetProcessHeap(), 0, This); - return ref; + ULONG refCount = InterlockedDecrement(&This->ref); + + TRACE("(%p) : Releasing from %ld\n", This, refCount + 1); + + if (!refCount) HeapFree(GetProcessHeap(), 0, This); + return refCount; } /********************************************************** diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c index a39fed2b4c4..1d447e66e3e 100644 --- a/dlls/wined3d/stateblock.c +++ b/dlls/wined3d/stateblock.c @@ -262,20 +262,23 @@ HRESULT WINAPI IWineD3DStateBlockImpl_QueryInterface(IWineD3DStateBlock *iface,R ULONG WINAPI IWineD3DStateBlockImpl_AddRef(IWineD3DStateBlock *iface) { IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface; - TRACE("(%p) : AddRef increasing from %ld\n", This, This->ref); - return InterlockedIncrement(&This->ref); + ULONG refCount = InterlockedIncrement(&This->ref); + + TRACE("(%p) : AddRef increasing from %ld\n", This, refCount - 1); + return refCount; } ULONG WINAPI IWineD3DStateBlockImpl_Release(IWineD3DStateBlock *iface) { IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface; - ULONG ref; - TRACE("(%p) : Releasing from %ld\n", This, This->ref); - ref = InterlockedDecrement(&This->ref); - if (ref == 0) { + ULONG refCount = InterlockedDecrement(&This->ref); + + TRACE("(%p) : Releasing from %ld\n", This, refCount + 1); + + if (!refCount) { IWineD3DDevice_Release((IWineD3DDevice *)This->wineD3DDevice); HeapFree(GetProcessHeap(), 0, This); } - return ref; + return refCount; } /**********************************************************