Commit 1727eb48 authored by James Hawkins's avatar James Hawkins Committed by Alexandre Julliard

Properly implement DllCanUnloadNow ref counting.

parent 3b38dc68
......@@ -58,6 +58,8 @@ ULONG WINAPI IDirectMusicAudioPathImpl_IUnknown_AddRef (LPUNKNOWN iface) {
TRACE("(%p): AddRef from %ld\n", This, ref - 1);
DMIME_LockModule();
return ref;
}
......@@ -65,12 +67,16 @@ ULONG WINAPI IDirectMusicAudioPathImpl_IUnknown_Release (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicAudioPathImpl, UnknownVtbl, iface);
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p): ReleaseRef to %ld\n", This, ref);
if (ref == 0) {
if (This->pDSBuffer) {
IDirectSoundBuffer8_Release(This->pDSBuffer);
}
HeapFree(GetProcessHeap(), 0, This);
}
DMIME_UnlockModule();
return ref;
}
......
......@@ -949,6 +949,12 @@ extern HRESULT WINAPI IDirectMusicWaveTrack_IPersistStream_Load (LPPERSISTSTREAM
extern HRESULT WINAPI IDirectMusicWaveTrack_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty);
extern HRESULT WINAPI IDirectMusicWaveTrack_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize);
/**********************************************************************
* Dll lifetime tracking declaration for dmime.dll
*/
extern LONG DMIME_refCount;
static inline void DMIME_LockModule() { InterlockedIncrement( &DMIME_refCount ); }
static inline void DMIME_UnlockModule() { InterlockedDecrement( &DMIME_refCount ); }
/*****************************************************************************
* Misc.
......
......@@ -58,6 +58,8 @@ ULONG WINAPI IDirectMusicGraphImpl_IUnknown_AddRef (LPUNKNOWN iface) {
TRACE("(%p): AddRef from %ld\n", This, ref - 1);
DMIME_LockModule();
return ref;
}
......@@ -65,9 +67,13 @@ ULONG WINAPI IDirectMusicGraphImpl_IUnknown_Release (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicGraphImpl, UnknownVtbl, iface);
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p): ReleaseRef to %ld\n", This, ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMIME_UnlockModule();
return ref;
}
......
......@@ -55,6 +55,8 @@ ULONG WINAPI IDirectMusicLyricsTrack_IUnknown_AddRef (LPUNKNOWN iface) {
TRACE("(%p): AddRef from %ld\n", This, ref - 1);
DMIME_LockModule();
return ref;
}
......@@ -62,9 +64,13 @@ ULONG WINAPI IDirectMusicLyricsTrack_IUnknown_Release (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicLyricsTrack, UnknownVtbl, iface);
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p): ReleaseRef to %ld\n", This, ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMIME_UnlockModule();
return ref;
}
......
......@@ -55,6 +55,8 @@ ULONG WINAPI IDirectMusicMarkerTrack_IUnknown_AddRef (LPUNKNOWN iface) {
TRACE("(%p): AddRef from %ld\n", This, ref - 1);
DMIME_LockModule();
return ref;
}
......@@ -62,9 +64,13 @@ ULONG WINAPI IDirectMusicMarkerTrack_IUnknown_Release (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicMarkerTrack, UnknownVtbl, iface);
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p): ReleaseRef to %ld\n", This, ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMIME_UnlockModule();
return ref;
}
......
......@@ -55,6 +55,8 @@ ULONG WINAPI IDirectMusicParamControlTrack_IUnknown_AddRef (LPUNKNOWN iface) {
TRACE("(%p): AddRef from %ld\n", This, ref - 1);
DMIME_LockModule();
return ref;
}
......@@ -62,9 +64,13 @@ ULONG WINAPI IDirectMusicParamControlTrack_IUnknown_Release (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicParamControlTrack, UnknownVtbl, iface);
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p): ReleaseRef to %ld\n", This, ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMIME_UnlockModule();
return ref;
}
......
......@@ -43,6 +43,8 @@ ULONG WINAPI IDirectMusicPatternTrackImpl_AddRef (LPDIRECTMUSICPATTERNTRACK ifac
TRACE("(%p): AddRef from %ld\n", This, ref - 1);
DMIME_LockModule();
return ref;
}
......@@ -50,9 +52,13 @@ ULONG WINAPI IDirectMusicPatternTrackImpl_Release (LPDIRECTMUSICPATTERNTRACK ifa
IDirectMusicPatternTrackImpl *This = (IDirectMusicPatternTrackImpl *)iface;
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p): ReleaseRef to %ld\n", This, ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMIME_UnlockModule();
return ref;
}
......
......@@ -186,6 +186,8 @@ ULONG WINAPI IDirectMusicPerformance8Impl_AddRef (LPDIRECTMUSICPERFORMANCE8 ifac
TRACE("(%p): AddRef from %ld\n", This, ref - 1);
DMIME_LockModule();
return ref;
}
......@@ -193,10 +195,14 @@ ULONG WINAPI IDirectMusicPerformance8Impl_Release (LPDIRECTMUSICPERFORMANCE8 ifa
IDirectMusicPerformance8Impl *This = (IDirectMusicPerformance8Impl *)iface;
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p): ReleaseRef to %ld\n", This, ref);
if (ref == 0) {
DeleteCriticalSection(&This->safe);
HeapFree(GetProcessHeap(), 0, This);
}
DMIME_UnlockModule();
return ref;
}
......
......@@ -61,6 +61,8 @@ ULONG WINAPI IDirectMusicSegment8Impl_IUnknown_AddRef (LPUNKNOWN iface) {
TRACE("(%p): AddRef from %ld\n", This, ref - 1);
DMIME_LockModule();
return ref;
}
......@@ -68,9 +70,13 @@ ULONG WINAPI IDirectMusicSegment8Impl_IUnknown_Release (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicSegment8Impl, UnknownVtbl, iface);
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p): ReleaseRef to %ld\n", This, ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMIME_UnlockModule();
return ref;
}
......
......@@ -43,6 +43,8 @@ ULONG WINAPI IDirectMusicSegmentState8Impl_AddRef (LPDIRECTMUSICSEGMENTSTATE8 if
TRACE("(%p): AddRef from %ld\n", This, ref - 1);
DMIME_LockModule();
return ref;
}
......@@ -50,9 +52,13 @@ ULONG WINAPI IDirectMusicSegmentState8Impl_Release (LPDIRECTMUSICSEGMENTSTATE8 i
IDirectMusicSegmentState8Impl *This = (IDirectMusicSegmentState8Impl *)iface;
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p): ReleaseRef to %ld\n", This, ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMIME_UnlockModule();
return ref;
}
......
......@@ -56,6 +56,8 @@ ULONG WINAPI IDirectMusicSegTriggerTrack_IUnknown_AddRef (LPUNKNOWN iface) {
TRACE("(%p): AddRef from %ld\n", This, ref - 1);
DMIME_LockModule();
return ref;
}
......@@ -63,9 +65,13 @@ ULONG WINAPI IDirectMusicSegTriggerTrack_IUnknown_Release (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicSegTriggerTrack, UnknownVtbl, iface);
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p): ReleaseRef to %ld\n", This, ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMIME_UnlockModule();
return ref;
}
......
......@@ -55,6 +55,8 @@ ULONG WINAPI IDirectMusicSeqTrack_IUnknown_AddRef (LPUNKNOWN iface) {
TRACE("(%p): AddRef from %ld\n", This, ref - 1);
DMIME_LockModule();
return ref;
}
......@@ -62,9 +64,13 @@ ULONG WINAPI IDirectMusicSeqTrack_IUnknown_Release (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicSeqTrack, UnknownVtbl, iface);
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p): ReleaseRef to %ld\n", This, ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMIME_UnlockModule();
return ref;
}
......
......@@ -55,6 +55,8 @@ ULONG WINAPI IDirectMusicSysExTrack_IUnknown_AddRef (LPUNKNOWN iface) {
TRACE("(%p): AddRef from %ld\n", This, ref - 1);
DMIME_LockModule();
return ref;
}
......@@ -62,9 +64,13 @@ ULONG WINAPI IDirectMusicSysExTrack_IUnknown_Release (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicSysExTrack, UnknownVtbl, iface);
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p): ReleaseRef to %ld\n", This, ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMIME_UnlockModule();
return ref;
}
......
......@@ -56,6 +56,8 @@ ULONG WINAPI IDirectMusicTempoTrack_IUnknown_AddRef (LPUNKNOWN iface) {
TRACE("(%p): AddRef from %ld\n", This, ref - 1);
DMIME_LockModule();
return ref;
}
......@@ -63,9 +65,13 @@ ULONG WINAPI IDirectMusicTempoTrack_IUnknown_Release (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicTempoTrack, UnknownVtbl, iface);
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p): ReleaseRef to %ld\n", This, ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMIME_UnlockModule();
return ref;
}
......
......@@ -55,6 +55,8 @@ ULONG WINAPI IDirectMusicTimeSigTrack_IUnknown_AddRef (LPUNKNOWN iface) {
TRACE("(%p): AddRef from %ld\n", This, ref - 1);
DMIME_LockModule();
return ref;
}
......@@ -62,9 +64,13 @@ ULONG WINAPI IDirectMusicTimeSigTrack_IUnknown_Release (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicTimeSigTrack, UnknownVtbl, iface);
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p): ReleaseRef to %ld\n", This, ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMIME_UnlockModule();
return ref;
}
......
......@@ -42,6 +42,8 @@ ULONG WINAPI IDirectMusicTool8Impl_AddRef (LPDIRECTMUSICTOOL8 iface) {
TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
DMIME_LockModule();
return ref;
}
......@@ -49,9 +51,13 @@ ULONG WINAPI IDirectMusicTool8Impl_Release (LPDIRECTMUSICTOOL8 iface) {
IDirectMusicTool8Impl *This = (IDirectMusicTool8Impl *)iface;
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMIME_UnlockModule();
return ref;
}
......
......@@ -55,6 +55,8 @@ ULONG WINAPI IDirectMusicWaveTrack_IUnknown_AddRef (LPUNKNOWN iface) {
TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
DMIME_LockModule();
return ref;
}
......@@ -62,9 +64,13 @@ ULONG WINAPI IDirectMusicWaveTrack_IUnknown_Release (LPUNKNOWN iface) {
ICOM_THIS_MULTI(IDirectMusicWaveTrack, UnknownVtbl, iface);
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMIME_UnlockModule();
return ref;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment