From 53584695ca1eb22d8f2a9d9e1cb281d68c38966e Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sun, 31 Jan 2021 19:31:14 +0100 Subject: 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 --- embedserv/source/embed/servprov.cxx | 47 +++---------------------------------- 1 file changed, 3 insertions(+), 44 deletions(-) (limited to 'embedserv') 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(true)); - } + return SUCCEEDED(hr); + }(); } -- cgit