diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2018-11-04 12:48:59 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2018-11-04 11:49:42 +0100 |
commit | a2058e7516a01167c2d20ed157500b38db967c64 (patch) | |
tree | 375dc0fd109e36bc490ee7e04d2201cee10e4cf2 /cppu | |
parent | b156ca6e4692c2a32f41b9dfcd543966efc64a5d (diff) |
replace double-checked locking patterns with thread safe local statics
Change-Id: Ie1aae7ecbd065a88b371d8c0deb586f54f7eff65
Reviewed-on: https://gerrit.libreoffice.org/62835
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'cppu')
-rw-r--r-- | cppu/source/threadpool/current.cxx | 88 |
1 files changed, 37 insertions, 51 deletions
diff --git a/cppu/source/threadpool/current.cxx b/cppu/source/threadpool/current.cxx index ed8891fabf8f..cd769c046d3f 100644 --- a/cppu/source/threadpool/current.cxx +++ b/cppu/source/threadpool/current.cxx @@ -42,57 +42,43 @@ namespace cppu static typelib_InterfaceTypeDescription * get_type_XCurrentContext() { - static typelib_InterfaceTypeDescription * s_type_XCurrentContext = nullptr; - if (nullptr == s_type_XCurrentContext) - { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - if (nullptr == s_type_XCurrentContext) - { - OUString sTypeName("com.sun.star.uno.XCurrentContext"); - typelib_InterfaceTypeDescription * pTD = nullptr; - typelib_TypeDescriptionReference * pMembers[1] = { nullptr }; - OUString sMethodName0("com.sun.star.uno.XCurrentContext::getValueByName"); - typelib_typedescriptionreference_new( - &pMembers[0], - typelib_TypeClass_INTERFACE_METHOD, - sMethodName0.pData ); - typelib_typedescription_newInterface( - &pTD, - sTypeName.pData, 0, 0, 0, 0, 0, - * typelib_static_type_getByTypeClass( typelib_TypeClass_INTERFACE ), - 1, - pMembers ); - - typelib_typedescription_register( reinterpret_cast<typelib_TypeDescription**>(&pTD) ); - typelib_typedescriptionreference_release( pMembers[0] ); - - typelib_InterfaceMethodTypeDescription * pMethod = nullptr; - typelib_Parameter_Init aParameters[1]; - OUString sParamName0("Name"); - OUString sParamType0("string"); - aParameters[0].pParamName = sParamName0.pData; - aParameters[0].eTypeClass = typelib_TypeClass_STRING; - aParameters[0].pTypeName = sParamType0.pData; - aParameters[0].bIn = true; - aParameters[0].bOut = false; - rtl_uString * pExceptions[1]; - OUString sExceptionName0("com.sun.star.uno.RuntimeException"); - pExceptions[0] = sExceptionName0.pData; - OUString sReturnType0("any"); - typelib_typedescription_newInterfaceMethod( - &pMethod, - 3, false, - sMethodName0.pData, - typelib_TypeClass_ANY, sReturnType0.pData, - 1, aParameters, 1, pExceptions ); - typelib_typedescription_register( reinterpret_cast<typelib_TypeDescription**>(&pMethod) ); - typelib_typedescription_release( &pMethod->aBase.aBase ); - // another static ref: - ++reinterpret_cast< typelib_TypeDescription * >( pTD )-> - nStaticRefCount; - s_type_XCurrentContext = pTD; - } - } + static typelib_InterfaceTypeDescription* s_type_XCurrentContext = []() { + OUString sTypeName("com.sun.star.uno.XCurrentContext"); + typelib_InterfaceTypeDescription* pTD = nullptr; + typelib_TypeDescriptionReference* pMembers[1] = { nullptr }; + OUString sMethodName0("com.sun.star.uno.XCurrentContext::getValueByName"); + typelib_typedescriptionreference_new(&pMembers[0], typelib_TypeClass_INTERFACE_METHOD, + sMethodName0.pData); + typelib_typedescription_newInterface( + &pTD, sTypeName.pData, 0, 0, 0, 0, 0, + *typelib_static_type_getByTypeClass(typelib_TypeClass_INTERFACE), 1, pMembers); + + typelib_typedescription_register(reinterpret_cast<typelib_TypeDescription**>(&pTD)); + typelib_typedescriptionreference_release(pMembers[0]); + + typelib_InterfaceMethodTypeDescription* pMethod = nullptr; + typelib_Parameter_Init aParameters[1]; + OUString sParamName0("Name"); + OUString sParamType0("string"); + aParameters[0].pParamName = sParamName0.pData; + aParameters[0].eTypeClass = typelib_TypeClass_STRING; + aParameters[0].pTypeName = sParamType0.pData; + aParameters[0].bIn = true; + aParameters[0].bOut = false; + rtl_uString* pExceptions[1]; + OUString sExceptionName0("com.sun.star.uno.RuntimeException"); + pExceptions[0] = sExceptionName0.pData; + OUString sReturnType0("any"); + typelib_typedescription_newInterfaceMethod(&pMethod, 3, false, sMethodName0.pData, + typelib_TypeClass_ANY, sReturnType0.pData, 1, + aParameters, 1, pExceptions); + typelib_typedescription_register(reinterpret_cast<typelib_TypeDescription**>(&pMethod)); + typelib_typedescription_release(&pMethod->aBase.aBase); + // another static ref: + ++reinterpret_cast<typelib_TypeDescription*>(pTD)->nStaticRefCount; + return pTD; + }(); + return s_type_XCurrentContext; } |