From e128f7806961b391cfb265a1ce009b2e036622ca Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Sun, 4 Nov 2018 15:28:37 +0300 Subject: replace double-checked locking patterns with thread safe local statics Change-Id: I1bf67196e97411aeecc13ed4f91d1088a315e323 Reviewed-on: https://gerrit.libreoffice.org/62839 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- pyuno/source/module/pyuno_module.cxx | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) (limited to 'pyuno') diff --git a/pyuno/source/module/pyuno_module.cxx b/pyuno/source/module/pyuno_module.cxx index 0f08ebc53367..8456abfbfff2 100644 --- a/pyuno/source/module/pyuno_module.cxx +++ b/pyuno/source/module/pyuno_module.cxx @@ -202,26 +202,20 @@ void fillStruct( OUString getLibDir() { - static OUString *pLibDir; - if( !pLibDir ) - { - osl::MutexGuard guard( osl::Mutex::getGlobalMutex() ); - if( ! pLibDir ) - { - static OUString libDir; + static OUString sLibDir = []() { + OUString libDir; - // workarounds the $(ORIGIN) until it is available - if( Module::getUrlFromAddress( - reinterpret_cast< oslGenericFunction >(getLibDir), libDir ) ) - { - libDir = libDir.copy( 0, libDir.lastIndexOf('/') ); - OUString name ( "PYUNOLIBDIR" ); - rtl_bootstrap_set( name.pData, libDir.pData ); - } - pLibDir = &libDir; + // workarounds the $(ORIGIN) until it is available + if (Module::getUrlFromAddress(reinterpret_cast(getLibDir), libDir)) + { + libDir = libDir.copy(0, libDir.lastIndexOf('/')); + OUString name("PYUNOLIBDIR"); + rtl_bootstrap_set(name.pData, libDir.pData); } - } - return *pLibDir; + return libDir; + }(); + + return sLibDir; } void raisePySystemException( const char * exceptionType, const OUString & message ) -- cgit