[Libreoffice-commits] core.git: embedserv/source

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Sun Jan 31 21:22:57 UTC 2021


 embedserv/source/embed/servprov.cxx |   47 ++----------------------------------
 1 file changed, 3 insertions(+), 44 deletions(-)

New commits:
commit 53584695ca1eb22d8f2a9d9e1cb281d68c38966e
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sun Jan 31 19:31:14 2021 +0100
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sun Jan 31 22:22:03 2021 +0100

    Simplify thread apartment initialization
    
    This also fixes a regression from commit
    4342e2206052c837816aa63d320e4d30033fa12d,
    which had made o2u_attachCurrentThread a no-op.
    From 2006, this initialization had never been executed.
    Is it unnecessary after all?
    
    Change-Id: I2ff942a913fa844f5e4627ba23ca34d1b864846b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110217
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/embedserv/source/embed/servprov.cxx b/embedserv/source/embed/servprov.cxx
index 46454667a42c..4d3eea9d3af2 100644
--- a/embedserv/source/embed/servprov.cxx
+++ b/embedserv/source/embed/servprov.cxx
@@ -43,50 +43,9 @@ const GUID* const guidList[ SUPPORTED_FACTORIES_NUM ] = {
     &OID_MathOASISServer
 };
 
-namespace {
-
-class CurThreadData
-{
-    public:
-        CurThreadData();
-        virtual ~CurThreadData();
-
-        bool setData(void *pData);
-
-        void* getData();
-
-    protected:
-        oslThreadKey m_hKey;
-};
-
-}
-
-CurThreadData::CurThreadData() : m_hKey(osl_createThreadKey( nullptr ))
-{
-}
-
-CurThreadData::~CurThreadData()
-{
-    osl_destroyThreadKey(m_hKey);
-}
-
-bool CurThreadData::setData(void *pData)
-{
-    OSL_ENSURE( m_hKey, "No thread key!" );
-    return osl_setThreadKeyData(m_hKey, pData);
-}
-
-void *CurThreadData::getData()
-{
-    OSL_ENSURE( m_hKey, "No thread key!" );
-    return osl_getThreadKeyData(m_hKey);
-}
-
 static void o2u_attachCurrentThread()
 {
-    static CurThreadData oleThreadData;
-
-    if ( oleThreadData.getData() != nullptr )
+    static thread_local bool aInit = []
     {
         HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
         if (!SUCCEEDED(hr))
@@ -95,8 +54,8 @@ static void o2u_attachCurrentThread()
             SAL_INFO("embedserv.ole",
                     "CoInitializeEx fail: probably thread is in STA already?");
         }
-        oleThreadData.setData(reinterpret_cast<void*>(true));
-    }
+        return SUCCEEDED(hr);
+    }();
 }
 
 


More information about the Libreoffice-commits mailing list