diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-04-04 13:09:33 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-04-04 13:09:33 +0100 |
commit | c51c13ff92adbe1d3f22bee6d907132c48d16602 (patch) | |
tree | 16454dd8a7146e90c95d1ec0580e9fc3925abfc6 /cppuhelper | |
parent | 03e70541de65af207b5f5a580d402967c533b857 (diff) |
use rtl::Static where double-locked pattern used
Diffstat (limited to 'cppuhelper')
-rw-r--r-- | cppuhelper/source/exc_thrower.cxx | 25 | ||||
-rw-r--r-- | cppuhelper/source/factory.cxx | 19 | ||||
-rw-r--r-- | cppuhelper/source/implbase.cxx | 18 | ||||
-rw-r--r-- | cppuhelper/source/shlib.cxx | 47 |
4 files changed, 45 insertions, 64 deletions
diff --git a/cppuhelper/source/exc_thrower.cxx b/cppuhelper/source/exc_thrower.cxx index 8bf50f481..4db1888a2 100644 --- a/cppuhelper/source/exc_thrower.cxx +++ b/cppuhelper/source/exc_thrower.cxx @@ -29,6 +29,7 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_cppuhelper.hxx" +#include "rtl/instance.hxx" #include "osl/diagnose.h" #include "osl/doublecheckedlocking.h" #include "osl/mutex.hxx" @@ -58,8 +59,6 @@ struct ExceptionThrower : public uno_Interface, XExceptionThrower { inline ExceptionThrower(); -public: - static ExceptionThrower * get(); static inline Type const & getCppuType() { return ::getCppuType( @@ -188,23 +187,7 @@ inline ExceptionThrower::ExceptionThrower() uno_Interface::pDispatcher = ExceptionThrower_dispatch; } -//______________________________________________________________________________ -ExceptionThrower * ExceptionThrower::get() -{ - ExceptionThrower * s_pThrower = 0; - if (s_pThrower == 0) - { - MutexGuard guard( Mutex::getGlobalMutex() ); - static ExceptionThrower s_thrower; - OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); - s_pThrower = &s_thrower; - } - else - { - OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); - } - return s_pThrower; -} +class theExceptionThrower : public rtl::Static<ExceptionThrower, theExceptionThrower> {}; } // anonymous namespace @@ -234,7 +217,7 @@ void SAL_CALL throwException( Any const & exc ) SAL_THROW( (Exception) ) Reference< XExceptionThrower > xThrower; uno2cpp.mapInterface( reinterpret_cast< void ** >( &xThrower ), - static_cast< uno_Interface * >( ExceptionThrower::get() ), + static_cast< uno_Interface * >( &theExceptionThrower::get() ), ExceptionThrower::getCppuType() ); OSL_ASSERT( xThrower.is() ); xThrower->throwException( exc ); @@ -265,7 +248,7 @@ Any SAL_CALL getCaughtException() UnoInterfaceReference unoI; cpp2uno.mapInterface( reinterpret_cast< void ** >( &unoI.m_pUnoI ), - static_cast< XExceptionThrower * >( ExceptionThrower::get() ), pTD ); + static_cast< XExceptionThrower * >( &theExceptionThrower::get() ), pTD ); OSL_ASSERT( unoI.is() ); typelib_TypeDescription * pMemberTD = 0; diff --git a/cppuhelper/source/factory.cxx b/cppuhelper/source/factory.cxx index 89ef69171..63d22c877 100644 --- a/cppuhelper/source/factory.cxx +++ b/cppuhelper/source/factory.cxx @@ -35,6 +35,7 @@ #include <cppuhelper/factory.hxx> #include <cppuhelper/implbase3.hxx> #include <cppuhelper/typeprovider.hxx> +#include <rtl/instance.hxx> #include <rtl/unload.h> #include "cppuhelper/propshlp.hxx" @@ -421,20 +422,16 @@ Sequence< Type > OFactoryComponentHelper::getTypes() return Sequence< Type >( ar, m_fptr ? 4 : 3 ); } +namespace +{ + class theOFactoryComponentHelperImplementationId : + public rtl::Static<OImplementationId, theOFactoryComponentHelperImplementationId>{}; +} + Sequence< sal_Int8 > OFactoryComponentHelper::getImplementationId() throw (::com::sun::star::uno::RuntimeException) { - static OImplementationId * pId = 0; - if (! pId) - { - MutexGuard aGuard( Mutex::getGlobalMutex() ); - if (! pId) - { - static OImplementationId aId; - pId = &aId; - } - } - return pId->getImplementationId(); + return theOFactoryComponentHelperImplementationId::get().getImplementationId(); } // XSingleServiceFactory diff --git a/cppuhelper/source/implbase.cxx b/cppuhelper/source/implbase.cxx index c2b481f7f..77d0c469c 100644 --- a/cppuhelper/source/implbase.cxx +++ b/cppuhelper/source/implbase.cxx @@ -31,6 +31,7 @@ #include <cppuhelper/implbase.hxx> #include <cppuhelper/compbase.hxx> #include <osl/diagnose.h> +#include <rtl/instance.hxx> #include <rtl/uuid.h> #include <com/sun/star/lang/XComponent.hpp> @@ -41,22 +42,17 @@ using namespace ::rtl; using namespace ::com::sun::star; using namespace ::com::sun::star::uno; +namespace +{ + class theImplHelperInitMutex : public rtl::Static<Mutex, theImplHelperInitMutex>{}; +} + namespace cppu { //================================================================================================== Mutex & SAL_CALL getImplHelperInitMutex(void) SAL_THROW( () ) { - 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; + return theImplHelperInitMutex::get(); } // ClassDataBase diff --git a/cppuhelper/source/shlib.cxx b/cppuhelper/source/shlib.cxx index 0f75bd837..358aac184 100644 --- a/cppuhelper/source/shlib.cxx +++ b/cppuhelper/source/shlib.cxx @@ -35,6 +35,7 @@ #include "osl/module.hxx" #include "rtl/unload.h" #include "rtl/ustrbuf.hxx" +#include "rtl/instance.hxx" #include "uno/environment.h" #include "uno/mapping.hxx" #include "cppuhelper/factory.hxx" @@ -71,21 +72,20 @@ static inline void out( const OUString & r ) throw () } #endif -//------------------------------------------------------------------------------ -static const ::std::vector< OUString > * getAccessDPath() SAL_THROW( () ) +namespace { - static ::std::vector< OUString > * s_p = 0; - static bool s_bInit = false; - - if (! s_bInit) + class buildAccessDPath { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - if (! s_bInit) + private: + ::std::vector< OUString > m_aAccessDPath; + bool m_bCPLD_ACCESSPATHSet; + public: + buildAccessDPath() : m_bCPLD_ACCESSPATHSet(false) { const char * pEnv = ::getenv( "CPLD_ACCESSPATH" ); if (pEnv) { - static ::std::vector< OUString > s_v; + m_bCPLD_ACCESSPATHSet = true; OString aEnv( pEnv ); sal_Int32 nIndex = 0; @@ -100,34 +100,39 @@ static const ::std::vector< OUString > * getAccessDPath() SAL_THROW( () ) { OSL_ASSERT(false); } - s_v.push_back( aFileUrl ); + m_aAccessDPath.push_back( aFileUrl ); } while( nIndex != -1 ); -#if OSL_DEBUG_LEVEL > 1 + #if OSL_G_LEVEL > 1 out( "> cpld: acknowledged following access path(s): \"" ); - ::std::vector< OUString >::const_iterator iPos( s_v.begin() ); - while (iPos != s_v.end()) + ::std::vector< OUString >::const_iterator iPos( m_aAccessDPath.begin() ); + while (iPos != m_aAccessDPath.end()) { out( *iPos ); ++iPos; - if (iPos != s_v.end()) + if (iPos != m_aAccessDPath.end()) out( ";" ); } out( "\"\n" ); -#endif - s_p = & s_v; + #endif } else { // no access path env set -#if OSL_DEBUG_LEVEL > 1 + #if OSL_G_LEVEL > 1 out( "=> no CPLD_ACCESSPATH set.\n" ); -#endif + #endif } - s_bInit = true; } - } + ::std::vector< OUString >* getAccessDPath() { return m_bCPLD_ACCESSPATHSet ? &m_aAccessDPath : NULL; } + }; + + class theAccessDPath : public rtl::Static<buildAccessDPath, theAccessDPath> {}; +} - return s_p; +//------------------------------------------------------------------------------ +static const ::std::vector< OUString > * getAccessDPath() SAL_THROW( () ) +{ + return theAccessDPath::get().getAccessDPath(); } //------------------------------------------------------------------------------ |