unotools/source/config/moduleoptions.cxx | 36 ++++++++++++++++--------------- 1 file changed, 19 insertions(+), 17 deletions(-)
New commits: commit e368cc61fa715e98fbc448c5b0edc781915f8385 Author: Noel Grandin <n...@peralex.com> AuthorDate: Mon May 10 19:08:08 2021 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon May 10 20:20:28 2021 +0200 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.gran...@collabora.co.uk> 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 ); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits