summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2021-11-18 20:24:57 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-11-19 07:33:34 +0100
commitf7a8c3cc4dc9a316b39e8680a2af330d8f8ba296 (patch)
tree89eeb3f9c2da4c5f459d4e778ac6c54625a99548 /unotools
parent4d3e4c1cf3f117b8abd8dd67843864bb4c2e5a2f (diff)
rtl::Static->thread-safe static in unotools
Change-Id: I2a8c9ca7c45a8e20f3d114722a0677b856a13d8c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125495 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'unotools')
-rw-r--r--unotools/source/config/bootstrap.cxx11
-rw-r--r--unotools/source/config/cmdoptions.cxx9
-rw-r--r--unotools/source/config/configmgr.cxx8
-rw-r--r--unotools/source/config/fontcfg.cxx24
-rw-r--r--unotools/source/config/lingucfg.cxx32
-rw-r--r--unotools/source/config/moduleoptions.cxx1
-rw-r--r--unotools/source/config/pathoptions.cxx14
-rw-r--r--unotools/source/config/syslocaleoptions.cxx10
-rw-r--r--unotools/source/i18n/textsearch.cxx1
-rw-r--r--unotools/source/ucbhelper/tempfile.cxx2
10 files changed, 47 insertions, 65 deletions
diff --git a/unotools/source/config/bootstrap.cxx b/unotools/source/config/bootstrap.cxx
index 51d3625e4af0..09c52157024b 100644
--- a/unotools/source/config/bootstrap.cxx
+++ b/unotools/source/config/bootstrap.cxx
@@ -32,7 +32,6 @@
#include <osl/diagnose.h>
#include <rtl/bootstrap.hxx>
-#include <rtl/instance.hxx>
#include <osl/process.h>
// #define this to true, if remembering defaults is not supported properly
@@ -112,12 +111,16 @@ private: // implementation
namespace
{
- class theImpl : public rtl::Static<Bootstrap::Impl, theImpl> {};
+ Bootstrap::Impl& theImpl()
+ {
+ static Bootstrap::Impl SINGLETON;
+ return SINGLETON;
+ }
}
const Bootstrap::Impl& Bootstrap::data()
{
- return theImpl::get();
+ return theImpl();
}
bool Bootstrap::getProcessWorkingDir(OUString &rUrl)
@@ -146,7 +149,7 @@ bool Bootstrap::getProcessWorkingDir(OUString &rUrl)
void Bootstrap::reloadData()
{
- theImpl::get().initialize();
+ theImpl().initialize();
}
// helper
diff --git a/unotools/source/config/cmdoptions.cxx b/unotools/source/config/cmdoptions.cxx
index b61e49840390..d9e061224a4a 100644
--- a/unotools/source/config/cmdoptions.cxx
+++ b/unotools/source/config/cmdoptions.cxx
@@ -27,7 +27,6 @@
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/frame/XFrame.hpp>
#include <cppuhelper/weakref.hxx>
-#include <rtl/instance.hxx>
#include "itemholder1.hxx"
@@ -340,16 +339,12 @@ void SvtCommandOptions::EstablishFrameCallback(const css::uno::Reference< css::f
m_pImpl->EstablishFrameCallback(xFrame);
}
-namespace
-{
- class theCommandOptionsMutex : public rtl::Static<osl::Mutex, theCommandOptionsMutex>{};
-}
-
// private method
Mutex& SvtCommandOptions::GetOwnStaticMutex()
{
- return theCommandOptionsMutex::get();
+ static osl::Mutex theCommandOptionsMutex;
+ return theCommandOptionsMutex;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/unotools/source/config/configmgr.cxx b/unotools/source/config/configmgr.cxx
index 84ab42cc795d..5b109788d2cd 100644
--- a/unotools/source/config/configmgr.cxx
+++ b/unotools/source/config/configmgr.cxx
@@ -28,7 +28,6 @@
#include <com/sun/star/uno/Sequence.hxx>
#include <i18nlangtag/languagetag.hxx>
#include <officecfg/Setup.hxx>
-#include <rtl/instance.hxx>
#include <rtl/ustring.hxx>
#include <sal/log.hxx>
#include <unotools/configitem.hxx>
@@ -67,10 +66,6 @@ getConfigurationProvider() {
return css::configuration::theDefaultProvider::get( comphelper::getProcessComponentContext() );
}
-struct theConfigManager:
- public rtl::Static< utl::ConfigManager, theConfigManager >
-{};
-
}
OUString utl::ConfigManager::getAboutBoxProductVersion() {
@@ -114,7 +109,8 @@ void utl::ConfigManager::storeConfigItems() {
}
utl::ConfigManager & utl::ConfigManager::getConfigManager() {
- return theConfigManager::get();
+ static utl::ConfigManager theConfigManager;
+ return theConfigManager;
}
css::uno::Reference< css::container::XHierarchicalNameAccess >
diff --git a/unotools/source/config/fontcfg.cxx b/unotools/source/config/fontcfg.cxx
index cfa6705a41c6..ef94981d7746 100644
--- a/unotools/source/config/fontcfg.cxx
+++ b/unotools/source/config/fontcfg.cxx
@@ -31,7 +31,6 @@
#include <comphelper/propertysequence.hxx>
#include <unotools/syslocale.hxx>
#include <rtl/ustrbuf.hxx>
-#include <rtl/instance.hxx>
#include <osl/diagnose.h>
#include <sal/macros.h>
#include <sal/log.hxx>
@@ -83,18 +82,10 @@ static const char* getKeyType( DefaultFontType nKeyType )
}
}
-namespace
-{
- class theDefaultFontConfiguration
- : public rtl::Static<DefaultFontConfiguration,
- theDefaultFontConfiguration>
- {
- };
-}
-
DefaultFontConfiguration& DefaultFontConfiguration::get()
{
- return theDefaultFontConfiguration::get();
+ static DefaultFontConfiguration theDefaultFontConfiguration;
+ return theDefaultFontConfiguration;
}
DefaultFontConfiguration::DefaultFontConfiguration()
@@ -297,17 +288,10 @@ OUString DefaultFontConfiguration::getUserInterfaceFont( const LanguageTag& rLan
* FontSubstConfigItem::get
*/
-namespace
-{
- class theFontSubstConfiguration
- : public rtl::Static<FontSubstConfiguration, theFontSubstConfiguration>
- {
- };
-}
-
FontSubstConfiguration& FontSubstConfiguration::get()
{
- return theFontSubstConfiguration::get();
+ static FontSubstConfiguration theFontSubstConfiguration;
+ return theFontSubstConfiguration;
}
/*
diff --git a/unotools/source/config/lingucfg.cxx b/unotools/source/config/lingucfg.cxx
index eaf4310ca314..f37fffb5734a 100644
--- a/unotools/source/config/lingucfg.cxx
+++ b/unotools/source/config/lingucfg.cxx
@@ -25,7 +25,6 @@
#include <com/sun/star/configuration/theDefaultProvider.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/util/XChangesBatch.hpp>
-#include <rtl/instance.hxx>
#include <sal/log.hxx>
#include <osl/mutex.hxx>
#include <tools/diagnose_ex.h>
@@ -47,8 +46,11 @@ constexpr OUStringLiteral FILE_PROTOCOL = u"file:///";
namespace
{
- class theSvtLinguConfigItemMutex :
- public rtl::Static< osl::Mutex, theSvtLinguConfigItemMutex > {};
+ osl::Mutex& theSvtLinguConfigItemMutex()
+ {
+ static osl::Mutex SINGLETON;
+ return SINGLETON;
+ }
}
static bool lcl_SetLocale( LanguageType &rLanguage, const uno::Any &rVal )
@@ -319,7 +321,7 @@ bool SvtLinguConfigItem::GetHdlByName(
uno::Any SvtLinguConfigItem::GetProperty( const OUString &rPropertyName ) const
{
- osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
+ osl::MutexGuard aGuard(theSvtLinguConfigItemMutex());
sal_Int32 nHdl;
return GetHdlByName( nHdl, rPropertyName ) ? GetProperty( nHdl ) : uno::Any();
@@ -327,7 +329,7 @@ uno::Any SvtLinguConfigItem::GetProperty( const OUString &rPropertyName ) const
uno::Any SvtLinguConfigItem::GetProperty( sal_Int32 nPropertyHandle ) const
{
- osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
+ osl::MutexGuard aGuard(theSvtLinguConfigItemMutex());
uno::Any aRes;
@@ -409,7 +411,7 @@ uno::Any SvtLinguConfigItem::GetProperty( sal_Int32 nPropertyHandle ) const
bool SvtLinguConfigItem::SetProperty( const OUString &rPropertyName, const uno::Any &rValue )
{
- osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
+ osl::MutexGuard aGuard(theSvtLinguConfigItemMutex());
bool bSucc = false;
sal_Int32 nHdl;
@@ -420,7 +422,7 @@ bool SvtLinguConfigItem::SetProperty( const OUString &rPropertyName, const uno::
bool SvtLinguConfigItem::SetProperty( sal_Int32 nPropertyHandle, const uno::Any &rValue )
{
- osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
+ osl::MutexGuard aGuard(theSvtLinguConfigItemMutex());
bool bSucc = false;
if (!rValue.hasValue())
@@ -559,13 +561,13 @@ bool SvtLinguConfigItem::SetProperty( sal_Int32 nPropertyHandle, const uno::Any
const SvtLinguOptions& SvtLinguConfigItem::GetOptions() const
{
- osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
+ osl::MutexGuard aGuard(theSvtLinguConfigItemMutex());
return aOpt;
}
void SvtLinguConfigItem::LoadOptions( const uno::Sequence< OUString > &rProperyNames )
{
- osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
+ osl::MutexGuard aGuard(theSvtLinguConfigItemMutex());
bool bRes = false;
@@ -684,7 +686,7 @@ bool SvtLinguConfigItem::SaveOptions( const uno::Sequence< OUString > &rProperyN
if (!IsModified())
return true;
- osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
+ osl::MutexGuard aGuard(theSvtLinguConfigItemMutex());
bool bRet = false;
@@ -746,7 +748,7 @@ bool SvtLinguConfigItem::SaveOptions( const uno::Sequence< OUString > &rProperyN
bool SvtLinguConfigItem::IsReadOnly( const OUString &rPropertyName ) const
{
- osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
+ osl::MutexGuard aGuard(theSvtLinguConfigItemMutex());
bool bReadOnly = false;
sal_Int32 nHdl;
@@ -757,7 +759,7 @@ bool SvtLinguConfigItem::IsReadOnly( const OUString &rPropertyName ) const
bool SvtLinguConfigItem::IsReadOnly( sal_Int32 nPropertyHandle ) const
{
- osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
+ osl::MutexGuard aGuard(theSvtLinguConfigItemMutex());
bool bReadOnly = false;
@@ -808,13 +810,13 @@ constexpr OUStringLiteral aG_Dictionaries = u"Dictionaries";
SvtLinguConfig::SvtLinguConfig()
{
// Global access, must be guarded (multithreading)
- osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
+ osl::MutexGuard aGuard(theSvtLinguConfigItemMutex());
++nCfgItemRefCount;
}
SvtLinguConfig::~SvtLinguConfig()
{
- osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
+ osl::MutexGuard aGuard(theSvtLinguConfigItemMutex());
if (pCfgItem && pCfgItem->IsModified())
pCfgItem->Commit();
@@ -829,7 +831,7 @@ SvtLinguConfig::~SvtLinguConfig()
SvtLinguConfigItem & SvtLinguConfig::GetConfigItem()
{
// Global access, must be guarded (multithreading)
- osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
+ osl::MutexGuard aGuard(theSvtLinguConfigItemMutex());
if (!pCfgItem)
{
pCfgItem = new SvtLinguConfigItem;
diff --git a/unotools/source/config/moduleoptions.cxx b/unotools/source/config/moduleoptions.cxx
index 0af82141d30a..324736359b6e 100644
--- a/unotools/source/config/moduleoptions.cxx
+++ b/unotools/source/config/moduleoptions.cxx
@@ -28,7 +28,6 @@
#include <comphelper/sequence.hxx>
#include <osl/diagnose.h>
#include <o3tl/enumarray.hxx>
-#include <rtl/instance.hxx>
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/beans/PropertyValue.hpp>
diff --git a/unotools/source/config/pathoptions.cxx b/unotools/source/config/pathoptions.cxx
index 59e8a978d0b1..60335e00dfb9 100644
--- a/unotools/source/config/pathoptions.cxx
+++ b/unotools/source/config/pathoptions.cxx
@@ -37,7 +37,6 @@
#include <com/sun/star/util/PathSubstitution.hpp>
#include <com/sun/star/util/XStringSubstitution.hpp>
#include <com/sun/star/util/theMacroExpander.hpp>
-#include <rtl/instance.hxx>
#include <o3tl/enumarray.hxx>
#include "itemholder1.hxx"
@@ -433,12 +432,19 @@ SvtPathOptions_Impl::SvtPathOptions_Impl()
// class SvtPathOptions --------------------------------------------------
-namespace { struct lclMutex : public rtl::Static< ::osl::Mutex, lclMutex > {}; }
+namespace
+{
+ ::osl::Mutex& lclMutex()
+ {
+ static ::osl::Mutex SINGLETON;
+ return SINGLETON;
+ }
+}
SvtPathOptions::SvtPathOptions()
{
// Global access, must be guarded (multithreading)
- ::osl::MutexGuard aGuard( lclMutex::get() );
+ ::osl::MutexGuard aGuard( lclMutex() );
pImpl = g_pOptions.lock();
if ( !pImpl )
{
@@ -451,7 +457,7 @@ SvtPathOptions::SvtPathOptions()
SvtPathOptions::~SvtPathOptions()
{
// Global access, must be guarded (multithreading)
- ::osl::MutexGuard aGuard( lclMutex::get() );
+ ::osl::MutexGuard aGuard( lclMutex() );
pImpl.reset();
}
diff --git a/unotools/source/config/syslocaleoptions.cxx b/unotools/source/config/syslocaleoptions.cxx
index 7e38237ec3b2..8f08202a7a23 100644
--- a/unotools/source/config/syslocaleoptions.cxx
+++ b/unotools/source/config/syslocaleoptions.cxx
@@ -18,7 +18,6 @@
*/
#include <com/sun/star/uno/Sequence.hxx>
-#include <rtl/instance.hxx>
#include <sal/log.hxx>
#include <i18nlangtag/mslangid.hxx>
#include <i18nlangtag/languagetag.hxx>
@@ -41,8 +40,7 @@ using namespace com::sun::star::lang;
namespace
{
std::weak_ptr<SvtSysLocaleOptions_Impl> g_pSysLocaleOptions;
- struct CurrencyChangeLink
- : public rtl::Static<Link<LinkParamNone*,void>, CurrencyChangeLink> {};
+ Link<LinkParamNone*,void> g_CurrencyChangeLink;
Mutex& GetMutex()
{
@@ -669,15 +667,15 @@ OUString SvtSysLocaleOptions::CreateCurrencyConfigString(
void SvtSysLocaleOptions::SetCurrencyChangeLink( const Link<LinkParamNone*,void>& rLink )
{
MutexGuard aGuard( GetMutex() );
- DBG_ASSERT( !CurrencyChangeLink::get().IsSet(), "SvtSysLocaleOptions::SetCurrencyChangeLink: already set" );
- CurrencyChangeLink::get() = rLink;
+ DBG_ASSERT( !g_CurrencyChangeLink.IsSet(), "SvtSysLocaleOptions::SetCurrencyChangeLink: already set" );
+ g_CurrencyChangeLink = rLink;
}
// static
const Link<LinkParamNone*,void>& SvtSysLocaleOptions::GetCurrencyChangeLink()
{
MutexGuard aGuard( GetMutex() );
- return CurrencyChangeLink::get();
+ return g_CurrencyChangeLink;
}
void SvtSysLocaleOptions::ConfigurationChanged( utl::ConfigurationBroadcaster* p, ConfigurationHints nHint )
diff --git a/unotools/source/i18n/textsearch.cxx b/unotools/source/i18n/textsearch.cxx
index ba75b0b2319b..0ed0539b0e17 100644
--- a/unotools/source/i18n/textsearch.cxx
+++ b/unotools/source/i18n/textsearch.cxx
@@ -32,7 +32,6 @@
#include <unotools/charclass.hxx>
#include <comphelper/processfactory.hxx>
#include <unotools/textsearch.hxx>
-#include <rtl/instance.hxx>
#include <rtl/ustrbuf.hxx>
#include <tools/diagnose_ex.h>
#include <mutex>
diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx
index 22ce434b0e3e..02770fda8744 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -24,7 +24,7 @@
#include <unotools/tempfile.hxx>
#include <rtl/ustring.hxx>
-#include <rtl/instance.hxx>
+#include <osl/mutex.hxx>
#include <osl/detail/file.h>
#include <osl/file.hxx>
#include <tools/time.hxx>