[DSOUND] clean up reference counting

Robert Reif reif at earthlink.net
Thu Feb 10 15:47:26 CST 2005


Removed printing of thread id for AddRef and Release because 
WINEDEBUG=+tid gives the same result.
General consistency cleanup.
-------------- next part --------------
Index: dlls/dsound/buffer.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/buffer.c,v
retrieving revision 1.45
diff -u -p -r1.45 buffer.c
--- dlls/dsound/buffer.c	10 Feb 2005 17:09:20 -0000	1.45
+++ dlls/dsound/buffer.c	10 Feb 2005 21:39:29 -0000
@@ -54,25 +54,25 @@ static HRESULT WINAPI IDirectSoundNotify
 
 static ULONG WINAPI IDirectSoundNotifyImpl_AddRef(LPDIRECTSOUNDNOTIFY iface)
 {
-	IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
-	TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
-	return InterlockedIncrement(&(This->ref));
+    IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
-static ULONG WINAPI IDirectSoundNotifyImpl_Release(LPDIRECTSOUNDNOTIFY iface) {
-	IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
-	ULONG ref;
-
-	TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
-
-	ref = InterlockedDecrement(&(This->ref));
-	if (ref == 0) {
-		IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER)This->dsb);
-		This->dsb->notify = NULL;
-		HeapFree(GetProcessHeap(),0,This);
-		TRACE("(%p) released\n",This);
-	}
-	return ref;
+static ULONG WINAPI IDirectSoundNotifyImpl_Release(LPDIRECTSOUNDNOTIFY iface)
+{
+    IDirectSoundNotifyImpl *This = (IDirectSoundNotifyImpl *)iface;
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
+
+    if (!ref) {
+        IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER)This->dsb);
+        This->dsb->notify = NULL;
+        HeapFree(GetProcessHeap(), 0, This);
+        TRACE("(%p) released\n", This);
+    }
+    return ref;
 }
 
 static HRESULT WINAPI IDirectSoundNotifyImpl_SetNotificationPositions(
@@ -350,22 +350,19 @@ static HRESULT WINAPI IDirectSoundBuffer
 
 static ULONG WINAPI IDirectSoundBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface)
 {
-	IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-	TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
-	return InterlockedIncrement(&(This->ref));
+    IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
 static ULONG WINAPI IDirectSoundBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
 {
-	IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-	ULONG ref;
-
-	TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
-
-	ref = InterlockedDecrement(&(This->ref));
-	if (ref)
-		return ref;
+    IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
 
+    if (!ref) {
 	DSOUND_RemoveBuffer(This->dsound, This);
 
 	This->lock.DebugInfo->Spare[1] = 0;
@@ -390,10 +387,11 @@ static ULONG WINAPI IDirectSoundBufferIm
 
 	HeapFree(GetProcessHeap(), 0, This->notifies);
 	HeapFree(GetProcessHeap(), 0, This->pwfx);
-	HeapFree(GetProcessHeap(),0,This);
+	HeapFree(GetProcessHeap(), 0, This);
 
-	TRACE("(%p) released\n",This);
-	return 0;
+	TRACE("(%p) released\n", This);
+    }
+    return ref;
 }
 
 DWORD DSOUND_CalcPlayPosition(IDirectSoundBufferImpl *This,
@@ -1246,25 +1244,25 @@ static HRESULT WINAPI SecondaryBufferImp
 
 static ULONG WINAPI SecondaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface)
 {
-	IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-	TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
-	return InterlockedIncrement(&(This->ref));
+    IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
 static ULONG WINAPI SecondaryBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
 {
-	IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
-	ULONG ref;
-	TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
+    IDirectSoundBufferImpl *This = (IDirectSoundBufferImpl *)iface;
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
 
-	ref = InterlockedDecrement(&(This->ref));
-	if (!ref) {
-		This->dsb->dsb = NULL;
-		IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER8)This->dsb);
-		HeapFree(GetProcessHeap(),0,This);
-		TRACE("(%p) released\n",This);
-	}
-	return ref;
+    if (!ref) {
+        This->dsb->dsb = NULL;
+        IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER8)This->dsb);
+        HeapFree(GetProcessHeap(), 0, This);
+        TRACE("(%p) released\n", This);
+    }
+    return ref;
 }
 
 static HRESULT WINAPI SecondaryBufferImpl_GetCaps(
Index: dlls/dsound/capture.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/capture.c,v
retrieving revision 1.43
diff -u -p -r1.43 capture.c
--- dlls/dsound/capture.c	28 Jan 2005 17:21:07 -0000	1.43
+++ dlls/dsound/capture.c	10 Feb 2005 21:39:30 -0000
@@ -363,19 +363,19 @@ static ULONG WINAPI
 IDirectSoundCaptureImpl_AddRef( LPDIRECTSOUNDCAPTURE iface )
 {
     IDirectSoundCaptureImpl *This = (IDirectSoundCaptureImpl *)iface;
-    TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
-    return InterlockedIncrement(&(This->ref));
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
 static ULONG WINAPI
 IDirectSoundCaptureImpl_Release( LPDIRECTSOUNDCAPTURE iface )
 {
-    ULONG uRef;
     IDirectSoundCaptureImpl *This = (IDirectSoundCaptureImpl *)iface;
-    TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
 
-    uRef = InterlockedDecrement(&(This->ref));
-    if ( uRef == 0 ) {
+    if (!ref) {
         TRACE("deleting object\n");
         if (This->capture_buffer)
             IDirectSoundCaptureBufferImpl_Release(
@@ -391,10 +391,9 @@ IDirectSoundCaptureImpl_Release( LPDIREC
         DeleteCriticalSection( &(This->lock) );
         HeapFree( GetProcessHeap(), 0, This );
 	dsound_capture = NULL;
-	TRACE("(%p) released\n",This);
+	TRACE("(%p) released\n", This);
     }
-
-    return uRef;
+    return ref;
 }
 
 static HRESULT WINAPI
@@ -788,25 +787,24 @@ static HRESULT WINAPI IDirectSoundCaptur
 static ULONG WINAPI IDirectSoundCaptureNotifyImpl_AddRef(LPDIRECTSOUNDNOTIFY iface)
 {
     IDirectSoundCaptureNotifyImpl *This = (IDirectSoundCaptureNotifyImpl *)iface;
-    TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
-    return InterlockedIncrement(&(This->ref));
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
 static ULONG WINAPI IDirectSoundCaptureNotifyImpl_Release(LPDIRECTSOUNDNOTIFY iface)
 {
     IDirectSoundCaptureNotifyImpl *This = (IDirectSoundCaptureNotifyImpl *)iface;
-    ULONG ref;
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
 
-    TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
-
-    ref = InterlockedDecrement(&(This->ref));
-    if (ref == 0) {
+    if (!ref) {
         if (This->dscb->hwnotify)
             IDsDriverNotify_Release(This->dscb->hwnotify);
 	This->dscb->notify=NULL;
 	IDirectSoundCaptureBuffer_Release((LPDIRECTSOUNDCAPTUREBUFFER)This->dscb);
 	HeapFree(GetProcessHeap(),0,This);
-	TRACE("(%p) released\n",This);
+	TRACE("(%p) released\n", This);
     }
     return ref;
 }
@@ -952,19 +950,19 @@ static ULONG WINAPI
 IDirectSoundCaptureBufferImpl_AddRef( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
 {
     IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)iface;
-    TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
-    return InterlockedIncrement(&(This->ref));
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
 static ULONG WINAPI
 IDirectSoundCaptureBufferImpl_Release( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
 {
-    ULONG uRef;
     IDirectSoundCaptureBufferImpl *This = (IDirectSoundCaptureBufferImpl *)iface;
-    TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
 
-    uRef = InterlockedDecrement(&(This->ref));
-    if ( uRef == 0 ) {
+    if (!ref) {
         TRACE("deleting object\n");
 	if (This->dsound->state == STATE_CAPTURING)
 	    This->dsound->state = STATE_STOPPING;
@@ -993,10 +991,9 @@ IDirectSoundCaptureBufferImpl_Release( L
 
 	HeapFree(GetProcessHeap(), 0, This->notifies);
         HeapFree( GetProcessHeap(), 0, This );
-	TRACE("(%p) released\n",This);
+	TRACE("(%p) released\n", This);
     }
-
-    return uRef;
+    return ref;
 }
 
 static HRESULT WINAPI
@@ -1578,17 +1575,19 @@ static ULONG WINAPI
 DSCCF_AddRef(LPCLASSFACTORY iface)
 {
     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
-    TRACE("(%p) ref was %ld\n", This, This->ref);
-    return InterlockedIncrement(&(This->ref));
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
 static ULONG WINAPI
 DSCCF_Release(LPCLASSFACTORY iface)
 {
     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
     /* static class, won't be  freed */
-    TRACE("(%p) ref was %ld\n", This, This->ref);
-    return InterlockedDecrement(&(This->ref));
+    return ref;
 }
 
 static HRESULT WINAPI
@@ -1729,26 +1728,25 @@ static ULONG WINAPI
 IDirectSoundFullDuplexImpl_AddRef( LPDIRECTSOUNDFULLDUPLEX iface )
 {
     IDirectSoundFullDuplexImpl *This = (IDirectSoundFullDuplexImpl *)iface;
-    TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
-    return InterlockedIncrement(&(This->ref));
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
 static ULONG WINAPI
 IDirectSoundFullDuplexImpl_Release( LPDIRECTSOUNDFULLDUPLEX iface )
 {
-    ULONG uRef;
     IDirectSoundFullDuplexImpl *This = (IDirectSoundFullDuplexImpl *)iface;
-    TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
 
-    uRef = InterlockedDecrement(&(This->ref));
-    if ( uRef == 0 ) {
+    if (!ref) {
         This->lock.DebugInfo->Spare[1] = 0;
         DeleteCriticalSection( &(This->lock) );
         HeapFree( GetProcessHeap(), 0, This );
-	TRACE("(%p) released\n",This);
+	TRACE("(%p) released\n", This);
     }
-
-    return uRef;
+    return ref;
 }
 
 static HRESULT WINAPI
Index: dlls/dsound/dsound.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/dsound.c,v
retrieving revision 1.28
diff -u -p -r1.28 dsound.c
--- dlls/dsound/dsound.c	1 Feb 2005 18:47:23 -0000	1.28
+++ dlls/dsound/dsound.c	10 Feb 2005 21:39:31 -0000
@@ -230,21 +230,19 @@ static ULONG WINAPI IDirectSoundImpl_Add
     LPDIRECTSOUND8 iface)
 {
     IDirectSoundImpl *This = (IDirectSoundImpl *)iface;
-    TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId());
-
-    return InterlockedIncrement(&(This->ref));
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
 static ULONG WINAPI IDirectSoundImpl_Release(
     LPDIRECTSOUND8 iface)
 {
     IDirectSoundImpl *This = (IDirectSoundImpl *)iface;
-    ULONG ref;
-    TRACE("(%p) ref was %ld, thread is %04lx\n",
-          This, This->ref, GetCurrentThreadId());
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
 
-    ref = InterlockedDecrement(&(This->ref));
-    if (ref == 0) {
+    if (!ref) {
         HRESULT hres;
         INT i;
 
@@ -291,9 +289,8 @@ static ULONG WINAPI IDirectSoundImpl_Rel
         DeleteCriticalSection(&This->mixlock);
         HeapFree(GetProcessHeap(),0,This);
         dsound = NULL;
-        TRACE("(%p) released\n",This);
+        TRACE("(%p) released\n", This);
     }
-
     return ref;
 }
 
@@ -971,23 +968,23 @@ static ULONG WINAPI IDirectSound_IUnknow
     LPUNKNOWN iface)
 {
     IDirectSound_IUnknown *This = (IDirectSound_IUnknown *)iface;
-    TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId());
-    return InterlockedIncrement(&(This->ref));
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
 static ULONG WINAPI IDirectSound_IUnknown_Release(
     LPUNKNOWN iface)
 {
     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));
-    if (ulReturn == 0) {
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
+    if (!ref) {
         IDirectSoundImpl_Release(This->pds);
-        HeapFree(GetProcessHeap(),0,This);
-        TRACE("(%p) released\n",This);
+        HeapFree(GetProcessHeap(), 0, This);
+        TRACE("(%p) released\n", This);
     }
-    return ulReturn;
+    return ref;
 }
 
 static IUnknownVtbl DirectSound_Unknown_Vtbl =
@@ -1049,23 +1046,23 @@ static ULONG WINAPI IDirectSound_IDirect
     LPDIRECTSOUND iface)
 {
     IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
-    TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId());
-    return InterlockedIncrement(&(This->ref));
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
 static ULONG WINAPI IDirectSound_IDirectSound_Release(
     LPDIRECTSOUND iface)
 {
     IDirectSound_IDirectSound *This = (IDirectSound_IDirectSound *)iface;
-    ULONG ulReturn;
-    TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId());
-    ulReturn = InterlockedDecrement(&This->ref);
-    if (ulReturn == 0) {
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
+    if (!ref) {
         IDirectSoundImpl_Release(This->pds);
-        HeapFree(GetProcessHeap(),0,This);
-        TRACE("(%p) released\n",This);
+        HeapFree(GetProcessHeap(), 0, This);
+        TRACE("(%p) released\n", This);
     }
-    return ulReturn;
+    return ref;
 }
 
 static HRESULT WINAPI IDirectSound_IDirectSound_CreateSoundBuffer(
@@ -1210,23 +1207,23 @@ static ULONG WINAPI IDirectSound8_IUnkno
     LPUNKNOWN iface)
 {
     IDirectSound_IUnknown *This = (IDirectSound_IUnknown *)iface;
-    TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId());
-    return InterlockedIncrement(&(This->ref));
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
 static ULONG WINAPI IDirectSound8_IUnknown_Release(
     LPUNKNOWN iface)
 {
     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));
-    if (ulReturn == 0) {
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
+    if (!ref) {
         IDirectSoundImpl_Release(This->pds);
-        HeapFree(GetProcessHeap(),0,This);
-        TRACE("(%p) released\n",This);
+        HeapFree(GetProcessHeap(), 0, This);
+        TRACE("(%p) released\n", This);
     }
-    return ulReturn;
+    return ref;
 }
 
 static IUnknownVtbl DirectSound8_Unknown_Vtbl =
@@ -1288,23 +1285,23 @@ static ULONG WINAPI IDirectSound8_IDirec
     LPDIRECTSOUND iface)
 {
     IDirectSound8_IDirectSound *This = (IDirectSound8_IDirectSound *)iface;
-    TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId());
-    return InterlockedIncrement(&(This->ref));
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
 static ULONG WINAPI IDirectSound8_IDirectSound_Release(
     LPDIRECTSOUND iface)
 {
     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));
-    if (ulReturn == 0) {
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
+    if (!ref) {
         IDirectSoundImpl_Release(This->pds);
-        HeapFree(GetProcessHeap(),0,This);
-        TRACE("(%p) released\n",This);
+        HeapFree(GetProcessHeap(), 0, This);
+        TRACE("(%p) released\n", This);
     }
-    return ulReturn;
+    return ref;
 }
 
 static HRESULT WINAPI IDirectSound8_IDirectSound_CreateSoundBuffer(
@@ -1449,23 +1446,23 @@ static ULONG WINAPI IDirectSound8_IDirec
     LPDIRECTSOUND8 iface)
 {
     IDirectSound8_IDirectSound8 *This = (IDirectSound8_IDirectSound8 *)iface;
-    TRACE("(%p) ref was %ld, thread is %04lx\n", This, This->ref, GetCurrentThreadId());
-    return InterlockedIncrement(&(This->ref));
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
 static ULONG WINAPI IDirectSound8_IDirectSound8_Release(
     LPDIRECTSOUND8 iface)
 {
     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));
-    if (ulReturn == 0) {
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
+    if (!ref) {
         IDirectSoundImpl_Release(This->pds);
-        HeapFree(GetProcessHeap(),0,This);
-        TRACE("(%p) released\n",This);
+        HeapFree(GetProcessHeap(), 0, This);
+        TRACE("(%p) released\n", This);
     }
-    return ulReturn;
+    return ref;
 }
 
 static HRESULT WINAPI IDirectSound8_IDirectSound8_CreateSoundBuffer(
Index: dlls/dsound/dsound_main.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/dsound_main.c,v
retrieving revision 1.114
diff -u -p -r1.114 dsound_main.c
--- dlls/dsound/dsound_main.c	28 Jan 2005 17:21:07 -0000	1.114
+++ dlls/dsound/dsound_main.c	10 Feb 2005 21:39:32 -0000
@@ -427,18 +427,21 @@ DSCF_QueryInterface(LPCLASSFACTORY iface
 	return E_NOINTERFACE;
 }
 
-static ULONG WINAPI
-DSCF_AddRef(LPCLASSFACTORY iface) {
-	IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
-	TRACE("(%p) ref was %ld\n", This, This->ref);
-	return InterlockedIncrement(&(This->ref));
+static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
+{
+    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return 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 InterlockedDecrement(&(This->ref));
+static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
+{
+    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
+    /* static class, won't be freed */
+    return ref;
 }
 
 static HRESULT WINAPI DSCF_CreateInstance(
@@ -495,19 +498,21 @@ DSPCF_QueryInterface(LPCLASSFACTORY ifac
 	return E_NOINTERFACE;
 }
 
-static ULONG WINAPI
-DSPCF_AddRef(LPCLASSFACTORY iface) {
-	IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
-	TRACE("(%p) ref was %ld\n", This, This->ref);
-	return InterlockedIncrement(&(This->ref));
+static ULONG WINAPI DSPCF_AddRef(LPCLASSFACTORY iface)
+{
+    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
-static ULONG WINAPI
-DSPCF_Release(LPCLASSFACTORY iface) {
-	IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
-	/* static class, won't be  freed */
-	TRACE("(%p) ref was %ld\n", This, This->ref);
-	return InterlockedDecrement(&(This->ref));
+static ULONG WINAPI DSPCF_Release(LPCLASSFACTORY iface)
+{
+    IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
+    /* static class, won't be freed */
+    return ref;
 }
 
 static HRESULT WINAPI
Index: dlls/dsound/primary.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/primary.c,v
retrieving revision 1.41
diff -u -p -r1.41 primary.c
--- dlls/dsound/primary.c	9 Feb 2005 14:05:00 -0000	1.41
+++ dlls/dsound/primary.c	10 Feb 2005 21:39:33 -0000
@@ -562,26 +562,26 @@ static HRESULT WINAPI PrimaryBufferImpl_
 	return DS_OK;
 }
 
-static ULONG WINAPI PrimaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface) {
-	PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface;
-	TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
-	return InterlockedIncrement(&(This->ref));
+static ULONG WINAPI PrimaryBufferImpl_AddRef(LPDIRECTSOUNDBUFFER8 iface)
+{
+    PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface;
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
-static ULONG WINAPI PrimaryBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface) {
-	PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface;
-	DWORD ref;
+static ULONG WINAPI PrimaryBufferImpl_Release(LPDIRECTSOUNDBUFFER8 iface)
+{
+    PrimaryBufferImpl *This = (PrimaryBufferImpl *)iface;
+    DWORD ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
 
-	TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
-	ref = InterlockedDecrement(&(This->ref));
-
-	if (ref == 0) {
-		This->dsound->primary = NULL;
-		HeapFree(GetProcessHeap(),0,This);
-		TRACE("(%p) released\n",This);
-	}
-
-	return ref;
+    if (!ref) {
+        This->dsound->primary = NULL;
+        HeapFree(GetProcessHeap(), 0, This);
+        TRACE("(%p) released\n", This);
+    }
+    return ref;
 }
 
 static HRESULT WINAPI PrimaryBufferImpl_GetCurrentPosition(
Index: dlls/dsound/propset.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/propset.c,v
retrieving revision 1.32
diff -u -p -r1.32 propset.c
--- dlls/dsound/propset.c	28 Jan 2005 17:21:07 -0000	1.32
+++ dlls/dsound/propset.c	10 Feb 2005 21:39:34 -0000
@@ -64,24 +64,24 @@ static HRESULT WINAPI IKsBufferPropertyS
 static ULONG WINAPI IKsBufferPropertySetImpl_AddRef(LPKSPROPERTYSET iface)
 {
     IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
-    TRACE("(%p) ref was %ld\n", This, This->ref);
-    return InterlockedIncrement(&(This->ref));
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
 static ULONG WINAPI IKsBufferPropertySetImpl_Release(LPKSPROPERTYSET iface)
 {
     IKsBufferPropertySetImpl *This = (IKsBufferPropertySetImpl *)iface;
-    ULONG ulReturn;
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
 
-    TRACE("(%p) ref was %ld\n", This, This->ref);
-    ulReturn = InterlockedDecrement(&(This->ref));
-    if (!ulReturn) {
+    if (!ref) {
 	This->dsb->iks = 0;
 	IDirectSoundBuffer_Release((LPDIRECTSOUND3DBUFFER)This->dsb);
-	HeapFree(GetProcessHeap(),0,This);
-	TRACE("(%p) released\n",This);
+	HeapFree(GetProcessHeap(), 0, This);
+	TRACE("(%p) released\n", This);
     }
-    return ulReturn;
+    return ref;
 }
 
 static HRESULT WINAPI IKsBufferPropertySetImpl_Get(
@@ -248,22 +248,22 @@ static HRESULT WINAPI IKsPrivateProperty
 static ULONG WINAPI IKsPrivatePropertySetImpl_AddRef(LPKSPROPERTYSET iface)
 {
     IKsPrivatePropertySetImpl *This = (IKsPrivatePropertySetImpl *)iface;
-    TRACE("(%p) ref was %ld\n", This, This->ref);
-    return InterlockedIncrement(&(This->ref));
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
 static ULONG WINAPI IKsPrivatePropertySetImpl_Release(LPKSPROPERTYSET iface)
 {
     IKsPrivatePropertySetImpl *This = (IKsPrivatePropertySetImpl *)iface;
-    ULONG ulReturn;
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
 
-    TRACE("(%p) ref was %ld\n", This, This->ref);
-    ulReturn = InterlockedDecrement(&(This->ref));
-    if (ulReturn == 0) {
-        HeapFree(GetProcessHeap(),0,This);
-	TRACE("(%p) released\n",This);
+    if (!ref) {
+        HeapFree(GetProcessHeap(), 0, This);
+	TRACE("(%p) released\n", This);
     }
-    return ulReturn;
+    return ref;
 }
 
 static HRESULT WINAPI DSPROPERTY_WaveDeviceMappingA(
Index: dlls/dsound/sound3d.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/sound3d.c,v
retrieving revision 1.38
diff -u -p -r1.38 sound3d.c
--- dlls/dsound/sound3d.c	24 Jan 2005 13:31:27 -0000	1.38
+++ dlls/dsound/sound3d.c	10 Feb 2005 21:39:34 -0000
@@ -364,26 +364,25 @@ static HRESULT WINAPI IDirectSound3DBuff
 
 static ULONG WINAPI IDirectSound3DBufferImpl_AddRef(LPDIRECTSOUND3DBUFFER iface)
 {
-	IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
-	TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
-	return InterlockedIncrement(&(This->ref));
+    IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
 static ULONG WINAPI IDirectSound3DBufferImpl_Release(LPDIRECTSOUND3DBUFFER iface)
 {
-	IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
-	ULONG ulReturn;
-
-	TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
-	ulReturn = InterlockedDecrement(&(This->ref));
-	if (!ulReturn) {
-		This->dsb->ds3db = NULL;
-		IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER8)This->dsb);
-		HeapFree(GetProcessHeap(),0,This);
-		TRACE("(%p) released\n",This);
-	}
-
-	return ulReturn;
+    IDirectSound3DBufferImpl *This = (IDirectSound3DBufferImpl *)iface;
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
+
+    if (!ref) {
+        This->dsb->ds3db = NULL;
+        IDirectSoundBuffer_Release((LPDIRECTSOUNDBUFFER8)This->dsb);
+        HeapFree(GetProcessHeap(), 0, This);
+        TRACE("(%p) released\n", This);
+    }
+    return ref;
 }
 
 /* IDirectSound3DBuffer methods */
@@ -801,27 +800,24 @@ static HRESULT WINAPI IDirectSound3DList
 
 static ULONG WINAPI IDirectSound3DListenerImpl_AddRef(LPDIRECTSOUND3DLISTENER iface)
 {
-	IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
-	TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
-	return InterlockedIncrement(&(This->ref));
+    IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
+    ULONG ref = InterlockedIncrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref - 1);
+    return ref;
 }
 
 static ULONG WINAPI IDirectSound3DListenerImpl_Release(LPDIRECTSOUND3DLISTENER iface)
 {
-	IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
-	ULONG ulReturn;
-
-	TRACE("(%p) ref was %ld, thread is %04lx\n",This, This->ref, GetCurrentThreadId());
-	ulReturn = InterlockedDecrement(&(This->ref));
-
-	/* Free all resources */
-	if( ulReturn == 0 ) {
-		This->dsound->listener = 0;
-		HeapFree(GetProcessHeap(),0,This);
-		TRACE("(%p) released\n",This);
-	}
-
-	return ulReturn;
+    IDirectSound3DListenerImpl *This = (IDirectSound3DListenerImpl *)iface;
+    ULONG ref = InterlockedDecrement(&(This->ref));
+    TRACE("(%p) ref was %ld\n", This, ref + 1);
+
+    if (!ref) {
+        This->dsound->listener = 0;
+        HeapFree(GetProcessHeap(), 0, This);
+        TRACE("(%p) released\n", This);
+    }
+    return ref;
 }
 
 /* IDirectSound3DListener methods */


More information about the wine-patches mailing list