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 @@
// 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;
......
......@@ -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
......
......@@ -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
......
......@@ -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();
}
//------------------------------------------------------------------------------
......
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