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>
This commit is contained in:
Noel Grandin 2021-11-18 20:24:57 +02:00 committed by Noel Grandin
parent 4d3e4c1cf3
commit f7a8c3cc4d
10 changed files with 47 additions and 65 deletions

View file

@ -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

View file

@ -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: */

View file

@ -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 >

View file

@ -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;
}
/*

View file

@ -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;

View file

@ -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>

View file

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

View file

@ -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 )

View file

@ -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>

View file

@ -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>