Vincent Povirk : mscoree: Add a proper implementation of DllCanUnloadNow.
Alexandre Julliard
julliard at winehq.org
Wed Nov 10 11:09:44 CST 2010
Module: wine
Branch: master
Commit: 1309731b4a3fbfcd10243a2c1f886e0a035d6d1d
URL: http://source.winehq.org/git/wine.git/?a=commit;h=1309731b4a3fbfcd10243a2c1f886e0a035d6d1d
Author: Vincent Povirk <vincent at codeweavers.com>
Date: Sun Oct 3 13:42:24 2010 -0500
mscoree: Add a proper implementation of DllCanUnloadNow.
---
dlls/mscoree/corruntimehost.c | 8 ++++++++
dlls/mscoree/metahost.c | 8 ++++++++
dlls/mscoree/mscoree_main.c | 7 ++++++-
dlls/mscoree/mscoree_private.h | 4 ++++
4 files changed, 26 insertions(+), 1 deletions(-)
diff --git a/dlls/mscoree/corruntimehost.c b/dlls/mscoree/corruntimehost.c
index 95f7ef3..46b9f91 100644
--- a/dlls/mscoree/corruntimehost.c
+++ b/dlls/mscoree/corruntimehost.c
@@ -108,6 +108,8 @@ static HRESULT RuntimeHost_AddDomain(RuntimeHost *This, MonoDomain **result)
list_add_tail(&This->domains, &entry->entry);
+ MSCOREE_LockModule();
+
*result = entry->domain;
end:
@@ -149,6 +151,7 @@ static void RuntimeHost_DeleteDomain(RuntimeHost *This, MonoDomain *domain)
if (This->default_domain == domain)
This->default_domain = NULL;
HeapFree(GetProcessHeap(), 0, entry);
+ MSCOREE_UnlockModule();
break;
}
}
@@ -193,6 +196,9 @@ static HRESULT WINAPI corruntimehost_QueryInterface(ICorRuntimeHost* iface,
static ULONG WINAPI corruntimehost_AddRef(ICorRuntimeHost* iface)
{
RuntimeHost *This = impl_from_ICorRuntimeHost( iface );
+
+ MSCOREE_LockModule();
+
return InterlockedIncrement( &This->ref );
}
@@ -201,6 +207,8 @@ static ULONG WINAPI corruntimehost_Release(ICorRuntimeHost* iface)
RuntimeHost *This = impl_from_ICorRuntimeHost( iface );
ULONG ref;
+ MSCOREE_UnlockModule();
+
ref = InterlockedDecrement( &This->ref );
return ref;
diff --git a/dlls/mscoree/metahost.c b/dlls/mscoree/metahost.c
index 51897b2..018c1ee 100644
--- a/dlls/mscoree/metahost.c
+++ b/dlls/mscoree/metahost.c
@@ -225,11 +225,13 @@ static HRESULT WINAPI CLRRuntimeInfo_QueryInterface(ICLRRuntimeInfo* iface,
static ULONG WINAPI CLRRuntimeInfo_AddRef(ICLRRuntimeInfo* iface)
{
+ MSCOREE_LockModule();
return 2;
}
static ULONG WINAPI CLRRuntimeInfo_Release(ICLRRuntimeInfo* iface)
{
+ MSCOREE_UnlockModule();
return 1;
}
@@ -668,6 +670,8 @@ static ULONG WINAPI InstalledRuntimeEnum_AddRef(IEnumUnknown* iface)
struct InstalledRuntimeEnum *This = (struct InstalledRuntimeEnum*)iface;
ULONG ref = InterlockedIncrement(&This->ref);
+ MSCOREE_LockModule();
+
TRACE("(%p) refcount=%u\n", iface, ref);
return ref;
@@ -678,6 +682,8 @@ static ULONG WINAPI InstalledRuntimeEnum_Release(IEnumUnknown* iface)
struct InstalledRuntimeEnum *This = (struct InstalledRuntimeEnum*)iface;
ULONG ref = InterlockedDecrement(&This->ref);
+ MSCOREE_UnlockModule();
+
TRACE("(%p) refcount=%u\n", iface, ref);
if (ref == 0)
@@ -818,11 +824,13 @@ static HRESULT WINAPI CLRMetaHost_QueryInterface(ICLRMetaHost* iface,
static ULONG WINAPI CLRMetaHost_AddRef(ICLRMetaHost* iface)
{
+ MSCOREE_LockModule();
return 2;
}
static ULONG WINAPI CLRMetaHost_Release(ICLRMetaHost* iface)
{
+ MSCOREE_UnlockModule();
return 1;
}
diff --git a/dlls/mscoree/mscoree_main.c b/dlls/mscoree/mscoree_main.c
index 0e96a47..e0d1e95 100644
--- a/dlls/mscoree/mscoree_main.c
+++ b/dlls/mscoree/mscoree_main.c
@@ -44,6 +44,8 @@
WINE_DEFAULT_DEBUG_CHANNEL( mscoree );
+LONG dll_refs = 0;
+
static BOOL get_install_root(LPWSTR install_dir)
{
const WCHAR dotnet_key[] = {'S','O','F','T','W','A','R','E','\\','M','i','c','r','o','s','o','f','t','\\','.','N','E','T','F','r','a','m','e','w','o','r','k','\\',0};
@@ -398,7 +400,10 @@ HRESULT WINAPI DllUnregisterServer(void)
HRESULT WINAPI DllCanUnloadNow(VOID)
{
- return S_OK;
+ if (dll_refs)
+ return S_FALSE;
+ else
+ return S_OK;
}
INT WINAPI ND_RU1( const void *ptr, INT offset )
diff --git a/dlls/mscoree/mscoree_private.h b/dlls/mscoree/mscoree_private.h
index 5062431..00c3652 100644
--- a/dlls/mscoree/mscoree_private.h
+++ b/dlls/mscoree/mscoree_private.h
@@ -20,6 +20,10 @@
#ifndef __MSCOREE_PRIVATE__
#define __MSCOREE_PRIVATE__
+extern LONG dll_refs;
+static inline void MSCOREE_LockModule(void) { InterlockedIncrement(&dll_refs); }
+static inline void MSCOREE_UnlockModule(void) { InterlockedDecrement(&dll_refs); }
+
extern HRESULT CLRMetaHost_CreateInstance(REFIID riid, void **ppobj);
typedef struct tagASSEMBLY ASSEMBLY;
More information about the wine-cvs
mailing list