Nikolay Sivov : ole32: Use single static instance for ROT.

Alexandre Julliard julliard at winehq.org
Thu Aug 27 15:26:49 CDT 2020


Module: wine
Branch: master
Commit: 48bd5461ed0d5ba0e7c7e0c5ae5fb782764b2003
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=48bd5461ed0d5ba0e7c7e0c5ae5fb782764b2003

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Thu Aug 27 11:37:44 2020 +0300

ole32: Use single static instance for ROT.

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ole32/compobj.c         |  10 +--
 dlls/ole32/compobj_private.h |   9 +--
 dlls/ole32/moniker.c         | 170 ++++++++-----------------------------------
 dlls/ole32/ole32.spec        |   1 +
 4 files changed, 37 insertions(+), 153 deletions(-)

diff --git a/dlls/ole32/compobj.c b/dlls/ole32/compobj.c
index 55d06f197f..88482392d5 100644
--- a/dlls/ole32/compobj.c
+++ b/dlls/ole32/compobj.c
@@ -758,16 +758,8 @@ HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoIni
    * And crank-up that lock count.
    */
   if (InterlockedExchangeAdd(&s_COMLockCount,1)==0)
-  {
-    /*
-     * Initialize the various COM libraries and data structures.
-     */
     TRACE("() - Initializing the COM libraries\n");
 
-    /* we may need to defer this until after apartment initialisation */
-    RunningObjectTableImpl_Initialize();
-  }
-
   lock_init_spies(info);
   LIST_FOR_EACH_ENTRY(cursor, &info->spies, struct init_spy, entry)
   {
@@ -849,7 +841,7 @@ void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
     TRACE("() - Releasing the COM libraries\n");
 
     InternalRevokeAllPSClsids();
-    RunningObjectTableImpl_UnInitialize();
+    DestroyRunningObjectTable();
   }
   else if (lCOMRefCnt<1) {
     ERR( "CoUninitialize() - not CoInitialized.\n" );
diff --git a/dlls/ole32/compobj_private.h b/dlls/ole32/compobj_private.h
index 29e4cac362..e910746fef 100644
--- a/dlls/ole32/compobj_private.h
+++ b/dlls/ole32/compobj_private.h
@@ -234,12 +234,6 @@ HRESULT RPC_RegisterChannelHook(REFGUID rguid, IChannelHook *hook) DECLSPEC_HIDD
 void    RPC_UnregisterAllChannelHooks(void) 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 */
 void OLEDD_UnInitialize(void) DECLSPEC_HIDDEN;
 
@@ -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,
                                       BOOL copy, IEnumSTATDATA **ppenum) DECLSPEC_HIDDEN;
 
+extern BOOL WINAPI InternalIsInitialized(void);
+extern void WINAPI DestroyRunningObjectTable(void);
+
 #endif /* __WINE_OLE_COMPOBJ_H */
diff --git a/dlls/ole32/moniker.c b/dlls/ole32/moniker.c
index b143b1bc6c..874b58f99e 100644
--- a/dlls/ole32/moniker.c
+++ b/dlls/ole32/moniker.c
@@ -63,15 +63,10 @@ struct rot_entry
 typedef struct RunningObjectTableImpl
 {
     IRunningObjectTable IRunningObjectTable_iface;
-    LONG ref;
-
     struct list rot; /* list of ROT entries */
     CRITICAL_SECTION lock;
 } RunningObjectTableImpl;
 
-static RunningObjectTableImpl* runningObjectTableInstance = NULL;
-static IrotHandle irot_handle;
-
 /* define the EnumMonikerImpl structure */
 typedef struct EnumMonikerImpl
 {
@@ -256,85 +251,18 @@ RunningObjectTableImpl_QueryInterface(IRunningObjectTable* iface,
     return S_OK;
 }
 
-/***********************************************************************
- *        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)
+static ULONG WINAPI RunningObjectTableImpl_AddRef(IRunningObjectTable *iface)
 {
-    struct list *cursor, *cursor2;
-    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);
+    TRACE("%p\n", iface);
 
-    /* free the ROT structure memory */
-    HeapFree(GetProcessHeap(),0,runningObjectTableInstance);
-    runningObjectTableInstance = NULL;
-
-    old_handle = irot_handle;
-    irot_handle = NULL;
-    if (old_handle)
-        RpcBindingFree(&old_handle);
-
-    return S_OK;
+    return 2;
 }
 
-/***********************************************************************
- *        RunningObjectTable_Release
- */
-static ULONG WINAPI
-RunningObjectTableImpl_Release(IRunningObjectTable* iface)
+static ULONG WINAPI RunningObjectTableImpl_Release(IRunningObjectTable *iface)
 {
-    RunningObjectTableImpl *This = impl_from_IRunningObjectTable(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
-         */
-    }
+    TRACE("%p\n", iface);
 
-    return ref;
+    return 1;
 }
 
 /***********************************************************************
@@ -775,82 +703,48 @@ static const IRunningObjectTableVtbl VT_RunningObjectTableImpl =
     RunningObjectTableImpl_EnumRunning
 };
 
-/***********************************************************************
- *        RunningObjectTable_Initialize
- */
-HRESULT WINAPI RunningObjectTableImpl_Initialize(void)
+static RunningObjectTableImpl rot =
 {
-    TRACE("\n");
-
-    /* create the unique instance of the RunningObjectTableImpl structure */
-    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;
-}
+    .IRunningObjectTable_iface.lpVtbl = &VT_RunningObjectTableImpl,
+    .lock.LockCount = -1,
+    .rot = LIST_INIT(rot.rot),
+};
 
 /***********************************************************************
- *        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)
-        return E_POINTER;
+    if (reserved!=0)
+        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;
 }
 
 /***********************************************************************
- *           GetRunningObjectTable (OLE32.@)
- *
- * Retrieves the global running object table.
- *
- * 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)
+ *        DestroyRunningObjectTable    (ole32.@)
+*/
+void WINAPI DestroyRunningObjectTable(void)
 {
-    IID riid=IID_IRunningObjectTable;
-    HRESULT res;
-
-    TRACE("()\n");
-
-    if (reserved!=0)
-        return E_UNEXPECTED;
-
-    if(runningObjectTableInstance==NULL)
-        return CO_E_NOTINITIALIZED;
+    struct rot_entry *rot_entry, *cursor2;
 
-    res = IRunningObjectTable_QueryInterface(&runningObjectTableInstance->IRunningObjectTable_iface,
-                                             &riid,(void**)pprot);
+    TRACE("\n");
 
-    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,
diff --git a/dlls/ole32/ole32.spec b/dlls/ole32/ole32.spec
index 4908729d1f..c102bce177 100644
--- a/dlls/ole32/ole32.spec
+++ b/dlls/ole32/ole32.spec
@@ -106,6 +106,7 @@
 @ stdcall CreateOleAdviseHolder(ptr)
 @ stdcall CreatePointerMoniker(ptr ptr)
 @ stdcall CreateStreamOnHGlobal(ptr long ptr)
+@ stdcall DestroyRunningObjectTable()
 @ stdcall DllDebugObjectRPCHook(long ptr)
 @ stdcall -private DllGetClassObject (ptr ptr ptr)
 @ stub DllGetClassObjectWOW




More information about the wine-cvs mailing list