summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2021-05-10 19:08:08 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-05-10 20:20:28 +0200
commite368cc61fa715e98fbc448c5b0edc781915f8385 (patch)
tree21bd7702fca35136f05f9c0e16589ce23bd652ec /unotools
parent158737c2aa29904b726829399f9f5b24345dd013 (diff)
reduce cost of locking in SvtModuleOptions
Change-Id: If9e0c275822b733d339845d16edfbc5942b4aa6f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115354 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'unotools')
-rw-r--r--unotools/source/config/moduleoptions.cxx36
1 files changed, 19 insertions, 17 deletions
diff --git a/unotools/source/config/moduleoptions.cxx b/unotools/source/config/moduleoptions.cxx
index ea3db01585c2..e9d9e84a8c06 100644
--- a/unotools/source/config/moduleoptions.cxx
+++ b/unotools/source/config/moduleoptions.cxx
@@ -779,23 +779,25 @@ osl::Mutex& impl_GetOwnStaticMutex()
*//*-*************************************************************************************************************/
SvtModuleOptions::SvtModuleOptions()
{
- // Global access, must be guarded (multithreading!)
- ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
-
+ // no need to take the mutex yet, shared_ptr/weak_ptr are thread-safe
m_pImpl = g_pModuleOptions.lock();
if( !m_pImpl )
{
- m_pImpl = std::make_shared<SvtModuleOptions_Impl>();
- g_pModuleOptions = m_pImpl;
- ItemHolder1::holdConfigItem(EItem::ModuleOptions);
+ // take the mutex, so we don't accidentally create more than one
+ ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
+
+ m_pImpl = g_pModuleOptions.lock();
+ if( !m_pImpl )
+ {
+ m_pImpl = std::make_shared<SvtModuleOptions_Impl>();
+ g_pModuleOptions = m_pImpl;
+ ItemHolder1::holdConfigItem(EItem::ModuleOptions);
+ }
}
}
SvtModuleOptions::~SvtModuleOptions()
{
- // Global access, must be guarded (multithreading!)
- ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
-
m_pImpl.reset();
}
@@ -809,13 +811,13 @@ SvtModuleOptions::~SvtModuleOptions()
*//*-*************************************************************************************************************/
bool SvtModuleOptions::IsModuleInstalled( EModule eModule ) const
{
- ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
+ // doesn't need mutex, never modified
return m_pImpl->IsModuleInstalled( eModule );
}
OUString SvtModuleOptions::GetFactoryName( EFactory eFactory ) const
{
- ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
+ // doesn't need mutex, never modified
return m_pImpl->GetFactoryName( eFactory );
}
@@ -873,25 +875,25 @@ void SvtModuleOptions::SetFactoryDefaultFilter( EFactory eFactory,
bool SvtModuleOptions::IsMath() const
{
- ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
+ // doesn't need mutex, never modified
return m_pImpl->IsModuleInstalled( EModule::MATH );
}
bool SvtModuleOptions::IsChart() const
{
- ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
+ // doesn't need mutex, never modified
return m_pImpl->IsModuleInstalled( EModule::CHART );
}
bool SvtModuleOptions::IsCalc() const
{
- ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
+ // doesn't need mutex, never modified
return m_pImpl->IsModuleInstalled( EModule::CALC );
}
bool SvtModuleOptions::IsDraw() const
{
- ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
+ // doesn't need mutex, never modified
return m_pImpl->IsModuleInstalled( EModule::DRAW );
}
@@ -903,13 +905,13 @@ bool SvtModuleOptions::IsWriter() const
bool SvtModuleOptions::IsImpress() const
{
- ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
+ // doesn't need mutex, never modified
return m_pImpl->IsModuleInstalled( EModule::IMPRESS );
}
bool SvtModuleOptions::IsDataBase() const
{
- ::osl::MutexGuard aGuard( impl_GetOwnStaticMutex() );
+ // doesn't need mutex, never modified
return m_pImpl->IsModuleInstalled( EModule::DATABASE );
}