diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-04-02 16:47:11 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-04-03 21:43:00 +0100 |
commit | 723e74b5dc8465e6910729c84a7ecc81262c7e37 (patch) | |
tree | cc85d887712369970177904ef5d0f62d444d3287 /comphelper | |
parent | 3dfc2de702491e86dfeaaebd789f2143da6e3658 (diff) |
use rtl::Static where double-locked pattern used
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/inc/comphelper/accimplaccess.hxx | 2 | ||||
-rw-r--r-- | comphelper/source/misc/accimplaccess.cxx | 18 | ||||
-rw-r--r-- | comphelper/source/misc/comphelper_services.cxx | 20 | ||||
-rw-r--r-- | comphelper/source/property/propstate.cxx | 16 |
4 files changed, 25 insertions, 31 deletions
diff --git a/comphelper/inc/comphelper/accimplaccess.hxx b/comphelper/inc/comphelper/accimplaccess.hxx index 8ba9fe43867e..fbbee6fbfde6 100644 --- a/comphelper/inc/comphelper/accimplaccess.hxx +++ b/comphelper/inc/comphelper/accimplaccess.hxx @@ -154,7 +154,7 @@ namespace comphelper private: - COMPHELPER_DLLPRIVATE static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelImplementationId(); + COMPHELPER_DLLPRIVATE static const ::com::sun::star::uno::Sequence< sal_Int8 > getUnoTunnelImplementationId(); }; //......................................................................... diff --git a/comphelper/source/misc/accimplaccess.cxx b/comphelper/source/misc/accimplaccess.cxx index 7128d4e13991..e06df35cde0c 100644 --- a/comphelper/source/misc/accimplaccess.cxx +++ b/comphelper/source/misc/accimplaccess.cxx @@ -121,21 +121,13 @@ namespace comphelper return ( NULL != pImplementation ); } + namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; } + //--------------------------------------------------------------------- - const Sequence< sal_Int8 >& OAccessibleImplementationAccess::getUnoTunnelImplementationId() + const Sequence< sal_Int8 > OAccessibleImplementationAccess::getUnoTunnelImplementationId() { - static Sequence< sal_Int8 > aId; - if ( !aId.getLength() ) - { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - if ( !aId.getLength() ) - { - static ::cppu::OImplementationId aImplId; - // unfortunately, the OImplementationId::getImplementationId returns a copy, not a static reference ... - aId = aImplId.getImplementationId(); - } - } - return aId; + ::cppu::OImplementationId &rID = lcl_ImplId::get(); + return rID.getImplementationId(); } //--------------------------------------------------------------------- diff --git a/comphelper/source/misc/comphelper_services.cxx b/comphelper/source/misc/comphelper_services.cxx index b9cc41fe5b09..32d1c53aff93 100644 --- a/comphelper/source/misc/comphelper_services.cxx +++ b/comphelper/source/misc/comphelper_services.cxx @@ -30,6 +30,8 @@ #include "comphelper_module.hxx" +#include <rtl/instance.hxx> + //-------------------------------------------------------------------- extern void createRegistryInfo_OPropertyBag(); extern void createRegistryInfo_SequenceOutputStream(); @@ -49,13 +51,12 @@ namespace comphelper { namespace module { //........................................................................ - static void initializeModule() + namespace { - static bool bInitialized( false ); - if ( !bInitialized ) + class doInitialize { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - if ( !bInitialized ) + public: + doInitialize() { createRegistryInfo_OPropertyBag(); createRegistryInfo_SequenceOutputStream(); @@ -70,7 +71,14 @@ namespace comphelper { namespace module createRegistryInfo_OSimpleLogRing(); createRegistryInfo_OOfficeRestartManager(); } - } + }; + + struct theInitializer : public rtl::Static< doInitialize, theInitializer > {}; + } + + static void initializeModule() + { + theInitializer::get(); } //........................................................................ diff --git a/comphelper/source/property/propstate.cxx b/comphelper/source/property/propstate.cxx index 5be6c842a5f8..b58bdb6d0283 100644 --- a/comphelper/source/property/propstate.cxx +++ b/comphelper/source/property/propstate.cxx @@ -32,6 +32,7 @@ #include <com/sun/star/uno/genfunc.h> #include <cppuhelper/queryinterface.hxx> #include <comphelper/sequence.hxx> +#include <rtl/instance.hxx> //......................................................................... namespace comphelper @@ -217,20 +218,13 @@ namespace comphelper ); } + namespace { struct lcl_ImplId : public rtl::Static< ::cppu::OImplementationId, lcl_ImplId > {}; } + //--------------------------------------------------------------------- Sequence< sal_Int8 > SAL_CALL OStatefulPropertySet::getImplementationId() throw(RuntimeException) { - static ::cppu::OImplementationId * pId = NULL; - if ( !pId ) - { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - if ( !pId ) - { - static ::cppu::OImplementationId aId; - pId = &aId; - } - } - return pId->getImplementationId(); + ::cppu::OImplementationId &rID = lcl_ImplId::get(); + return rID.getImplementationId(); } //--------------------------------------------------------------------- |