Sync to Wine-20050211 James Hawkins truiken@gmail.com - Properly implement DllCanUnloadNow ref counting. - Use only stored result of Interlocked* in AddRef/Release. - Expand TRACEs to display the ref count. Modified: trunk/reactos/lib/urlmon/sec_mgr.c Modified: trunk/reactos/lib/urlmon/umon.c Modified: trunk/reactos/lib/urlmon/urlmon_main.c Modified: trunk/reactos/lib/urlmon/urlmon_main.h _____
Modified: trunk/reactos/lib/urlmon/sec_mgr.c --- trunk/reactos/lib/urlmon/sec_mgr.c 2005-02-14 14:55:38 UTC (rev 13560) +++ trunk/reactos/lib/urlmon/sec_mgr.c 2005-02-14 15:04:09 UTC (rev 13561) @@ -78,25 +78,30 @@
static ULONG WINAPI SecManagerImpl_AddRef(IInternetSecurityManager* iface) { SecManagerImpl *This = (SecManagerImpl *)iface; + ULONG refCount = InterlockedIncrement(&This->ref);
- TRACE("(%p)\n",This); + TRACE("(%p)->(ref before=%lu)\n",This, refCount - 1);
- return InterlockedIncrement(&This->ref); + URLMON_LockModule(); + + return refCount; }
static ULONG WINAPI SecManagerImpl_Release(IInternetSecurityManager* iface) { SecManagerImpl *This = (SecManagerImpl *)iface; - ULONG ref; - TRACE("(%p)\n",This); + ULONG refCount = InterlockedDecrement(&This->ref);
- ref = InterlockedDecrement(&This->ref); + TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1);
/* destroy the object if there's no more reference on it */ - if (ref==0){ + if (!refCount){ HeapFree(GetProcessHeap(),0,This); } - return ref; + + URLMON_UnlockModule(); + + return refCount; }
static HRESULT WINAPI SecManagerImpl_SetSecuritySite(IInternetSecurityManager *iface, @@ -238,10 +243,13 @@ static ULONG WINAPI ZoneMgrImpl_AddRef(IInternetZoneManager* iface) { ZoneMgrImpl* This = (ZoneMgrImpl*)iface; + ULONG refCount = InterlockedIncrement(&This->ref);
- TRACE("(%p) was %lu\n", This, This->ref); + TRACE("(%p)->(ref before=%lu)\n",This, refCount - 1);
- return InterlockedIncrement(&This->ref); + URLMON_LockModule(); + + return refCount; }
/******************************************************************** @@ -250,15 +258,16 @@ static ULONG WINAPI ZoneMgrImpl_Release(IInternetZoneManager* iface) { ZoneMgrImpl* This = (ZoneMgrImpl*)iface; - ULONG ref; + ULONG refCount = InterlockedDecrement(&This->ref);
- TRACE("(%p) was %lu\n", This, This->ref); - ref = InterlockedDecrement(&This->ref); + TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1);
- if(!ref) + if(!refCount) HeapFree(GetProcessHeap(), 0, This);
- return ref; + URLMON_UnlockModule(); + + return refCount; }
/******************************************************************** _____
Modified: trunk/reactos/lib/urlmon/umon.c --- trunk/reactos/lib/urlmon/umon.c 2005-02-14 14:55:38 UTC (rev 13560) +++ trunk/reactos/lib/urlmon/umon.c 2005-02-14 15:04:09 UTC (rev 13561) @@ -103,10 +103,13 @@
static ULONG WINAPI URLMonikerImpl_AddRef(IMoniker* iface) { URLMonikerImpl *This = (URLMonikerImpl *)iface; + ULONG refCount = InterlockedIncrement(&This->ref);
- TRACE("(%p)\n",This); + TRACE("(%p)->(ref before=%lu)\n",This, refCount - 1);
- return InterlockedIncrement(&This->ref); + URLMON_LockModule(); + + return refCount; }
/*********************************************************************** ******* @@ -115,19 +118,19 @@ static ULONG WINAPI URLMonikerImpl_Release(IMoniker* iface) { URLMonikerImpl *This = (URLMonikerImpl *)iface; - ULONG ref; + ULONG refCount = InterlockedDecrement(&This->ref);
- TRACE("(%p)\n",This); + TRACE("(%p)->(ref before=%lu)\n",This, refCount + 1);
- ref = InterlockedDecrement(&This->ref); - /* destroy the object if there's no more reference on it */ - if (ref == 0) { + if (!refCount) { HeapFree(GetProcessHeap(),0,This->URLName); HeapFree(GetProcessHeap(),0,This); }
- return ref; + URLMON_UnlockModule(); + + return refCount; }
/*********************************************************************** ******* _____
Modified: trunk/reactos/lib/urlmon/urlmon_main.c --- trunk/reactos/lib/urlmon/urlmon_main.c 2005-02-14 14:55:38 UTC (rev 13560) +++ trunk/reactos/lib/urlmon/urlmon_main.c 2005-02-14 15:04:09 UTC (rev 13561) @@ -37,6 +37,8 @@
WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
+LONG URLMON_refCount = 0; + HINSTANCE URLMON_hInstance = 0;
/*********************************************************************** @@ -76,9 +78,7 @@ */ HRESULT WINAPI URLMON_DllCanUnloadNow(void) { - FIXME("(void): stub\n"); - - return S_FALSE; + return URLMON_refCount != 0 ? S_FALSE : S_OK; }
@@ -125,6 +125,8 @@ static ULONG WINAPI CF_AddRef(LPCLASSFACTORY iface) { IClassFactoryImpl *This = (IClassFactoryImpl *)iface; + URLMON_LockModule(); + return InterlockedIncrement(&This->ref); }
@@ -137,6 +139,8 @@ if (ref == 0) HeapFree(GetProcessHeap(), 0, This);
+ URLMON_UnlockModule(); + return ref; }
@@ -160,8 +164,13 @@
static HRESULT WINAPI CF_LockServer(LPCLASSFACTORY iface,BOOL dolock) { - IClassFactoryImpl *This = (IClassFactoryImpl *)iface; - FIXME("(%p)->(%d),stub!\n",This,dolock); + TRACE("(%d)\n", dolock); + + if (dolock) + URLMON_LockModule(); + else + URLMON_UnlockModule(); + return S_OK; }
_____
Modified: trunk/reactos/lib/urlmon/urlmon_main.h --- trunk/reactos/lib/urlmon/urlmon_main.h 2005-02-14 14:55:38 UTC (rev 13560) +++ trunk/reactos/lib/urlmon/urlmon_main.h 2005-02-14 15:04:09 UTC (rev 13561) @@ -28,6 +28,13 @@
extern HRESULT SecManagerImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj); extern HRESULT ZoneMgrImpl_Construct(IUnknown *pUnkOuter, LPVOID *ppobj);
+/********************************************************************** + * Dll lifetime tracking declaration for urlmon.dll + */ +extern LONG URLMON_refCount; +static inline void URLMON_LockModule() { InterlockedIncrement( &URLMON_refCount ); } +static inline void URLMON_UnlockModule() { InterlockedDecrement( &URLMON_refCount ); } + #define ICOM_THIS_MULTI(impl,field,iface) impl* const This=(impl*)((char*)(iface) - offsetof(impl,field))
#endif /* __WINE_URLMON_MAIN_H */