dsound reference count cleanup

Robert Reif reif at earthlink.net
Wed Sep 15 20:26:08 CDT 2004


Cleanup reference counting.
-------------- next part --------------
Index: dlls/dsound/buffer.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/buffer.c,v
retrieving revision 1.37
diff -u -r1.37 buffer.c
--- dlls/dsound/buffer.c	10 Sep 2004 22:30:05 -0000	1.37
+++ dlls/dsound/buffer.c	16 Sep 2004 01:20:18 -0000
@@ -70,12 +70,10 @@
 
 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) {
Index: dlls/dsound/capture.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/capture.c,v
retrieving revision 1.33
diff -u -r1.33 capture.c
--- dlls/dsound/capture.c	10 Sep 2004 22:30:05 -0000	1.33
+++ dlls/dsound/capture.c	16 Sep 2004 01:20:19 -0000
@@ -373,19 +373,9 @@
 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 *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 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 @@
 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 *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 @@
 {
     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 @@
     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 @@
 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 *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 @@
 {
     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 @@
     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 
Index: dlls/dsound/dsound.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/dsound.c,v
retrieving revision 1.22
diff -u -r1.22 dsound.c
--- dlls/dsound/dsound.c	10 Sep 2004 22:30:05 -0000	1.22
+++ dlls/dsound/dsound.c	16 Sep 2004 01:20:21 -0000
@@ -249,7 +249,7 @@
     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 @@
     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 @@
 {
     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 @@
     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 @@
 {
     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 @@
 {
     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 @@
     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 @@
 {
     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 @@
     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 @@
 {
     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 @@
     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);
Index: dlls/dsound/dsound_main.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/dsound_main.c,v
retrieving revision 1.108
diff -u -r1.108 dsound_main.c
--- dlls/dsound/dsound_main.c	9 Sep 2004 20:17:08 -0000	1.108
+++ dlls/dsound/dsound_main.c	16 Sep 2004 01:20:21 -0000
@@ -448,14 +448,14 @@
 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 @@
 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 @@
 	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
Index: dlls/dsound/primary.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/primary.c,v
retrieving revision 1.34
diff -u -r1.34 primary.c
--- dlls/dsound/primary.c	10 Sep 2004 19:34:01 -0000	1.34
+++ dlls/dsound/primary.c	16 Sep 2004 01:20:22 -0000
@@ -580,12 +580,8 @@
 
 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) {
Index: dlls/dsound/propset.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/propset.c,v
retrieving revision 1.24
diff -u -r1.24 propset.c
--- dlls/dsound/propset.c	9 Sep 2004 20:17:08 -0000	1.24
+++ dlls/dsound/propset.c	16 Sep 2004 01:20:23 -0000
@@ -74,11 +74,8 @@
 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 @@
     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 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 @@
     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;
 }
 
Index: dlls/dsound/sound3d.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/sound3d.c,v
retrieving revision 1.34
diff -u -r1.34 sound3d.c
--- dlls/dsound/sound3d.c	9 Sep 2004 20:17:08 -0000	1.34
+++ dlls/dsound/sound3d.c	16 Sep 2004 01:20:24 -0000
@@ -382,7 +382,7 @@
 	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 @@
 	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 @@
 	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 @@
 	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 ) {


More information about the wine-patches mailing list