osl::Mutex->std::mutex in SvtSysLocale

Change-Id: I722c4ca5d1bb6c0de6b1eff7478de03a23e9d89b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134199
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2022-05-11 13:04:14 +02:00
parent bed301f42f
commit c8e144638c
2 changed files with 16 additions and 18 deletions

View File

@ -31,8 +31,6 @@ class LocaleDataWrapper;
class SvtSysLocale_Impl;
class SvtSysLocaleOptions;
namespace osl { class Mutex; }
/**
SvtSysLocale provides a refcounted single instance of an application wide
LocaleDataWrapper and <type>CharClass</type> which always
@ -48,8 +46,6 @@ class UNOTOOLS_DLLPUBLIC SvtSysLocale
std::shared_ptr<SvtSysLocale_Impl> pImpl;
UNOTOOLS_DLLPRIVATE static ::osl::Mutex& GetMutex();
public:
SvtSysLocale();
~SvtSysLocale();

View File

@ -31,6 +31,7 @@
#include <osl/nlsupport.h>
#include <memory>
#include <mutex>
#include <optional>
#include <vector>
@ -41,6 +42,18 @@ namespace {
std::weak_ptr<SvtSysLocale_Impl> g_pSysLocale;
// static
std::mutex& GetMutex()
{
// #i77768# Due to a static reference in the toolkit lib
// we need a mutex that lives longer than the svl library.
// Otherwise the dtor would use a destructed mutex!!
static std::mutex* persistentMutex(new std::mutex);
return *persistentMutex;
}
}
class SvtSysLocale_Impl : public utl::ConfigurationListener
@ -88,7 +101,7 @@ void SvtSysLocale_Impl::ConfigurationChanged( utl::ConfigurationBroadcaster*, Co
!(nHint & ConfigurationHints::DatePatterns) )
return;
MutexGuard aGuard( SvtSysLocale::GetMutex() );
std::unique_lock aGuard( GetMutex() );
const LanguageTag& rLanguageTag = aSysLocaleOptions.GetRealLanguageTag();
if ( nHint & ConfigurationHints::Locale )
@ -115,7 +128,7 @@ std::vector<OUString> SvtSysLocale_Impl::getDateAcceptancePatternsConfig() const
SvtSysLocale::SvtSysLocale()
{
MutexGuard aGuard( GetMutex() );
std::unique_lock aGuard( GetMutex() );
pImpl = g_pSysLocale.lock();
if ( !pImpl )
{
@ -126,21 +139,10 @@ SvtSysLocale::SvtSysLocale()
SvtSysLocale::~SvtSysLocale()
{
MutexGuard aGuard( GetMutex() );
std::unique_lock aGuard( GetMutex() );
pImpl.reset();
}
// static
Mutex& SvtSysLocale::GetMutex()
{
// #i77768# Due to a static reference in the toolkit lib
// we need a mutex that lives longer than the svl library.
// Otherwise the dtor would use a destructed mutex!!
static Mutex* persistentMutex(new Mutex);
return *persistentMutex;
}
const LocaleDataWrapper& SvtSysLocale::GetLocaleData() const
{
return *(pImpl->pLocaleData);