From a1e304a25f79feaa2d7086cd33d86c1d6e2e8259 Mon Sep 17 00:00:00 2001 From: James Hawkins Date: Wed, 12 Jan 2005 19:29:43 +0000 Subject: [PATCH] - use only stored result of Interlocked* in AddRef/Release - expand TRACEs to display the ref count --- dlls/shlwapi/assoc.c | 16 +++++++++------- dlls/shlwapi/istream.c | 17 ++++++++++------- dlls/shlwapi/regstream.c | 15 +++++++++------ 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/dlls/shlwapi/assoc.c b/dlls/shlwapi/assoc.c index d52dad78998..480f3ee1260 100644 --- a/dlls/shlwapi/assoc.c +++ b/dlls/shlwapi/assoc.c @@ -467,10 +467,11 @@ static HRESULT WINAPI IQueryAssociations_fnQueryInterface( static ULONG WINAPI IQueryAssociations_fnAddRef(IQueryAssociations *iface) { IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface; + ULONG refCount = InterlockedIncrement(&This->ref); + + TRACE("(%p)->(ref before=%lu)\n",This, refCount - 1); - TRACE("(%p)->(ref before=%lu)\n",This, This->ref); - - return InterlockedIncrement(&This->ref); + return refCount; } /************************************************************************** @@ -481,16 +482,17 @@ static ULONG WINAPI IQueryAssociations_fnAddRef(IQueryAssociations *iface) static ULONG WINAPI IQueryAssociations_fnRelease(IQueryAssociations *iface) { IQueryAssociationsImpl *This = (IQueryAssociationsImpl *)iface; - ULONG ulRet; + ULONG refCount = InterlockedDecrement(&This->ref); - TRACE("(%p)->(ref before=%lu)\n",This, This->ref); + TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1); - if (!(ulRet = InterlockedDecrement(&This->ref))) + if (!refCount) { TRACE("Destroying IQueryAssociations (%p)\n", This); HeapFree(GetProcessHeap(), 0, This); } - return ulRet; + + return refCount; } /************************************************************************** diff --git a/dlls/shlwapi/istream.c b/dlls/shlwapi/istream.c index 0b38ad2911f..fffa5018376 100644 --- a/dlls/shlwapi/istream.c +++ b/dlls/shlwapi/istream.c @@ -78,9 +78,11 @@ static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVO static ULONG WINAPI IStream_fnAddRef(IStream *iface) { ISHFileStream *This = (ISHFileStream *)iface; + ULONG refCount = InterlockedIncrement(&This->ref); + + TRACE("(%p)->(ref before=%lu)\n",This, refCount - 1); - TRACE("(%p)\n", This); - return InterlockedIncrement(&This->ref); + return refCount; } /************************************************************************** @@ -89,18 +91,19 @@ static ULONG WINAPI IStream_fnAddRef(IStream *iface) static ULONG WINAPI IStream_fnRelease(IStream *iface) { ISHFileStream *This = (ISHFileStream *)iface; - ULONG ulRet; + ULONG refCount = InterlockedDecrement(&This->ref); - TRACE("(%p)\n", This); - - if (!(ulRet = InterlockedDecrement(&This->ref))) + TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1); + + if (!refCount) { IStream_fnCommit(iface, 0); /* If ever buffered, this will be needed */ LocalFree((HLOCAL)This->lpszPath); CloseHandle(This->hFile); HeapFree(GetProcessHeap(), 0, This); } - return ulRet; + + return refCount; } /************************************************************************** diff --git a/dlls/shlwapi/regstream.c b/dlls/shlwapi/regstream.c index 384c61a0726..b6811c3f909 100644 --- a/dlls/shlwapi/regstream.c +++ b/dlls/shlwapi/regstream.c @@ -75,10 +75,11 @@ static HRESULT WINAPI IStream_fnQueryInterface(IStream *iface, REFIID riid, LPVO static ULONG WINAPI IStream_fnAddRef(IStream *iface) { ISHRegStream *This = (ISHRegStream *)iface; + ULONG refCount = InterlockedIncrement(&This->ref); + + TRACE("(%p)->(ref before=%lu)\n",This, refCount - 1); - TRACE("(%p)->(count=%lu)\n",This, This->ref); - - return InterlockedIncrement(&This->ref); + return refCount; } /************************************************************************** @@ -87,10 +88,11 @@ static ULONG WINAPI IStream_fnAddRef(IStream *iface) static ULONG WINAPI IStream_fnRelease(IStream *iface) { ISHRegStream *This = (ISHRegStream *)iface; + ULONG refCount = InterlockedDecrement(&This->ref); - TRACE("(%p)->()\n",This); + TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1); - if (!InterlockedDecrement(&This->ref)) + if (!refCount) { TRACE(" destroying SHReg IStream (%p)\n",This); @@ -102,7 +104,8 @@ static ULONG WINAPI IStream_fnRelease(IStream *iface) HeapFree(GetProcessHeap(),0,This); return 0; } - return This->ref; + + return refCount; } /**************************************************************************