Kaydet (Commit) e07253e0 authored tarafından Mike Kaganski's avatar Mike Kaganski

replace double-checked locking patterns with thread safe local statics

Change-Id: I4ed97cc6d9f733292156d71551d5ce3af6071445
Reviewed-on: https://gerrit.libreoffice.org/62858
Tested-by: Jenkins
Reviewed-by: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 212ea275
...@@ -108,12 +108,7 @@ static cppu::IPropertyArrayHelper * createPropertyArrayHelper( ...@@ -108,12 +108,7 @@ static cppu::IPropertyArrayHelper * createPropertyArrayHelper(
Statics & getStatics() Statics & getStatics()
{ {
static Statics * p; static Statics* p = []() {
if( ! p )
{
::osl::MutexGuard guard( ::osl::Mutex::getGlobalMutex() );
if( ! p )
{
static Statics statics ; static Statics statics ;
statics.SYSTEM_TABLE = "SYSTEM TABLE"; statics.SYSTEM_TABLE = "SYSTEM TABLE";
statics.TABLE = "TABLE"; statics.TABLE = "TABLE";
...@@ -665,9 +660,8 @@ Statics & getStatics() ...@@ -665,9 +660,8 @@ Statics & getStatics()
defTypeInfoMetaData[i].isAutoIncrement ) ); defTypeInfoMetaData[i].isAutoIncrement ) );
} }
p = &statics; return &statics;
} }();
}
return *p; return *p;
} }
......
...@@ -20,13 +20,6 @@ namespace ...@@ -20,13 +20,6 @@ namespace
typedef std::unordered_map<const char*, const char*, rtl::CStringHash, rtl::CStringEqual> typedef std::unordered_map<const char*, const char*, rtl::CStringHash, rtl::CStringEqual>
PresetGeometryHashMap; PresetGeometryHashMap;
static PresetGeometryHashMap* pHashMap = nullptr;
::osl::Mutex& getHashMapMutex()
{
static osl::Mutex s_aHashMapProtection;
return s_aHashMapProtection;
}
struct PresetGeometryName struct PresetGeometryName
{ {
const char* pMsoName; const char* pMsoName;
...@@ -79,27 +72,20 @@ static const PresetGeometryName pPresetGeometryNameArray[] ...@@ -79,27 +72,20 @@ static const PresetGeometryName pPresetGeometryNameArray[]
OUString PresetGeometryTypeNames::GetFontworkType(const OUString& rMsoType) OUString PresetGeometryTypeNames::GetFontworkType(const OUString& rMsoType)
{ {
if (!pHashMap) static const PresetGeometryHashMap s_HashMap = []() {
{ // init hash map PresetGeometryHashMap aH;
::osl::MutexGuard aGuard(getHashMapMutex()); for (const auto& item : pPresetGeometryNameArray)
if (!pHashMap) aH[item.pMsoName] = item.pFontworkType;
{ return aH;
PresetGeometryHashMap* pH = new PresetGeometryHashMap; }();
const PresetGeometryName* pPtr = pPresetGeometryNameArray;
const PresetGeometryName* pEnd = pPtr + SAL_N_ELEMENTS(pPresetGeometryNameArray);
for (; pPtr < pEnd; pPtr++)
(*pH)[pPtr->pMsoName] = pPtr->pFontworkType;
pHashMap = pH;
}
}
const char* pRetValue = ""; const char* pRetValue = "";
int i, nLen = rMsoType.getLength(); int i, nLen = rMsoType.getLength();
std::unique_ptr<char[]> pBuf(new char[nLen + 1]); std::unique_ptr<char[]> pBuf(new char[nLen + 1]);
for (i = 0; i < nLen; i++) for (i = 0; i < nLen; i++)
pBuf[i] = static_cast<char>(rMsoType[i]); pBuf[i] = static_cast<char>(rMsoType[i]);
pBuf[i] = 0; pBuf[i] = 0;
PresetGeometryHashMap::const_iterator aHashIter(pHashMap->find(pBuf.get())); PresetGeometryHashMap::const_iterator aHashIter(s_HashMap.find(pBuf.get()));
if (aHashIter != pHashMap->end()) if (aHashIter != s_HashMap.end())
pRetValue = (*aHashIter).second; pRetValue = (*aHashIter).second;
return OUString(pRetValue, strlen(pRetValue), RTL_TEXTENCODING_ASCII_US); return OUString(pRetValue, strlen(pRetValue), RTL_TEXTENCODING_ASCII_US);
......
...@@ -53,23 +53,10 @@ OInputSeekStream::~OInputSeekStream() ...@@ -53,23 +53,10 @@ OInputSeekStream::~OInputSeekStream()
uno::Sequence< uno::Type > SAL_CALL OInputSeekStream::getTypes() uno::Sequence< uno::Type > SAL_CALL OInputSeekStream::getTypes()
{ {
static ::cppu::OTypeCollection* pTypeCollection = nullptr ; static cppu::OTypeCollection aTypeCollection(cppu::UnoType<io::XSeekable>::get(),
OInputCompStream::getTypes());
if ( pTypeCollection == nullptr ) return aTypeCollection.getTypes();
{
::osl::MutexGuard aGuard( m_xMutex->GetMutex() ) ;
if ( pTypeCollection == nullptr )
{
static ::cppu::OTypeCollection aTypeCollection(
cppu::UnoType<io::XSeekable>::get(),
OInputCompStream::getTypes() );
pTypeCollection = &aTypeCollection ;
}
}
return pTypeCollection->getTypes() ;
} }
uno::Any SAL_CALL OInputSeekStream::queryInterface( const uno::Type& rType ) uno::Any SAL_CALL OInputSeekStream::queryInterface( const uno::Type& rType )
......
...@@ -39,36 +39,21 @@ OFSInputStreamContainer::~OFSInputStreamContainer() ...@@ -39,36 +39,21 @@ OFSInputStreamContainer::~OFSInputStreamContainer()
uno::Sequence< uno::Type > SAL_CALL OFSInputStreamContainer::getTypes() uno::Sequence< uno::Type > SAL_CALL OFSInputStreamContainer::getTypes()
{ {
static ::cppu::OTypeCollection* pTypeCollection = nullptr ; if (m_bSeekable)
if ( pTypeCollection == nullptr )
{ {
::osl::MutexGuard aGuard( m_aMutex ) ; static cppu::OTypeCollection aTypeCollection(cppu::UnoType<io::XStream>::get(),
cppu::UnoType<io::XInputStream>::get(),
if ( pTypeCollection == nullptr ) cppu::UnoType<io::XSeekable>::get());
{
if ( m_bSeekable )
{
static ::cppu::OTypeCollection aTypeCollection(
cppu::UnoType<io::XStream>::get(),
cppu::UnoType<io::XInputStream>::get(),
cppu::UnoType<io::XSeekable>::get());
pTypeCollection = &aTypeCollection ;
}
else
{
static ::cppu::OTypeCollection aTypeCollection(
cppu::UnoType<io::XStream>::get(),
cppu::UnoType<io::XInputStream>::get());
pTypeCollection = &aTypeCollection ;
}
}
}
return pTypeCollection->getTypes() ; return aTypeCollection.getTypes();
}
else
{
static cppu::OTypeCollection aTypeCollection(cppu::UnoType<io::XStream>::get(),
cppu::UnoType<io::XInputStream>::get());
return aTypeCollection.getTypes();
}
} }
uno::Any SAL_CALL OFSInputStreamContainer::queryInterface( const uno::Type& rType ) uno::Any SAL_CALL OFSInputStreamContainer::queryInterface( const uno::Type& rType )
......
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