Properly implement DllCanUnloadNow ref counting.

This commit is contained in:
James Hawkins 2005-01-31 20:40:26 +00:00 committed by Alexandre Julliard
parent 932a65dddc
commit 7946edf27a
8 changed files with 116 additions and 57 deletions

View File

@ -60,6 +60,8 @@ ULONG WINAPI IDirectMusicBandImpl_IUnknown_AddRef (LPUNKNOWN iface) {
TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
DMBAND_LockModule();
return ref;
}
@ -72,6 +74,9 @@ ULONG WINAPI IDirectMusicBandImpl_IUnknown_Release (LPUNKNOWN iface) {
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMBAND_UnlockModule();
return ref;
}

View File

@ -55,6 +55,8 @@ ULONG WINAPI IDirectMusicBandTrack_IUnknown_AddRef (LPUNKNOWN iface) {
TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
DMBAND_LockModule();
return ref;
}
@ -67,6 +69,9 @@ ULONG WINAPI IDirectMusicBandTrack_IUnknown_Release (LPUNKNOWN iface) {
if (ref == 0) {
HeapFree(GetProcessHeap(), 0, This);
}
DMBAND_UnlockModule();
return ref;
}

View File

@ -21,10 +21,10 @@
WINE_DEFAULT_DEBUG_CHANNEL(dmband);
LONG DMBAND_refCount = 0;
typedef struct {
/* IUnknown fields */
IClassFactoryVtbl *lpVtbl;
DWORD ref;
} IClassFactoryImpl;
/******************************************************************
@ -32,31 +32,39 @@ typedef struct {
*/
static HRESULT WINAPI BandCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %s, %p): stub\n",This, debugstr_dmguid(riid), ppobj);
FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
if (ppobj == NULL) return E_POINTER;
return E_NOINTERFACE;
}
static ULONG WINAPI BandCF_AddRef(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return InterlockedIncrement(&This->ref);
DMBAND_LockModule();
return 2; /* non-heap based object */
}
static ULONG WINAPI BandCF_Release(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
/* static class, won't be freed */
return InterlockedDecrement(&This->ref);
DMBAND_UnlockModule();
return 1; /* non-heap based object */
}
static HRESULT WINAPI BandCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
TRACE ("(%p, %p, %s, %p)\n", This, pOuter, debugstr_dmguid(riid), ppobj);
TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
return DMUSIC_CreateDirectMusicBandImpl (riid, ppobj, pOuter);
}
static HRESULT WINAPI BandCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %d): stub\n", This, dolock);
TRACE("(%d)\n", dolock);
if (dolock)
DMBAND_LockModule();
else
DMBAND_UnlockModule();
return S_OK;
}
@ -68,7 +76,7 @@ static IClassFactoryVtbl BandCF_Vtbl = {
BandCF_LockServer
};
static IClassFactoryImpl Band_CF = {&BandCF_Vtbl, 1 };
static IClassFactoryImpl Band_CF = {&BandCF_Vtbl};
/******************************************************************
@ -76,32 +84,39 @@ static IClassFactoryImpl Band_CF = {&BandCF_Vtbl, 1 };
*/
static HRESULT WINAPI BandTrackCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %s, %p): stub\n", This, debugstr_dmguid(riid), ppobj);
FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
if (ppobj == NULL) return E_POINTER;
return E_NOINTERFACE;
}
static ULONG WINAPI BandTrackCF_AddRef(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return InterlockedIncrement(&This->ref);
DMBAND_LockModule();
return 2; /* non-heap based object */
}
static ULONG WINAPI BandTrackCF_Release(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
/* static class, won't be freed */
return InterlockedDecrement(&This->ref);
DMBAND_UnlockModule();
return 1; /* non-heap based object */
}
static HRESULT WINAPI BandTrackCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
TRACE ("(%p, %p, %s, %p)\n", This, pOuter, debugstr_dmguid(riid), ppobj);
TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
return DMUSIC_CreateDirectMusicBandTrack (riid, ppobj, pOuter);
}
static HRESULT WINAPI BandTrackCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %d): stub\n", This, dolock);
TRACE("(%d)\n", dolock);
if (dolock)
DMBAND_LockModule();
else
DMBAND_UnlockModule();
return S_OK;
}
@ -113,7 +128,7 @@ static IClassFactoryVtbl BandTrackCF_Vtbl = {
BandTrackCF_LockServer
};
static IClassFactoryImpl BandTrack_CF = {&BandTrackCF_Vtbl, 1 };
static IClassFactoryImpl BandTrack_CF = {&BandTrackCF_Vtbl};
/******************************************************************
* DllMain
@ -138,8 +153,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
*
*/
HRESULT WINAPI DMBAND_DllCanUnloadNow(void) {
FIXME("(void): stub\n");
return S_FALSE;
return DMBAND_refCount != 0 ? S_FALSE : S_OK;
}

View File

@ -192,6 +192,12 @@ extern HRESULT WINAPI IDirectMusicBandTrack_IPersistStream_Load (LPPERSISTSTREAM
extern HRESULT WINAPI IDirectMusicBandTrack_IPersistStream_Save (LPPERSISTSTREAM iface, IStream* pStm, BOOL fClearDirty);
extern HRESULT WINAPI IDirectMusicBandTrack_IPersistStream_GetSizeMax (LPPERSISTSTREAM iface, ULARGE_INTEGER* pcbSize);
/**********************************************************************
* Dll lifetime tracking declaration for dmband.dll
*/
extern LONG DMBAND_refCount;
static inline void DMBAND_LockModule() { InterlockedIncrement( &DMBAND_refCount ); }
static inline void DMBAND_UnlockModule() { InterlockedDecrement( &DMBAND_refCount ); }
/*****************************************************************************
* Misc.

View File

@ -23,41 +23,48 @@
WINE_DEFAULT_DEBUG_CHANNEL(dmsynth);
LONG DMSYNTH_refCount = 0;
typedef struct {
/* IUnknown fields */
IClassFactoryVtbl *lpVtbl;
DWORD ref;
} IClassFactoryImpl;
/******************************************************************
* DirectMusicSynth ClassFactory
*/
static HRESULT WINAPI SynthCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %s, %p): stub\n", This, debugstr_dmguid(riid), ppobj);
FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
if (ppobj == NULL) return E_POINTER;
return E_NOINTERFACE;
}
static ULONG WINAPI SynthCF_AddRef(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return InterlockedIncrement(&This->ref);
DMSYNTH_LockModule();
return 2; /* non-heap based object */
}
static ULONG WINAPI SynthCF_Release(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
/* static class, won't be freed */
return InterlockedDecrement(&This->ref);
DMSYNTH_UnlockModule();
return 1; /* non-heap based object */
}
static HRESULT WINAPI SynthCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
TRACE ("(%p, %p, %s, %p)\n", This, pOuter, debugstr_dmguid(riid), ppobj);
TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
return DMUSIC_CreateDirectMusicSynthImpl (riid, ppobj, pOuter);
}
static HRESULT WINAPI SynthCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %d): stub\n", This, dolock);
TRACE("(%d)\n", dolock);
if (dolock)
DMSYNTH_LockModule();
else
DMSYNTH_UnlockModule();
return S_OK;
}
@ -69,37 +76,44 @@ static IClassFactoryVtbl SynthCF_Vtbl = {
SynthCF_LockServer
};
static IClassFactoryImpl Synth_CF = {&SynthCF_Vtbl, 1 };
static IClassFactoryImpl Synth_CF = {&SynthCF_Vtbl};
/******************************************************************
* DirectMusicSynthSink ClassFactory
*/
static HRESULT WINAPI SynthSinkCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %s, %p): stub\n", This, debugstr_dmguid(riid), ppobj);
FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid));
if (ppobj == NULL) return E_POINTER;
return E_NOINTERFACE;
}
static ULONG WINAPI SynthSinkCF_AddRef(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
return InterlockedIncrement(&This->ref);
DMSYNTH_LockModule();
return 2; /* non-heap based object */
}
static ULONG WINAPI SynthSinkCF_Release(LPCLASSFACTORY iface) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
/* static class, won't be freed */
return InterlockedDecrement(&This->ref);
DMSYNTH_UnlockModule();
return 1; /* non-heap based object */
}
static HRESULT WINAPI SynthSinkCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
TRACE ("(%p, %p, %s, %p)\n", This, pOuter, debugstr_dmguid(riid), ppobj);
TRACE ("(%p, %s, %p)\n", pOuter, debugstr_dmguid(riid), ppobj);
return DMUSIC_CreateDirectMusicSynthSinkImpl (riid, ppobj, pOuter);
}
static HRESULT WINAPI SynthSinkCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
FIXME("(%p, %d): stub\n", This, dolock);
TRACE("(%d)\n", dolock);
if (dolock)
DMSYNTH_LockModule();
else
DMSYNTH_UnlockModule();
return S_OK;
}
@ -111,7 +125,7 @@ static IClassFactoryVtbl SynthSinkCF_Vtbl = {
SynthSinkCF_LockServer
};
static IClassFactoryImpl SynthSink_CF = {&SynthSinkCF_Vtbl, 1 };
static IClassFactoryImpl SynthSink_CF = {&SynthSinkCF_Vtbl};
/******************************************************************
* DllMain
@ -136,8 +150,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
*
*/
HRESULT WINAPI DMSYNTH_DllCanUnloadNow(void) {
FIXME("(void): stub\n");
return S_FALSE;
return DMSYNTH_refCount != 0 ? S_FALSE : S_OK;
}

View File

@ -127,6 +127,12 @@ extern HRESULT WINAPI IDirectMusicSynthSinkImpl_RefTimeToSample (LPDIRECTMUSICSY
extern HRESULT WINAPI IDirectMusicSynthSinkImpl_SetDirectSound (LPDIRECTMUSICSYNTHSINK iface, LPDIRECTSOUND pDirectSound, LPDIRECTSOUNDBUFFER pDirectSoundBuffer);
extern HRESULT WINAPI IDirectMusicSynthSinkImpl_GetDesiredBufferSize (LPDIRECTMUSICSYNTHSINK iface, LPDWORD pdwBufferSizeInSamples);
/**********************************************************************
* Dll lifetime tracking declaration for dmsynth.dll
*/
extern LONG DMSYNTH_refCount;
static inline void DMSYNTH_LockModule() { InterlockedIncrement( &DMSYNTH_refCount ); }
static inline void DMSYNTH_UnlockModule() { InterlockedDecrement( &DMSYNTH_refCount ); }
/*****************************************************************************
* Misc.

View File

@ -43,6 +43,8 @@ ULONG WINAPI IDirectMusicSynth8Impl_AddRef (LPDIRECTMUSICSYNTH8 iface) {
TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
DMSYNTH_LockModule();
return refCount;
}
@ -55,6 +57,9 @@ ULONG WINAPI IDirectMusicSynth8Impl_Release (LPDIRECTMUSICSYNTH8 iface) {
if (!refCount) {
HeapFree(GetProcessHeap(), 0, This);
}
DMSYNTH_UnlockModule();
return refCount;
}

View File

@ -42,6 +42,8 @@ ULONG WINAPI IDirectMusicSynthSinkImpl_AddRef (LPDIRECTMUSICSYNTHSINK iface) {
TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
DMSYNTH_LockModule();
return refCount;
}
@ -54,6 +56,9 @@ ULONG WINAPI IDirectMusicSynthSinkImpl_Release (LPDIRECTMUSICSYNTHSINK iface) {
if (!refCount) {
HeapFree(GetProcessHeap(), 0, This);
}
DMSYNTH_UnlockModule();
return refCount;
}