From b970aeb4b75c1e344f1e63c509cc0675660684dd Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Thu, 16 Sep 2004 19:08:04 +0000 Subject: [PATCH] Cleanup reference counting. --- dlls/dsound/buffer.c | 4 +-- dlls/dsound/capture.c | 71 ++++++++--------------------------------------- dlls/dsound/dsound.c | 22 +++++++-------- dlls/dsound/dsound_main.c | 8 +++--- dlls/dsound/primary.c | 6 +--- dlls/dsound/propset.c | 17 ++++++------ dlls/dsound/sound3d.c | 8 +++--- 7 files changed, 40 insertions(+), 96 deletions(-) diff --git a/dlls/dsound/buffer.c b/dlls/dsound/buffer.c index 8c833301690..44df9b07d70 100644 --- a/dlls/dsound/buffer.c +++ b/dlls/dsound/buffer.c @@ -70,12 +70,10 @@ static HRESULT WINAPI IDirectSoundNotifyImpl_QueryInterface( static ULONG WINAPI IDirectSoundNotifyImpl_AddRef(LPDIRECTSOUNDNOTIFY iface) { IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface; - DWORD ref; TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId()); - ref = InterlockedIncrement(&(This->ref)); - return ref; + return InterlockedIncrement(&(This->ref)); } static ULONG WINAPI IDirectSoundNotifyImpl_Release(LPDIRECTSOUNDNOTIFY iface) { diff --git a/dlls/dsound/capture.c b/dlls/dsound/capture.c index 1d550b80283..651a13dbbe6 100644 --- a/dlls/dsound/capture.c +++ b/dlls/dsound/capture.c @@ -373,19 +373,9 @@ IDirectSoundCaptureImpl_QueryInterface( static ULONG WINAPI IDirectSoundCaptureImpl_AddRef( LPDIRECTSOUNDCAPTURE iface ) { - ULONG uRef; IDirectSoundCaptureImpl *This = (IDirectSoundCaptureImpl *)iface; TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId()); - - EnterCriticalSection( &(This->lock) ); - uRef = ++(This->ref); - - if (This->driver) - IDsCaptureDriver_AddRef(This->driver); - - LeaveCriticalSection( &(This->lock) ); - - return uRef; + return InterlockedIncrement(&(This->ref)); } static ULONG WINAPI @@ -395,12 +385,7 @@ IDirectSoundCaptureImpl_Release( LPDIRECTSOUNDCAPTURE iface ) IDirectSoundCaptureImpl *This = (IDirectSoundCaptureImpl *)iface; TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId()); - EnterCriticalSection( &(This->lock) ); - - uRef = --(This->ref); - - LeaveCriticalSection( &(This->lock) ); - + uRef = InterlockedDecrement(&(This->ref)); if ( uRef == 0 ) { TRACE("deleting object\n"); if (This->capture_buffer) @@ -788,12 +773,8 @@ static HRESULT WINAPI IDirectSoundCaptureNotifyImpl_QueryInterface( static ULONG WINAPI IDirectSoundCaptureNotifyImpl_AddRef(LPDIRECTSOUNDNOTIFY iface) { IDirectSoundCaptureNotifyImpl *This = (IDirectSoundCaptureNotifyImpl *)iface; - DWORD ref; - TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId()); - - ref = InterlockedIncrement(&(This->ref)); - return ref; + return InterlockedIncrement(&(This->ref)); } static ULONG WINAPI IDirectSoundCaptureNotifyImpl_Release(LPDIRECTSOUNDNOTIFY iface) @@ -958,19 +939,9 @@ IDirectSoundCaptureBufferImpl_QueryInterface( static ULONG WINAPI IDirectSoundCaptureBufferImpl_AddRef( LPDIRECTSOUNDCAPTUREBUFFER8 iface ) { - ULONG uRef; IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)iface; TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId()); - - assert(This->dsound); - - EnterCriticalSection( &(This->dsound->lock) ); - - uRef = ++(This->ref); - - LeaveCriticalSection( &(This->dsound->lock) ); - - return uRef; + return InterlockedIncrement(&(This->ref)); } static ULONG WINAPI @@ -980,14 +951,7 @@ IDirectSoundCaptureBufferImpl_Release( LPDIRECTSOUNDCAPTUREBUFFER8 iface ) IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)iface; TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId()); - assert(This->dsound); - - EnterCriticalSection( &(This->dsound->lock) ); - - uRef = --(This->ref); - - LeaveCriticalSection( &(This->dsound->lock) ); - + uRef = InterlockedDecrement(&(This->ref)); if ( uRef == 0 ) { TRACE("deleting object\n"); if (This->dsound->state == STATE_CAPTURING) @@ -1613,7 +1577,7 @@ DSCCF_AddRef(LPCLASSFACTORY iface) { IClassFactoryImpl *This = (IClassFactoryImpl *)iface; TRACE("(%p) ref was %ld\n", This, This->ref); - return ++(This->ref); + return InterlockedIncrement(&(This->ref)); } static ULONG WINAPI @@ -1622,7 +1586,7 @@ DSCCF_Release(LPCLASSFACTORY iface) IClassFactoryImpl *This = (IClassFactoryImpl *)iface; /* static class, won't be freed */ TRACE("(%p) ref was %ld\n", This, This->ref); - return --(This->ref); + return InterlockedDecrement(&(This->ref)); } static HRESULT WINAPI @@ -1761,17 +1725,9 @@ IDirectSoundFullDuplexImpl_QueryInterface( static ULONG WINAPI IDirectSoundFullDuplexImpl_AddRef( LPDIRECTSOUNDFULLDUPLEX iface ) { - ULONG uRef; IDirectSoundFullDuplexImpl *This = (IDirectSoundFullDuplexImpl *)iface; TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId()); - - EnterCriticalSection( &(This->lock) ); - - uRef = ++(This->ref); - - LeaveCriticalSection( &(This->lock) ); - - return uRef; + return InterlockedIncrement(&(This->ref)); } static ULONG WINAPI @@ -1781,12 +1737,7 @@ IDirectSoundFullDuplexImpl_Release( LPDIRECTSOUNDFULLDUPLEX iface ) IDirectSoundFullDuplexImpl *This = (IDirectSoundFullDuplexImpl *)iface; TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId()); - EnterCriticalSection( &(This->lock) ); - - uRef = --(This->ref); - - LeaveCriticalSection( &(This->lock) ); - + uRef = InterlockedDecrement(&(This->ref)); if ( uRef == 0 ) { This->lock.DebugInfo->Spare[1] = 0; DeleteCriticalSection( &(This->lock) ); @@ -1849,7 +1800,7 @@ DSFDCF_AddRef(LPCLASSFACTORY iface) { IClassFactoryImpl *This = (IClassFactoryImpl *)iface; TRACE("(%p) ref was %ld\n", This, This->ref); - return ++(This->ref); + return InterlockedIncrement(&(This->ref)); } static ULONG WINAPI @@ -1858,7 +1809,7 @@ DSFDCF_Release(LPCLASSFACTORY iface) IClassFactoryImpl *This = (IClassFactoryImpl *)iface; /* static class, won't be freed */ TRACE("(%p) ref was %ld\n", This, This->ref); - return --(This->ref); + return InterlockedDecrement(&(This->ref)); } static HRESULT WINAPI diff --git a/dlls/dsound/dsound.c b/dlls/dsound/dsound.c index f1cba5e5de4..60958e52fb1 100644 --- a/dlls/dsound/dsound.c +++ b/dlls/dsound/dsound.c @@ -249,7 +249,7 @@ static ULONG WINAPI IDirectSoundImpl_AddRef( IDirectSoundImpl *This = (IDirectSoundImpl *)iface; TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId()); - return InterlockedIncrement(&This->ref); + return InterlockedIncrement(&(This->ref)); } static ULONG WINAPI IDirectSoundImpl_Release( @@ -260,7 +260,7 @@ static ULONG WINAPI IDirectSoundImpl_Release( TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId()); - ref = InterlockedDecrement(&This->ref); + ref = InterlockedDecrement(&(This->ref)); if (ref == 0) { HRESULT hres; INT i; @@ -985,7 +985,7 @@ static ULONG WINAPI IDirectSound_IUnknown_AddRef( { IDirectSound_IUnknown *This = (IDirectSound_IUnknown *)iface; TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId()); - return InterlockedIncrement(&This->ref); + return InterlockedIncrement(&(This->ref)); } static ULONG WINAPI IDirectSound_IUnknown_Release( @@ -994,7 +994,7 @@ static ULONG WINAPI IDirectSound_IUnknown_Release( IDirectSound_IUnknown *This = (IDirectSound_IUnknown *)iface; ULONG ulReturn; TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId()); - ulReturn = InterlockedDecrement(&This->ref); + ulReturn = InterlockedDecrement(&(This->ref)); if (ulReturn == 0) { IDirectSoundImpl_Release(This->pds); HeapFree(GetProcessHeap(),0,This); @@ -1063,7 +1063,7 @@ static ULONG WINAPI IDirectSound_IDirectSound_AddRef( { IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface; TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId()); - return InterlockedIncrement(&This->ref); + return InterlockedIncrement(&(This->ref)); } static ULONG WINAPI IDirectSound_IDirectSound_Release( @@ -1224,7 +1224,7 @@ static ULONG WINAPI IDirectSound8_IUnknown_AddRef( { IDirectSound_IUnknown *This = (IDirectSound_IUnknown *)iface; TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId()); - return InterlockedIncrement(&This->ref); + return InterlockedIncrement(&(This->ref)); } static ULONG WINAPI IDirectSound8_IUnknown_Release( @@ -1233,7 +1233,7 @@ static ULONG WINAPI IDirectSound8_IUnknown_Release( IDirectSound_IUnknown *This = (IDirectSound_IUnknown *)iface; ULONG ulReturn; TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId()); - ulReturn = InterlockedDecrement(&This->ref); + ulReturn = InterlockedDecrement(&(This->ref)); if (ulReturn == 0) { IDirectSoundImpl_Release(This->pds); HeapFree(GetProcessHeap(),0,This); @@ -1302,7 +1302,7 @@ static ULONG WINAPI IDirectSound8_IDirectSound_AddRef( { IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface; TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId()); - return InterlockedIncrement(&This->ref); + return InterlockedIncrement(&(This->ref)); } static ULONG WINAPI IDirectSound8_IDirectSound_Release( @@ -1311,7 +1311,7 @@ static ULONG WINAPI IDirectSound8_IDirectSound_Release( IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface; ULONG ulReturn; TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId()); - ulReturn = InterlockedDecrement(&This->ref); + ulReturn = InterlockedDecrement(&(This->ref)); if (ulReturn == 0) { IDirectSoundImpl_Release(This->pds); HeapFree(GetProcessHeap(),0,This); @@ -1463,7 +1463,7 @@ static ULONG WINAPI IDirectSound8_IDirectSound8_AddRef( { IDirectSound8_IDirectSound8 *This = (IDirectSound8_IDirectSound8 *)iface; TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId()); - return InterlockedIncrement(&This->ref); + return InterlockedIncrement(&(This->ref)); } static ULONG WINAPI IDirectSound8_IDirectSound8_Release( @@ -1472,7 +1472,7 @@ static ULONG WINAPI IDirectSound8_IDirectSound8_Release( IDirectSound8_IDirectSound8 *This = (IDirectSound8_IDirectSound8 *)iface; ULONG ulReturn; TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId()); - ulReturn = InterlockedDecrement(&This->ref); + ulReturn = InterlockedDecrement(&(This->ref)); if (ulReturn == 0) { IDirectSoundImpl_Release(This->pds); HeapFree(GetProcessHeap(),0,This); diff --git a/dlls/dsound/dsound_main.c b/dlls/dsound/dsound_main.c index 31c7c619160..96c5812262d 100644 --- a/dlls/dsound/dsound_main.c +++ b/dlls/dsound/dsound_main.c @@ -448,14 +448,14 @@ static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface) { IClassFactoryImpl *This = (IClassFactoryImpl *)iface; TRACE("(%p) ref was %ld\n", This, This->ref); - return ++(This->ref); + return InterlockedIncrement(&(This->ref)); } static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface) { IClassFactoryImpl *This = (IClassFactoryImpl *)iface; /* static class, won't be freed */ TRACE("(%p) ref was %ld\n", This, This->ref); - return --(This->ref); + return InterlockedDecrement(&(This->ref)); } static HRESULT WINAPI DSCF_CreateInstance( @@ -513,7 +513,7 @@ static ULONG WINAPI DSPCF_AddRef(LPCLASSFACTORY iface) { IClassFactoryImpl *This = (IClassFactoryImpl *)iface; TRACE("(%p) ref was %ld\n", This, This->ref); - return ++(This->ref); + return InterlockedIncrement(&(This->ref)); } static ULONG WINAPI @@ -521,7 +521,7 @@ DSPCF_Release(LPCLASSFACTORY iface) { IClassFactoryImpl *This = (IClassFactoryImpl *)iface; /* static class, won't be freed */ TRACE("(%p) ref was %ld\n", This, This->ref); - return --(This->ref); + return InterlockedDecrement(&(This->ref)); } static HRESULT WINAPI diff --git a/dlls/dsound/primary.c b/dlls/dsound/primary.c index a28a6bcef7a..4122a672311 100644 --- a/dlls/dsound/primary.c +++ b/dlls/dsound/primary.c @@ -580,12 +580,8 @@ static HRESULT WINAPI PrimaryBufferImpl_Stop(LPDIRECTSOUNDBUFFER8 iface) static DWORD WINAPI PrimaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface) { PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface; - DWORD ref; - TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId()); - ref = InterlockedIncrement(&(This->ref)); - - return ref; + return InterlockedIncrement(&(This->ref)); } static DWORD WINAPI PrimaryBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface) { diff --git a/dlls/dsound/propset.c b/dlls/dsound/propset.c index 5991df36cb4..e6025f13c06 100644 --- a/dlls/dsound/propset.c +++ b/dlls/dsound/propset.c @@ -74,11 +74,8 @@ static HRESULT WINAPI IKsBufferPropertySetImpl_QueryInterface( static ULONG WINAPI IKsBufferPropertySetImpl_AddRef(LPKSPROPERTYSET iface) { IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface; - ULONG ulReturn; - TRACE("(%p) ref was %ld\n", This, This->ref); - ulReturn = InterlockedIncrement(&(This->ref)); - return ulReturn; + return InterlockedIncrement(&(This->ref)); } static ULONG WINAPI IKsBufferPropertySetImpl_Release(LPKSPROPERTYSET iface) @@ -87,7 +84,7 @@ static ULONG WINAPI IKsBufferPropertySetImpl_Release(LPKSPROPERTYSET iface) ULONG ulReturn; TRACE("(%p) ref was %ld\n", This, This->ref); - ulReturn = InterlockedDecrement(&This->ref); + ulReturn = InterlockedDecrement(&(This->ref)); if (!ulReturn) { This->dsb->iks = 0; IDirectSoundBuffer_Release((LPDIRECTSOUND3DBUFFER)This->dsb); @@ -249,11 +246,9 @@ static HRESULT WINAPI IKsPrivatePropertySetImpl_QueryInterface( static ULONG WINAPI IKsPrivatePropertySetImpl_AddRef(LPKSPROPERTYSET iface) { IKsPrivatePropertySetImpl *This = (IKsPrivatePropertySetImpl *)iface; - ULONG ulReturn; TRACE("(%p) ref was %ld\n", This, This->ref); - ulReturn = InterlockedIncrement(&This->ref); - return ulReturn; + return InterlockedIncrement(&(This->ref)); } static ULONG WINAPI IKsPrivatePropertySetImpl_Release(LPKSPROPERTYSET iface) @@ -262,7 +257,11 @@ static ULONG WINAPI IKsPrivatePropertySetImpl_Release(LPKSPROPERTYSET iface) ULONG ulReturn; TRACE("(%p) ref was %ld\n", This, This->ref); - ulReturn = InterlockedDecrement(&This->ref); + ulReturn = InterlockedDecrement(&(This->ref)); + if (ulReturn == 0) { + HeapFree(GetProcessHeap(),0,This); + TRACE("(%p) released\n",This); + } return ulReturn; } diff --git a/dlls/dsound/sound3d.c b/dlls/dsound/sound3d.c index 93ef44f43e0..12b82023ef3 100644 --- a/dlls/dsound/sound3d.c +++ b/dlls/dsound/sound3d.c @@ -382,7 +382,7 @@ static ULONG WINAPI IDirectSound3DBufferImpl_AddRef(LPDIRECTSOUND3DBUFFER iface) ULONG ref; TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId()); - ref = InterlockedIncrement(&This->ref); + ref = InterlockedIncrement(&(This->ref)); if (!ref) { FIXME("thread-safety alert! AddRef-ing with a zero refcount!\n"); } @@ -395,7 +395,7 @@ static ULONG WINAPI IDirectSound3DBufferImpl_Release(LPDIRECTSOUND3DBUFFER iface ULONG ulReturn; TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId()); - ulReturn = InterlockedDecrement(&This->ref); + ulReturn = InterlockedDecrement(&(This->ref)); if (!ulReturn) { This->dsb->ds3db = NULL; IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER8)This->dsb); @@ -825,7 +825,7 @@ static ULONG WINAPI IDirectSound3DListenerImpl_AddRef(LPDIRECTSOUND3DLISTENER if ULONG ref; TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId()); - ref = InterlockedIncrement(&This->ref); + ref = InterlockedIncrement(&(This->ref)); if (!ref) { FIXME("thread-safety alert! AddRef-ing with a zero refcount!\n"); @@ -840,7 +840,7 @@ static ULONG WINAPI IDirectSound3DListenerImpl_Release(LPDIRECTSOUND3DLISTENER i ULONG ulReturn; TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId()); - ulReturn = InterlockedDecrement(&This->ref); + ulReturn = InterlockedDecrement(&(This->ref)); /* Free all resources */ if( ulReturn == 0 ) { -- 2.11.4.GIT