diff options
Diffstat (limited to 'cppu')
-rw-r--r-- | cppu/source/typelib/static_types.cxx | 32 | ||||
-rw-r--r-- | cppu/source/uno/lbenv.cxx | 22 |
2 files changed, 18 insertions, 36 deletions
diff --git a/cppu/source/typelib/static_types.cxx b/cppu/source/typelib/static_types.cxx index d2b859b93cc8..f0787c19ae5c 100644 --- a/cppu/source/typelib/static_types.cxx +++ b/cppu/source/typelib/static_types.cxx @@ -39,6 +39,7 @@ #include <rtl/ustring.hxx> #include <rtl/ustrbuf.hxx> #include <rtl/memory.h> +#include <rtl/instance.hxx> #include <typelib/typedescription.h> @@ -114,19 +115,10 @@ static inline sal_Int32 newAlignedSize( } //-------------------------------------------------------------------------------------------------- -static Mutex & typelib_getStaticInitMutex() SAL_THROW( () ) + +namespace { - static Mutex * s_pMutex = 0; - if (! s_pMutex) - { - MutexGuard aGuard( Mutex::getGlobalMutex() ); - if (! s_pMutex) - { - static Mutex s_aMutex; - s_pMutex = &s_aMutex; - } - } - return *s_pMutex; + struct typelib_StaticInitMutex : public rtl::Static< Mutex, typelib_StaticInitMutex > {}; } // !for NOT REALLY WEAK TYPES only! @@ -159,7 +151,7 @@ typelib_TypeDescriptionReference ** SAL_CALL typelib_static_type_getByTypeClass( if (! s_aTypes[eTypeClass]) { - MutexGuard aGuard( typelib_getStaticInitMutex() ); + MutexGuard aGuard( typelib_StaticInitMutex::get() ); if (! s_aTypes[eTypeClass]) { static const char * s_aTypeNames[] = { @@ -332,7 +324,7 @@ void SAL_CALL typelib_static_type_init( { if (! *ppRef) { - MutexGuard aGuard( typelib_getStaticInitMutex() ); + MutexGuard aGuard( typelib_StaticInitMutex::get() ); if (! *ppRef) { OUString aTypeName( OUString::createFromAscii( pTypeName ) ); @@ -354,7 +346,7 @@ void SAL_CALL typelib_static_sequence_type_init( { if (! *ppRef) { - MutexGuard aGuard( typelib_getStaticInitMutex() ); + MutexGuard aGuard( typelib_StaticInitMutex::get() ); if (! *ppRef) { OUStringBuffer aBuf( 32 ); @@ -398,7 +390,7 @@ void init( if (! *ppRef) { - MutexGuard aGuard( typelib_getStaticInitMutex() ); + MutexGuard aGuard( typelib_StaticInitMutex::get() ); if (! *ppRef) { OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(eTypeClass) ); @@ -514,7 +506,7 @@ void SAL_CALL typelib_static_mi_interface_type_init( { if (! *ppRef) { - MutexGuard aGuard( typelib_getStaticInitMutex() ); + MutexGuard aGuard( typelib_StaticInitMutex::get() ); if (! *ppRef) { OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_INTERFACE) ); @@ -579,7 +571,7 @@ void SAL_CALL typelib_static_enum_type_init( { if (! *ppRef) { - MutexGuard aGuard( typelib_getStaticInitMutex() ); + MutexGuard aGuard( typelib_StaticInitMutex::get() ); if (! *ppRef) { OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_ENUM) ); @@ -621,7 +613,7 @@ void SAL_CALL typelib_static_array_type_init( { if (! *ppRef) { - MutexGuard aGuard( typelib_getStaticInitMutex() ); + MutexGuard aGuard( typelib_StaticInitMutex::get() ); if (! *ppRef) { OUStringBuffer aBuf( 32 ); @@ -693,7 +685,7 @@ void SAL_CALL typelib_static_union_type_init( { if (! *ppRef) { - MutexGuard aGuard( typelib_getStaticInitMutex() ); + MutexGuard aGuard( typelib_StaticInitMutex::get() ); if (! *ppRef) { OSL_ASSERT( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_UNION) ); diff --git a/cppu/source/uno/lbenv.cxx b/cppu/source/uno/lbenv.cxx index 90fa774764a9..b0c31a653162 100644 --- a/cppu/source/uno/lbenv.cxx +++ b/cppu/source/uno/lbenv.cxx @@ -44,6 +44,7 @@ #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" @@ -151,20 +152,9 @@ struct EnvironmentsData uno_memAlloc memAlloc, const OUString & rEnvDcp ); }; -//------------------------------------------------------------------------------ -static EnvironmentsData & getEnvironmentsData() +namespace { - static EnvironmentsData * s_p = 0; - if (! s_p) - { - ::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() ); - if (! s_p) - { - static EnvironmentsData s_obj; - s_p = &s_obj; - } - } - return *s_p; + struct theEnvironmentsData : public rtl::Static< EnvironmentsData, theEnvironmentsData > {}; } //============================================================================== @@ -610,7 +600,7 @@ static void SAL_CALL defenv_harden( uno_DefaultEnvironment * that = (uno_DefaultEnvironment *)pEnv; { - ::osl::MutexGuard guard( getEnvironmentsData().mutex ); + ::osl::MutexGuard guard( theEnvironmentsData::get().mutex ); if (1 == ::osl_incrementInterlockedCount( &that->nRef )) // is dead { that->nRef = 0; @@ -1160,7 +1150,7 @@ void SAL_CALL uno_direct_getEnvironment( OSL_ENSURE( ppEnv, "### null ptr!" ); OUString const & rEnvDcp = OUString::unacquired( &pEnvDcp ); - EnvironmentsData & rData = getEnvironmentsData(); + EnvironmentsData & rData = theEnvironmentsData::get(); ::osl::MutexGuard guard( rData.mutex ); rData.getEnvironment( ppEnv, rEnvDcp, pContext ); @@ -1181,7 +1171,7 @@ void SAL_CALL uno_getRegisteredEnvironments( rtl_uString * pEnvDcp ) SAL_THROW_EXTERN_C() { - EnvironmentsData & rData = getEnvironmentsData(); + EnvironmentsData & rData = theEnvironmentsData::get(); ::osl::MutexGuard guard( rData.mutex ); rData.getRegisteredEnvironments( |