diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2021-11-08 21:01:19 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-11-09 08:28:56 +0100 |
commit | b3c6b3a274b4c89d3572010794897c65b26571aa (patch) | |
tree | 87493b0306663ac6c818a71df9f83831914e296b /cppu | |
parent | 926ac3c5e4b8eb425bc2db0366594acc0cf2c1ed (diff) |
rtl::Static to thread-safe static
Change-Id: I35e2a252708228bdbeaee557ef35763c64608653
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124884
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'cppu')
-rw-r--r-- | cppu/source/typelib/static_types.cxx | 27 | ||||
-rw-r--r-- | cppu/source/typelib/typelib.cxx | 49 | ||||
-rw-r--r-- | cppu/source/uno/lbenv.cxx | 13 |
3 files changed, 50 insertions, 39 deletions
diff --git a/cppu/source/typelib/static_types.cxx b/cppu/source/typelib/static_types.cxx index d94f8485f801..6b9a35ac9a06 100644 --- a/cppu/source/typelib/static_types.cxx +++ b/cppu/source/typelib/static_types.cxx @@ -24,7 +24,6 @@ #include <osl/mutex.hxx> #include <rtl/ustring.hxx> -#include <rtl/instance.hxx> #include <typelib/typedescription.h> #include "typelib.hxx" @@ -32,6 +31,15 @@ using namespace osl; +namespace +{ + Mutex& typelib_StaticInitMutex() + { + static Mutex SINGLETON; + return SINGLETON; + } +} + extern "C" { @@ -88,11 +96,6 @@ static sal_Int32 newAlignedSize( } -namespace -{ - struct typelib_StaticInitMutex : public rtl::Static< Mutex, typelib_StaticInitMutex > {}; -} - // !for NOT REALLY WEAK TYPES only! static typelib_TypeDescriptionReference * igetTypeByName( rtl_uString const * pTypeName ) { @@ -119,7 +122,7 @@ typelib_TypeDescriptionReference ** SAL_CALL typelib_static_type_getByTypeClass( if (! s_aTypes[eTypeClass]) { - MutexGuard aGuard( typelib_StaticInitMutex::get() ); + MutexGuard aGuard( typelib_StaticInitMutex() ); if (! s_aTypes[eTypeClass]) { static const char * s_aTypeNames[] = { @@ -280,7 +283,7 @@ void SAL_CALL typelib_static_type_init( { if (! *ppRef) { - MutexGuard aGuard( typelib_StaticInitMutex::get() ); + MutexGuard aGuard( typelib_StaticInitMutex() ); if (! *ppRef) { OUString aTypeName( OUString::createFromAscii( pTypeName ) ); @@ -300,7 +303,7 @@ void SAL_CALL typelib_static_sequence_type_init( if ( *ppRef) return; - MutexGuard aGuard( typelib_StaticInitMutex::get() ); + MutexGuard aGuard( typelib_StaticInitMutex() ); if ( *ppRef) return; @@ -338,7 +341,7 @@ void init( if ( *ppRef) return; - MutexGuard aGuard( typelib_StaticInitMutex::get() ); + MutexGuard aGuard( typelib_StaticInitMutex() ); if ( *ppRef) return; @@ -452,7 +455,7 @@ void SAL_CALL typelib_static_mi_interface_type_init( if ( *ppRef) return; - MutexGuard aGuard( typelib_StaticInitMutex::get() ); + MutexGuard aGuard( typelib_StaticInitMutex() ); if ( *ppRef) return; @@ -515,7 +518,7 @@ void SAL_CALL typelib_static_enum_type_init( if ( *ppRef) return; - MutexGuard aGuard( typelib_StaticInitMutex::get() ); + MutexGuard aGuard( typelib_StaticInitMutex() ); if ( *ppRef) return; diff --git a/cppu/source/typelib/typelib.cxx b/cppu/source/typelib/typelib.cxx index eadc2c3bdde9..650ac27c3ad9 100644 --- a/cppu/source/typelib/typelib.cxx +++ b/cppu/source/typelib/typelib.cxx @@ -33,7 +33,6 @@ #include <osl/interlck.h> #include <osl/mutex.hxx> #include <rtl/ustring.hxx> -#include <rtl/instance.hxx> #include <osl/diagnose.h> #include <typelib/typedescription.h> #include <uno/any2.h> @@ -273,14 +272,20 @@ TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl() SAL_INFO_IF( !maCallbacks.empty(), "cppu.typelib", "pCallbacks is not NULL or empty" ); }; -namespace { struct Init : public rtl::Static< TypeDescriptor_Init_Impl, Init > {}; } +namespace { +TypeDescriptor_Init_Impl& Init() +{ + static TypeDescriptor_Init_Impl SINGLETON; + return SINGLETON; +} +} extern "C" void SAL_CALL typelib_typedescription_registerCallback( void * pContext, typelib_typedescription_Callback pCallback ) SAL_THROW_EXTERN_C() { // todo mt safe: guard is no solution, can not acquire while calling callback! - TypeDescriptor_Init_Impl &rInit = Init::get(); + TypeDescriptor_Init_Impl &rInit = Init(); // OslGuard aGuard( rInit.getMutex() ); rInit.maCallbacks.push_back( CallbackEntry( pContext, pCallback ) ); } @@ -290,7 +295,7 @@ extern "C" void SAL_CALL typelib_typedescription_revokeCallback( void * pContext, typelib_typedescription_Callback pCallback ) SAL_THROW_EXTERN_C() { - TypeDescriptor_Init_Impl &rInit = Init::get(); + TypeDescriptor_Init_Impl &rInit = Init(); { // todo mt safe: guard is no solution, can not acquire while calling callback! // OslGuard aGuard( rInit.getMutex() ); @@ -326,7 +331,7 @@ static void typelib_typedescription_initTables( } } - MutexGuard aGuard( Init::get().maMutex ); + MutexGuard aGuard( Init().maMutex ); if( pTD->bComplete ) return; @@ -406,7 +411,7 @@ bool complete(typelib_TypeDescription ** ppTypeDescr, bool initTables) { typelib_TypeDescription * pTD = nullptr; // on demand access of complete td - TypeDescriptor_Init_Impl &rInit = Init::get(); + TypeDescriptor_Init_Impl &rInit = Init(); rInit.callChain( &pTD, (*ppTypeDescr)->pTypeName ); if (pTD) { @@ -493,7 +498,7 @@ extern "C" void typelib_typedescription_newEmpty( auto pTmp = allocTypeDescription<typelib_IndirectTypeDescription>(); pRet = &pTmp->aBase; #if OSL_DEBUG_LEVEL > 0 - osl_atomic_increment( &Init::get().nIndirectTypeDescriptionCount ); + osl_atomic_increment( &Init().nIndirectTypeDescriptionCount ); #endif pTmp->pType = nullptr; // coverity[leaked_storage] - this is on purpose @@ -506,7 +511,7 @@ extern "C" void typelib_typedescription_newEmpty( auto pTmp = allocTypeDescription<typelib_StructTypeDescription>(); pRet = &pTmp->aBase.aBase; #if OSL_DEBUG_LEVEL > 0 - osl_atomic_increment( &Init::get().nCompoundTypeDescriptionCount ); + osl_atomic_increment( &Init().nCompoundTypeDescriptionCount ); #endif pTmp->aBase.pBaseTypeDescription = nullptr; pTmp->aBase.nMembers = 0; @@ -524,7 +529,7 @@ extern "C" void typelib_typedescription_newEmpty( auto pTmp = allocTypeDescription<typelib_CompoundTypeDescription>(); pRet = &pTmp->aBase; #if OSL_DEBUG_LEVEL > 0 - osl_atomic_increment( &Init::get().nCompoundTypeDescriptionCount ); + osl_atomic_increment( &Init().nCompoundTypeDescriptionCount ); #endif pTmp->pBaseTypeDescription = nullptr; pTmp->nMembers = 0; @@ -540,7 +545,7 @@ extern "C" void typelib_typedescription_newEmpty( auto pTmp = allocTypeDescription<typelib_EnumTypeDescription>(); pRet = &pTmp->aBase; #if OSL_DEBUG_LEVEL > 0 - osl_atomic_increment( &Init::get().nEnumTypeDescriptionCount ); + osl_atomic_increment( &Init().nEnumTypeDescriptionCount ); #endif pTmp->nDefaultEnumValue = 0; pTmp->nEnumValues = 0; @@ -556,7 +561,7 @@ extern "C" void typelib_typedescription_newEmpty( typelib_InterfaceTypeDescription>(); pRet = &pTmp->aBase; #if OSL_DEBUG_LEVEL > 0 - osl_atomic_increment( &Init::get().nInterfaceTypeDescriptionCount ); + osl_atomic_increment( &Init().nInterfaceTypeDescriptionCount ); #endif pTmp->pBaseTypeDescription = nullptr; pTmp->nMembers = 0; @@ -578,7 +583,7 @@ extern "C" void typelib_typedescription_newEmpty( typelib_InterfaceMethodTypeDescription>(); pRet = &pTmp->aBase.aBase; #if OSL_DEBUG_LEVEL > 0 - osl_atomic_increment( &Init::get().nInterfaceMethodTypeDescriptionCount ); + osl_atomic_increment( &Init().nInterfaceMethodTypeDescriptionCount ); #endif pTmp->aBase.pMemberName = nullptr; pTmp->pReturnTypeRef = nullptr; @@ -599,7 +604,7 @@ extern "C" void typelib_typedescription_newEmpty( typelib_InterfaceAttributeTypeDescription>(); pRet = &pTmp->aBase.aBase; #if OSL_DEBUG_LEVEL > 0 - osl_atomic_increment( &Init::get().nInterfaceAttributeTypeDescriptionCount ); + osl_atomic_increment( &Init().nInterfaceAttributeTypeDescriptionCount ); #endif pTmp->aBase.pMemberName = nullptr; pTmp->pAttributeTypeRef = nullptr; @@ -618,7 +623,7 @@ extern "C" void typelib_typedescription_newEmpty( { pRet = allocTypeDescription<typelib_TypeDescription>(); #if OSL_DEBUG_LEVEL > 0 - osl_atomic_increment( &Init::get().nTypeDescriptionCount ); + osl_atomic_increment( &Init().nTypeDescriptionCount ); #endif } } @@ -1331,7 +1336,7 @@ extern "C" void SAL_CALL typelib_typedescription_release( if (0 != ref) return; - TypeDescriptor_Init_Impl &rInit = Init::get(); + TypeDescriptor_Init_Impl &rInit = Init(); if( TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK( pTD->eTypeClass ) ) { if( pTD->pWeakRef ) @@ -1395,7 +1400,7 @@ extern "C" void SAL_CALL typelib_typedescription_register( SAL_THROW_EXTERN_C() { // connect the description with the weak reference - TypeDescriptor_Init_Impl &rInit = Init::get(); + TypeDescriptor_Init_Impl &rInit = Init(); ClearableMutexGuard aGuard( rInit.maMutex ); typelib_TypeDescriptionReference * pTDR = nullptr; @@ -1873,7 +1878,7 @@ extern "C" void SAL_CALL typelib_typedescription_getByName( } static bool bInited = false; - TypeDescriptor_Init_Impl &rInit = Init::get(); + TypeDescriptor_Init_Impl &rInit = Init(); if( !bInited ) { @@ -2049,7 +2054,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_new( typelib_TypeClass eTypeClass, rtl_uString * pTypeName ) SAL_THROW_EXTERN_C() { - TypeDescriptor_Init_Impl &rInit = Init::get(); + TypeDescriptor_Init_Impl &rInit = Init(); if( eTypeClass == typelib_TypeClass_TYPEDEF ) { // on demand access @@ -2152,7 +2157,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_release( { if( ! osl_atomic_decrement( &pRef->nRefCount ) ) { - TypeDescriptor_Init_Impl &rInit = Init::get(); + TypeDescriptor_Init_Impl &rInit = Init(); MutexGuard aGuard( rInit.maMutex ); WeakMap_Impl::iterator aIt = rInit.maWeakMap.find( pRef->pTypeName->buffer ); if( aIt != rInit.maWeakMap.end() && (*aIt).second == pRef ) @@ -2195,7 +2200,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_getDescription( } { - MutexGuard aGuard( Init::get().maMutex ); + MutexGuard aGuard( Init().maMutex ); // pRef->pType->pWeakRef == 0 means that the description is empty if( pRef->pType && pRef->pType->pWeakRef ) { @@ -2231,7 +2236,7 @@ extern "C" void typelib_typedescriptionreference_getByName( typelib_typedescriptionreference_release( *ppRet ); *ppRet = nullptr; } - TypeDescriptor_Init_Impl &rInit = Init::get(); + TypeDescriptor_Init_Impl &rInit = Init(); MutexGuard aGuard( rInit.maMutex ); WeakMap_Impl::const_iterator aIt = rInit.maWeakMap.find( pName->buffer ); @@ -2287,7 +2292,7 @@ extern "C" void SAL_CALL typelib_setCacheSize( sal_Int32 nNewSize ) if (nNewSize < 0) return; - TypeDescriptor_Init_Impl &rInit = Init::get(); + TypeDescriptor_Init_Impl &rInit = Init(); MutexGuard aGuard( rInit.maMutex ); if (nNewSize < nCacheSize) { diff --git a/cppu/source/uno/lbenv.cxx b/cppu/source/uno/lbenv.cxx index 4af07c9d1944..f19d8e725e4f 100644 --- a/cppu/source/uno/lbenv.cxx +++ b/cppu/source/uno/lbenv.cxx @@ -33,7 +33,6 @@ #include <rtl/string.hxx> #include <rtl/ustring.hxx> #include <rtl/ustrbuf.hxx> -#include <rtl/instance.hxx> #include <typelib/typedescription.h> #include <uno/dispatcher.h> #include <uno/environment.h> @@ -127,7 +126,11 @@ struct EnvironmentsData bool isDisposing; }; -struct theEnvironmentsData : public rtl::Static< EnvironmentsData, theEnvironmentsData > {}; +EnvironmentsData& theEnvironmentsData() +{ + static EnvironmentsData SINGLETON; + return SINGLETON; +} struct uno_DefaultEnvironment : public uno_ExtEnvironment { @@ -563,7 +566,7 @@ static void defenv_harden( *ppHardEnv = nullptr; } - EnvironmentsData & rData = theEnvironmentsData::get(); + EnvironmentsData & rData = theEnvironmentsData(); if (rData.isDisposing) return; @@ -1110,7 +1113,7 @@ void SAL_CALL uno_getEnvironment( assert(ppEnv && "### null ptr!"); OUString const & rEnvDcp = OUString::unacquired( &pEnvDcp ); - EnvironmentsData & rData = theEnvironmentsData::get(); + EnvironmentsData & rData = theEnvironmentsData(); ::osl::MutexGuard guard( rData.mutex ); rData.getEnvironment( ppEnv, rEnvDcp, pContext ); @@ -1130,7 +1133,7 @@ void SAL_CALL uno_getRegisteredEnvironments( rtl_uString * pEnvDcp ) SAL_THROW_EXTERN_C() { - EnvironmentsData & rData = theEnvironmentsData::get(); + EnvironmentsData & rData = theEnvironmentsData(); ::osl::MutexGuard guard( rData.mutex ); rData.getRegisteredEnvironments( |