Commit 48bd5461 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

ole32: Use single static instance for ROT.

parent 3863b243
...@@ -758,16 +758,8 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoIni ...@@ -758,16 +758,8 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoIni
* And crank-up that lock count. * And crank-up that lock count.
*/ */
if (InterlockedExchangeAdd(&s_COMLockCount,1)==0) if (InterlockedExchangeAdd(&s_COMLockCount,1)==0)
{
/*
* Initialize the various COM libraries and data structures.
*/
TRACE("() - Initializing the COM libraries\n"); TRACE("() - Initializing the COM libraries\n");
/* we may need to defer this until after apartment initialisation */
RunningObjectTableImpl_Initialize();
}
lock_init_spies(info); lock_init_spies(info);
LIST_FOR_EACH_ENTRY(cursor, &info->spies, struct init_spy, entry) LIST_FOR_EACH_ENTRY(cursor, &info->spies, struct init_spy, entry)
{ {
...@@ -849,7 +841,7 @@ void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void) ...@@ -849,7 +841,7 @@ void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
TRACE("() - Releasing the COM libraries\n"); TRACE("() - Releasing the COM libraries\n");
InternalRevokeAllPSClsids(); InternalRevokeAllPSClsids();
RunningObjectTableImpl_UnInitialize(); DestroyRunningObjectTable();
} }
else if (lCOMRefCnt<1) { else if (lCOMRefCnt<1) {
ERR( "CoUninitialize() - not CoInitialized.\n" ); ERR( "CoUninitialize() - not CoInitialized.\n" );
......
...@@ -234,12 +234,6 @@ HRESULT RPC_RegisterChannelHook(REFGUID rguid, IChannelHook *hook) DECLSPEC_HIDD ...@@ -234,12 +234,6 @@ HRESULT RPC_RegisterChannelHook(REFGUID rguid, IChannelHook *hook) DECLSPEC_HIDD
void RPC_UnregisterAllChannelHooks(void) DECLSPEC_HIDDEN; void RPC_UnregisterAllChannelHooks(void) DECLSPEC_HIDDEN;
HRESULT RPC_ResolveOxid(OXID oxid, OXID_INFO *oxid_info) DECLSPEC_HIDDEN; HRESULT RPC_ResolveOxid(OXID oxid, OXID_INFO *oxid_info) DECLSPEC_HIDDEN;
/* This function initialize the Running Object Table */
HRESULT WINAPI RunningObjectTableImpl_Initialize(void) DECLSPEC_HIDDEN;
/* This function uninitialize the Running Object Table */
HRESULT WINAPI RunningObjectTableImpl_UnInitialize(void) DECLSPEC_HIDDEN;
/* Drag and drop */ /* Drag and drop */
void OLEDD_UnInitialize(void) DECLSPEC_HIDDEN; void OLEDD_UnInitialize(void) DECLSPEC_HIDDEN;
...@@ -365,4 +359,7 @@ static inline HRESULT copy_formatetc(FORMATETC *dst, const FORMATETC *src) ...@@ -365,4 +359,7 @@ static inline HRESULT copy_formatetc(FORMATETC *dst, const FORMATETC *src)
extern HRESULT EnumSTATDATA_Construct(IUnknown *holder, ULONG index, DWORD array_len, STATDATA *data, extern HRESULT EnumSTATDATA_Construct(IUnknown *holder, ULONG index, DWORD array_len, STATDATA *data,
BOOL copy, IEnumSTATDATA **ppenum) DECLSPEC_HIDDEN; BOOL copy, IEnumSTATDATA **ppenum) DECLSPEC_HIDDEN;
extern BOOL WINAPI InternalIsInitialized(void);
extern void WINAPI DestroyRunningObjectTable(void);
#endif /* __WINE_OLE_COMPOBJ_H */ #endif /* __WINE_OLE_COMPOBJ_H */
...@@ -63,15 +63,10 @@ struct rot_entry ...@@ -63,15 +63,10 @@ struct rot_entry
typedef struct RunningObjectTableImpl typedef struct RunningObjectTableImpl
{ {
IRunningObjectTable IRunningObjectTable_iface; IRunningObjectTable IRunningObjectTable_iface;
LONG ref;
struct list rot; /* list of ROT entries */ struct list rot; /* list of ROT entries */
CRITICAL_SECTION lock; CRITICAL_SECTION lock;
} RunningObjectTableImpl; } RunningObjectTableImpl;
static RunningObjectTableImpl* runningObjectTableInstance = NULL;
static IrotHandle irot_handle;
/* define the EnumMonikerImpl structure */ /* define the EnumMonikerImpl structure */
typedef struct EnumMonikerImpl typedef struct EnumMonikerImpl
{ {
...@@ -256,85 +251,18 @@ RunningObjectTableImpl_QueryInterface(IRunningObjectTable* iface, ...@@ -256,85 +251,18 @@ RunningObjectTableImpl_QueryInterface(IRunningObjectTable* iface,
return S_OK; return S_OK;
} }
/*********************************************************************** static ULONG WINAPI RunningObjectTableImpl_AddRef(IRunningObjectTable *iface)
* RunningObjectTable_AddRef
*/
static ULONG WINAPI
RunningObjectTableImpl_AddRef(IRunningObjectTable* iface)
{
RunningObjectTableImpl *This = impl_from_IRunningObjectTable(iface);
TRACE("(%p)\n",This);
return InterlockedIncrement(&This->ref);
}
/***********************************************************************
* RunningObjectTable_Destroy
*/
static HRESULT
RunningObjectTableImpl_Destroy(void)
{ {
struct list *cursor, *cursor2; TRACE("%p\n", iface);
IrotHandle old_handle;
TRACE("()\n");
if (runningObjectTableInstance==NULL)
return E_INVALIDARG;
/* free the ROT table memory */
LIST_FOR_EACH_SAFE(cursor, cursor2, &runningObjectTableInstance->rot)
{
struct rot_entry *rot_entry = LIST_ENTRY(cursor, struct rot_entry, entry);
list_remove(&rot_entry->entry);
rot_entry_delete(rot_entry);
}
DEBUG_CLEAR_CRITSEC_NAME(&runningObjectTableInstance->lock);
DeleteCriticalSection(&runningObjectTableInstance->lock);
/* free the ROT structure memory */ return 2;
HeapFree(GetProcessHeap(),0,runningObjectTableInstance);
runningObjectTableInstance = NULL;
old_handle = irot_handle;
irot_handle = NULL;
if (old_handle)
RpcBindingFree(&old_handle);
return S_OK;
} }
/*********************************************************************** static ULONG WINAPI RunningObjectTableImpl_Release(IRunningObjectTable *iface)
* RunningObjectTable_Release
*/
static ULONG WINAPI
RunningObjectTableImpl_Release(IRunningObjectTable* iface)
{ {
RunningObjectTableImpl *This = impl_from_IRunningObjectTable(iface); TRACE("%p\n", iface);
ULONG ref;
TRACE("(%p)\n",This);
ref = InterlockedDecrement(&This->ref);
/* uninitialize ROT structure if there are no more references to it */
if (ref == 0)
{
struct list *cursor, *cursor2;
LIST_FOR_EACH_SAFE(cursor, cursor2, &This->rot)
{
struct rot_entry *rot_entry = LIST_ENTRY(cursor, struct rot_entry, entry);
list_remove(&rot_entry->entry);
rot_entry_delete(rot_entry);
}
/* RunningObjectTable data structure will be not destroyed here ! the destruction will be done only
* when RunningObjectTableImpl_UnInitialize function is called
*/
}
return ref; return 1;
} }
/*********************************************************************** /***********************************************************************
...@@ -775,82 +703,48 @@ static const IRunningObjectTableVtbl VT_RunningObjectTableImpl = ...@@ -775,82 +703,48 @@ static const IRunningObjectTableVtbl VT_RunningObjectTableImpl =
RunningObjectTableImpl_EnumRunning RunningObjectTableImpl_EnumRunning
}; };
/*********************************************************************** static RunningObjectTableImpl rot =
* RunningObjectTable_Initialize
*/
HRESULT WINAPI RunningObjectTableImpl_Initialize(void)
{ {
TRACE("\n"); .IRunningObjectTable_iface.lpVtbl = &VT_RunningObjectTableImpl,
.lock.LockCount = -1,
/* create the unique instance of the RunningObjectTableImpl structure */ .rot = LIST_INIT(rot.rot),
runningObjectTableInstance = HeapAlloc(GetProcessHeap(), 0, sizeof(RunningObjectTableImpl)); };
if (!runningObjectTableInstance)
return E_OUTOFMEMORY;
/* initialize the virtual table function */
runningObjectTableInstance->IRunningObjectTable_iface.lpVtbl = &VT_RunningObjectTableImpl;
/* the initial reference is set to "1" so that it isn't destroyed after its
* first use until the process is destroyed, as the running object table is
* a process-wide cache of a global table */
runningObjectTableInstance->ref = 1;
list_init(&runningObjectTableInstance->rot);
InitializeCriticalSection(&runningObjectTableInstance->lock);
DEBUG_SET_CRITSEC_NAME(&runningObjectTableInstance->lock, "RunningObjectTableImpl.lock");
return S_OK;
}
/*********************************************************************** /***********************************************************************
* RunningObjectTable_UnInitialize * GetRunningObjectTable (OLE32.@)
*/ */
HRESULT WINAPI RunningObjectTableImpl_UnInitialize(void) HRESULT WINAPI GetRunningObjectTable(DWORD reserved, IRunningObjectTable **ret)
{ {
TRACE("\n"); TRACE("%#x, %p\n", reserved, ret);
if (runningObjectTableInstance==NULL) if (reserved!=0)
return E_POINTER; return E_UNEXPECTED;
RunningObjectTableImpl_Release(&runningObjectTableInstance->IRunningObjectTable_iface); if (!InternalIsInitialized())
return CO_E_NOTINITIALIZED;
RunningObjectTableImpl_Destroy(); *ret = &rot.IRunningObjectTable_iface;
IRunningObjectTable_AddRef(*ret);
return S_OK; return S_OK;
} }
/*********************************************************************** /***********************************************************************
* GetRunningObjectTable (OLE32.@) * DestroyRunningObjectTable (ole32.@)
* */
* Retrieves the global running object table. void WINAPI DestroyRunningObjectTable(void)
*
* PARAMS
* reserved [I] Reserved. Set to 0.
* pprot [O] Address that receives the pointer to the running object table.
*
* RETURNS
* Success: S_OK.
* Failure: Any HRESULT code.
*/
HRESULT WINAPI
GetRunningObjectTable(DWORD reserved, LPRUNNINGOBJECTTABLE *pprot)
{ {
IID riid=IID_IRunningObjectTable; struct rot_entry *rot_entry, *cursor2;
HRESULT res;
TRACE("()\n");
if (reserved!=0)
return E_UNEXPECTED;
if(runningObjectTableInstance==NULL)
return CO_E_NOTINITIALIZED;
res = IRunningObjectTable_QueryInterface(&runningObjectTableInstance->IRunningObjectTable_iface, TRACE("\n");
&riid,(void**)pprot);
return res; EnterCriticalSection(&rot.lock);
LIST_FOR_EACH_ENTRY_SAFE(rot_entry, cursor2, &rot.rot, struct rot_entry, entry)
{
list_remove(&rot_entry->entry);
rot_entry_delete(rot_entry);
}
LeaveCriticalSection(&rot.lock);
} }
static HRESULT get_moniker_for_progid_display_name(LPBC pbc, static HRESULT get_moniker_for_progid_display_name(LPBC pbc,
......
...@@ -106,6 +106,7 @@ ...@@ -106,6 +106,7 @@
@ stdcall CreateOleAdviseHolder(ptr) @ stdcall CreateOleAdviseHolder(ptr)
@ stdcall CreatePointerMoniker(ptr ptr) @ stdcall CreatePointerMoniker(ptr ptr)
@ stdcall CreateStreamOnHGlobal(ptr long ptr) @ stdcall CreateStreamOnHGlobal(ptr long ptr)
@ stdcall DestroyRunningObjectTable()
@ stdcall DllDebugObjectRPCHook(long ptr) @ stdcall DllDebugObjectRPCHook(long ptr)
@ stdcall -private DllGetClassObject (ptr ptr ptr) @ stdcall -private DllGetClassObject (ptr ptr ptr)
@ stub DllGetClassObjectWOW @ stub DllGetClassObjectWOW
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment