dmloader: Simplify the module refcount handling.
This commit is contained in:
parent
98a36f4694
commit
989f39ef32
|
@ -68,9 +68,7 @@ static HRESULT DMUSIC_DestroyDirectMusicContainerImpl (LPDIRECTMUSICCONTAINER if
|
|||
IStream_Release (This->pStream);
|
||||
|
||||
/* FIXME: release allocated entries */
|
||||
|
||||
/* decrease number of instances */
|
||||
InterlockedDecrement (&dwDirectMusicContainer);
|
||||
unlock_module();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
@ -924,8 +922,7 @@ HRESULT WINAPI DMUSIC_CreateDirectMusicContainerImpl (LPCGUID lpcGUID, LPVOID* p
|
|||
obj->pContainedObjects = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(struct list));
|
||||
list_init (obj->pContainedObjects);
|
||||
|
||||
/* increase number of instances */
|
||||
InterlockedIncrement (&dwDirectMusicContainer);
|
||||
|
||||
lock_module();
|
||||
|
||||
return IDirectMusicContainerImpl_IDirectMusicContainer_QueryInterface ((LPDIRECTMUSICCONTAINER)&obj->ContainerVtbl, lpcGUID, ppobj);
|
||||
}
|
||||
|
|
|
@ -23,8 +23,7 @@
|
|||
WINE_DEFAULT_DEBUG_CHANNEL(dmloader);
|
||||
|
||||
static HINSTANCE instance;
|
||||
LONG dwDirectMusicContainer = 0;
|
||||
LONG dwDirectMusicLoader = 0;
|
||||
LONG module_ref = 0;
|
||||
|
||||
typedef struct {
|
||||
IClassFactory IClassFactory_iface;
|
||||
|
@ -61,14 +60,14 @@ static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID r
|
|||
|
||||
static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
|
||||
{
|
||||
InterlockedIncrement(&dwDirectMusicLoader);
|
||||
lock_module();
|
||||
|
||||
return 2; /* non-heap based object */
|
||||
}
|
||||
|
||||
static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
|
||||
{
|
||||
InterlockedDecrement(&dwDirectMusicLoader);
|
||||
unlock_module();
|
||||
|
||||
return 1; /* non-heap based object */
|
||||
}
|
||||
|
@ -88,9 +87,9 @@ static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
|
|||
TRACE("(%d)\n", dolock);
|
||||
|
||||
if (dolock)
|
||||
InterlockedIncrement(&dwDirectMusicLoader);
|
||||
lock_module();
|
||||
else
|
||||
InterlockedDecrement(&dwDirectMusicLoader);
|
||||
unlock_module();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
@ -127,14 +126,10 @@ BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
|
|||
*/
|
||||
HRESULT WINAPI DllCanUnloadNow (void)
|
||||
{
|
||||
TRACE("(void)\n");
|
||||
/* if there are no instances left, it's safe to release */
|
||||
if (!dwDirectMusicContainer && !dwDirectMusicLoader)
|
||||
return S_OK;
|
||||
else
|
||||
return S_FALSE;
|
||||
}
|
||||
TRACE("() ref=%d\n", module_ref);
|
||||
|
||||
return module_ref ? S_FALSE : S_OK;
|
||||
}
|
||||
|
||||
/******************************************************************
|
||||
* DllGetClassObject (DMLOADER.@)
|
||||
|
|
|
@ -45,8 +45,9 @@
|
|||
#define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
|
||||
|
||||
/* dmloader.dll global (for DllCanUnloadNow) */
|
||||
extern LONG dwDirectMusicLoader DECLSPEC_HIDDEN; /* number of DirectMusicLoader(CF) instances */
|
||||
extern LONG dwDirectMusicContainer DECLSPEC_HIDDEN; /* number of DirectMusicContainer(CF) instances */
|
||||
extern LONG module_ref DECLSPEC_HIDDEN;
|
||||
static inline void lock_module(void) { InterlockedIncrement( &module_ref ); }
|
||||
static inline void unlock_module(void) { InterlockedDecrement( &module_ref ); }
|
||||
|
||||
/*****************************************************************************
|
||||
* Interfaces
|
||||
|
|
|
@ -104,11 +104,9 @@ static ULONG WINAPI IDirectMusicLoaderImpl_IDirectMusicLoader_Release (LPDIRECTM
|
|||
/*This->CritSect.DebugInfo->Spare[0] = 0;
|
||||
DeleteCriticalSection (&This->CritSect); */
|
||||
HeapFree (GetProcessHeap(), 0, This);
|
||||
|
||||
/* decrease number of instances */
|
||||
InterlockedDecrement (&dwDirectMusicLoader);
|
||||
unlock_module();
|
||||
}
|
||||
|
||||
|
||||
return dwRef;
|
||||
}
|
||||
|
||||
|
@ -895,9 +893,8 @@ HRESULT WINAPI DMUSIC_CreateDirectMusicLoaderImpl (LPCGUID lpcGUID, LPVOID *ppob
|
|||
pDefaultDLSEntry->bInvalidDefaultDLS = TRUE;
|
||||
}
|
||||
|
||||
/* increase number of instances */
|
||||
InterlockedIncrement (&dwDirectMusicLoader);
|
||||
|
||||
lock_module();
|
||||
|
||||
return IDirectMusicLoaderImpl_IDirectMusicLoader_QueryInterface ((LPDIRECTMUSICLOADER8)obj, lpcGUID, ppobj);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue