Kaydet (Commit) 71b6f3d9 authored tarafından Caolán McNamara's avatar Caolán McNamara

use rtl::Static where double-locked pattern used

üst 44d24455
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
// MARKER(update_precomp.py): autogen include statement, do not remove // MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_cppuhelper.hxx" #include "precompiled_cppuhelper.hxx"
#include "rtl/instance.hxx"
#include "osl/diagnose.h" #include "osl/diagnose.h"
#include "osl/doublecheckedlocking.h" #include "osl/doublecheckedlocking.h"
#include "osl/mutex.hxx" #include "osl/mutex.hxx"
...@@ -58,8 +59,6 @@ struct ExceptionThrower : public uno_Interface, XExceptionThrower ...@@ -58,8 +59,6 @@ struct ExceptionThrower : public uno_Interface, XExceptionThrower
{ {
inline ExceptionThrower(); inline ExceptionThrower();
public:
static ExceptionThrower * get();
static inline Type const & getCppuType() static inline Type const & getCppuType()
{ {
return ::getCppuType( return ::getCppuType(
...@@ -188,23 +187,7 @@ inline ExceptionThrower::ExceptionThrower() ...@@ -188,23 +187,7 @@ inline ExceptionThrower::ExceptionThrower()
uno_Interface::pDispatcher = ExceptionThrower_dispatch; uno_Interface::pDispatcher = ExceptionThrower_dispatch;
} }
//______________________________________________________________________________ class theExceptionThrower : public rtl::Static<ExceptionThrower, theExceptionThrower> {};
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;
}
} // anonymous namespace } // anonymous namespace
...@@ -234,7 +217,7 @@ void SAL_CALL throwException( Any const & exc ) SAL_THROW( (Exception) ) ...@@ -234,7 +217,7 @@ void SAL_CALL throwException( Any const & exc ) SAL_THROW( (Exception) )
Reference< XExceptionThrower > xThrower; Reference< XExceptionThrower > xThrower;
uno2cpp.mapInterface( uno2cpp.mapInterface(
reinterpret_cast< void ** >( &xThrower ), reinterpret_cast< void ** >( &xThrower ),
static_cast< uno_Interface * >( ExceptionThrower::get() ), static_cast< uno_Interface * >( &theExceptionThrower::get() ),
ExceptionThrower::getCppuType() ); ExceptionThrower::getCppuType() );
OSL_ASSERT( xThrower.is() ); OSL_ASSERT( xThrower.is() );
xThrower->throwException( exc ); xThrower->throwException( exc );
...@@ -265,7 +248,7 @@ Any SAL_CALL getCaughtException() ...@@ -265,7 +248,7 @@ Any SAL_CALL getCaughtException()
UnoInterfaceReference unoI; UnoInterfaceReference unoI;
cpp2uno.mapInterface( cpp2uno.mapInterface(
reinterpret_cast< void ** >( &unoI.m_pUnoI ), reinterpret_cast< void ** >( &unoI.m_pUnoI ),
static_cast< XExceptionThrower * >( ExceptionThrower::get() ), pTD ); static_cast< XExceptionThrower * >( &theExceptionThrower::get() ), pTD );
OSL_ASSERT( unoI.is() ); OSL_ASSERT( unoI.is() );
typelib_TypeDescription * pMemberTD = 0; typelib_TypeDescription * pMemberTD = 0;
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <cppuhelper/factory.hxx> #include <cppuhelper/factory.hxx>
#include <cppuhelper/implbase3.hxx> #include <cppuhelper/implbase3.hxx>
#include <cppuhelper/typeprovider.hxx> #include <cppuhelper/typeprovider.hxx>
#include <rtl/instance.hxx>
#include <rtl/unload.h> #include <rtl/unload.h>
#include "cppuhelper/propshlp.hxx" #include "cppuhelper/propshlp.hxx"
...@@ -421,20 +422,16 @@ Sequence< Type > OFactoryComponentHelper::getTypes() ...@@ -421,20 +422,16 @@ Sequence< Type > OFactoryComponentHelper::getTypes()
return Sequence< Type >( ar, m_fptr ? 4 : 3 ); return Sequence< Type >( ar, m_fptr ? 4 : 3 );
} }
namespace
{
class theOFactoryComponentHelperImplementationId :
public rtl::Static<OImplementationId, theOFactoryComponentHelperImplementationId>{};
}
Sequence< sal_Int8 > OFactoryComponentHelper::getImplementationId() Sequence< sal_Int8 > OFactoryComponentHelper::getImplementationId()
throw (::com::sun::star::uno::RuntimeException) throw (::com::sun::star::uno::RuntimeException)
{ {
static OImplementationId * pId = 0; return theOFactoryComponentHelperImplementationId::get().getImplementationId();
if (! pId)
{
MutexGuard aGuard( Mutex::getGlobalMutex() );
if (! pId)
{
static OImplementationId aId;
pId = &aId;
}
}
return pId->getImplementationId();
} }
// XSingleServiceFactory // XSingleServiceFactory
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <cppuhelper/implbase.hxx> #include <cppuhelper/implbase.hxx>
#include <cppuhelper/compbase.hxx> #include <cppuhelper/compbase.hxx>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <rtl/instance.hxx>
#include <rtl/uuid.h> #include <rtl/uuid.h>
#include <com/sun/star/lang/XComponent.hpp> #include <com/sun/star/lang/XComponent.hpp>
...@@ -41,22 +42,17 @@ using namespace ::rtl; ...@@ -41,22 +42,17 @@ using namespace ::rtl;
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
namespace
{
class theImplHelperInitMutex : public rtl::Static<Mutex, theImplHelperInitMutex>{};
}
namespace cppu namespace cppu
{ {
//================================================================================================== //==================================================================================================
Mutex & SAL_CALL getImplHelperInitMutex(void) SAL_THROW( () ) Mutex & SAL_CALL getImplHelperInitMutex(void) SAL_THROW( () )
{ {
static Mutex * s_pMutex = 0; return theImplHelperInitMutex::get();
if (! s_pMutex)
{
MutexGuard aGuard( Mutex::getGlobalMutex() );
if (! s_pMutex)
{
static Mutex s_aMutex;
s_pMutex = & s_aMutex;
}
}
return * s_pMutex;
} }
// ClassDataBase // ClassDataBase
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "osl/module.hxx" #include "osl/module.hxx"
#include "rtl/unload.h" #include "rtl/unload.h"
#include "rtl/ustrbuf.hxx" #include "rtl/ustrbuf.hxx"
#include "rtl/instance.hxx"
#include "uno/environment.h" #include "uno/environment.h"
#include "uno/mapping.hxx" #include "uno/mapping.hxx"
#include "cppuhelper/factory.hxx" #include "cppuhelper/factory.hxx"
...@@ -71,21 +72,20 @@ static inline void out( const OUString & r ) throw () ...@@ -71,21 +72,20 @@ static inline void out( const OUString & r ) throw ()
} }
#endif #endif
//------------------------------------------------------------------------------ namespace
static const ::std::vector< OUString > * getAccessDPath() SAL_THROW( () )
{ {
static ::std::vector< OUString > * s_p = 0; class buildAccessDPath
static bool s_bInit = false;
if (! s_bInit)
{ {
::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); private:
if (! s_bInit) ::std::vector< OUString > m_aAccessDPath;
bool m_bCPLD_ACCESSPATHSet;
public:
buildAccessDPath() : m_bCPLD_ACCESSPATHSet(false)
{ {
const char * pEnv = ::getenv( "CPLD_ACCESSPATH" ); const char * pEnv = ::getenv( "CPLD_ACCESSPATH" );
if (pEnv) if (pEnv)
{ {
static ::std::vector< OUString > s_v; m_bCPLD_ACCESSPATHSet = true;
OString aEnv( pEnv ); OString aEnv( pEnv );
sal_Int32 nIndex = 0; sal_Int32 nIndex = 0;
...@@ -100,34 +100,39 @@ static const ::std::vector< OUString > * getAccessDPath() SAL_THROW( () ) ...@@ -100,34 +100,39 @@ static const ::std::vector< OUString > * getAccessDPath() SAL_THROW( () )
{ {
OSL_ASSERT(false); OSL_ASSERT(false);
} }
s_v.push_back( aFileUrl ); m_aAccessDPath.push_back( aFileUrl );
} while( nIndex != -1 ); } while( nIndex != -1 );
#if OSL_DEBUG_LEVEL > 1 #if OSL_G_LEVEL > 1
out( "> cpld: acknowledged following access path(s): \"" ); out( "> cpld: acknowledged following access path(s): \"" );
::std::vector< OUString >::const_iterator iPos( s_v.begin() ); ::std::vector< OUString >::const_iterator iPos( m_aAccessDPath.begin() );
while (iPos != s_v.end()) while (iPos != m_aAccessDPath.end())
{ {
out( *iPos ); out( *iPos );
++iPos; ++iPos;
if (iPos != s_v.end()) if (iPos != m_aAccessDPath.end())
out( ";" ); out( ";" );
} }
out( "\"\n" ); out( "\"\n" );
#endif #endif
s_p = & s_v;
} }
else else
{ {
// no access path env set // no access path env set
#if OSL_DEBUG_LEVEL > 1 #if OSL_G_LEVEL > 1
out( "=> no CPLD_ACCESSPATH set.\n" ); 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();
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment