dmloader: Simplify the module refcount handling.

This commit is contained in:
Michael Stefaniuc 2011-08-02 10:28:16 +02:00 committed by Alexandre Julliard
parent 98a36f4694
commit 989f39ef32
4 changed files with 18 additions and 28 deletions

View File

@ -68,9 +68,7 @@ static HRESULT DMUSIC_DestroyDirectMusicContainerImpl (LPDIRECTMUSICCONTAINER if
IStream_Release (This->pStream); IStream_Release (This->pStream);
/* FIXME: release allocated entries */ /* FIXME: release allocated entries */
unlock_module();
/* decrease number of instances */
InterlockedDecrement (&dwDirectMusicContainer);
return S_OK; 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)); obj->pContainedObjects = HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, sizeof(struct list));
list_init (obj->pContainedObjects); list_init (obj->pContainedObjects);
/* increase number of instances */ lock_module();
InterlockedIncrement (&dwDirectMusicContainer);
return IDirectMusicContainerImpl_IDirectMusicContainer_QueryInterface ((LPDIRECTMUSICCONTAINER)&obj->ContainerVtbl, lpcGUID, ppobj); return IDirectMusicContainerImpl_IDirectMusicContainer_QueryInterface ((LPDIRECTMUSICCONTAINER)&obj->ContainerVtbl, lpcGUID, ppobj);
} }

View File

@ -23,8 +23,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(dmloader); WINE_DEFAULT_DEBUG_CHANNEL(dmloader);
static HINSTANCE instance; static HINSTANCE instance;
LONG dwDirectMusicContainer = 0; LONG module_ref = 0;
LONG dwDirectMusicLoader = 0;
typedef struct { typedef struct {
IClassFactory IClassFactory_iface; IClassFactory IClassFactory_iface;
@ -61,14 +60,14 @@ static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID r
static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface) static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
{ {
InterlockedIncrement(&dwDirectMusicLoader); lock_module();
return 2; /* non-heap based object */ return 2; /* non-heap based object */
} }
static ULONG WINAPI ClassFactory_Release(IClassFactory *iface) static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
{ {
InterlockedDecrement(&dwDirectMusicLoader); unlock_module();
return 1; /* non-heap based object */ return 1; /* non-heap based object */
} }
@ -88,9 +87,9 @@ static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
TRACE("(%d)\n", dolock); TRACE("(%d)\n", dolock);
if (dolock) if (dolock)
InterlockedIncrement(&dwDirectMusicLoader); lock_module();
else else
InterlockedDecrement(&dwDirectMusicLoader); unlock_module();
return S_OK; return S_OK;
} }
@ -127,14 +126,10 @@ BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
*/ */
HRESULT WINAPI DllCanUnloadNow (void) HRESULT WINAPI DllCanUnloadNow (void)
{ {
TRACE("(void)\n"); TRACE("() ref=%d\n", module_ref);
/* if there are no instances left, it's safe to release */
if (!dwDirectMusicContainer && !dwDirectMusicLoader)
return S_OK;
else
return S_FALSE;
}
return module_ref ? S_FALSE : S_OK;
}
/****************************************************************** /******************************************************************
* DllGetClassObject (DMLOADER.@) * DllGetClassObject (DMLOADER.@)

View File

@ -45,8 +45,9 @@
#define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field)) #define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
/* dmloader.dll global (for DllCanUnloadNow) */ /* dmloader.dll global (for DllCanUnloadNow) */
extern LONG dwDirectMusicLoader DECLSPEC_HIDDEN; /* number of DirectMusicLoader(CF) instances */ extern LONG module_ref DECLSPEC_HIDDEN;
extern LONG dwDirectMusicContainer DECLSPEC_HIDDEN; /* number of DirectMusicContainer(CF) instances */ static inline void lock_module(void) { InterlockedIncrement( &module_ref ); }
static inline void unlock_module(void) { InterlockedDecrement( &module_ref ); }
/***************************************************************************** /*****************************************************************************
* Interfaces * Interfaces

View File

@ -104,9 +104,7 @@ static ULONG WINAPI IDirectMusicLoaderImpl_IDirectMusicLoader_Release (LPDIRECTM
/*This->CritSect.DebugInfo->Spare[0] = 0; /*This->CritSect.DebugInfo->Spare[0] = 0;
DeleteCriticalSection (&This->CritSect); */ DeleteCriticalSection (&This->CritSect); */
HeapFree (GetProcessHeap(), 0, This); HeapFree (GetProcessHeap(), 0, This);
unlock_module();
/* decrease number of instances */
InterlockedDecrement (&dwDirectMusicLoader);
} }
return dwRef; return dwRef;
@ -895,8 +893,7 @@ HRESULT WINAPI DMUSIC_CreateDirectMusicLoaderImpl (LPCGUID lpcGUID, LPVOID *ppob
pDefaultDLSEntry->bInvalidDefaultDLS = TRUE; pDefaultDLSEntry->bInvalidDefaultDLS = TRUE;
} }
/* increase number of instances */ lock_module();
InterlockedIncrement (&dwDirectMusicLoader);
return IDirectMusicLoaderImpl_IDirectMusicLoader_QueryInterface ((LPDIRECTMUSICLOADER8)obj, lpcGUID, ppobj); return IDirectMusicLoaderImpl_IDirectMusicLoader_QueryInterface ((LPDIRECTMUSICLOADER8)obj, lpcGUID, ppobj);
} }