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:
@@ -31,8 +31,6 @@ class LocaleDataWrapper;
|
|||||||
class SvtSysLocale_Impl;
|
class SvtSysLocale_Impl;
|
||||||
class SvtSysLocaleOptions;
|
class SvtSysLocaleOptions;
|
||||||
|
|
||||||
namespace osl { class Mutex; }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
SvtSysLocale provides a refcounted single instance of an application wide
|
SvtSysLocale provides a refcounted single instance of an application wide
|
||||||
LocaleDataWrapper and <type>CharClass</type> which always
|
LocaleDataWrapper and <type>CharClass</type> which always
|
||||||
@@ -48,8 +46,6 @@ class UNOTOOLS_DLLPUBLIC SvtSysLocale
|
|||||||
|
|
||||||
std::shared_ptr<SvtSysLocale_Impl> pImpl;
|
std::shared_ptr<SvtSysLocale_Impl> pImpl;
|
||||||
|
|
||||||
UNOTOOLS_DLLPRIVATE static ::osl::Mutex& GetMutex();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SvtSysLocale();
|
SvtSysLocale();
|
||||||
~SvtSysLocale();
|
~SvtSysLocale();
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
#include <osl/nlsupport.h>
|
#include <osl/nlsupport.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <mutex>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -41,6 +42,18 @@ namespace {
|
|||||||
|
|
||||||
std::weak_ptr<SvtSysLocale_Impl> g_pSysLocale;
|
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
|
class SvtSysLocale_Impl : public utl::ConfigurationListener
|
||||||
@@ -88,7 +101,7 @@ void SvtSysLocale_Impl::ConfigurationChanged( utl::ConfigurationBroadcaster*, Co
|
|||||||
!(nHint & ConfigurationHints::DatePatterns) )
|
!(nHint & ConfigurationHints::DatePatterns) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MutexGuard aGuard( SvtSysLocale::GetMutex() );
|
std::unique_lock aGuard( GetMutex() );
|
||||||
|
|
||||||
const LanguageTag& rLanguageTag = aSysLocaleOptions.GetRealLanguageTag();
|
const LanguageTag& rLanguageTag = aSysLocaleOptions.GetRealLanguageTag();
|
||||||
if ( nHint & ConfigurationHints::Locale )
|
if ( nHint & ConfigurationHints::Locale )
|
||||||
@@ -115,7 +128,7 @@ std::vector<OUString> SvtSysLocale_Impl::getDateAcceptancePatternsConfig() const
|
|||||||
|
|
||||||
SvtSysLocale::SvtSysLocale()
|
SvtSysLocale::SvtSysLocale()
|
||||||
{
|
{
|
||||||
MutexGuard aGuard( GetMutex() );
|
std::unique_lock aGuard( GetMutex() );
|
||||||
pImpl = g_pSysLocale.lock();
|
pImpl = g_pSysLocale.lock();
|
||||||
if ( !pImpl )
|
if ( !pImpl )
|
||||||
{
|
{
|
||||||
@@ -126,21 +139,10 @@ SvtSysLocale::SvtSysLocale()
|
|||||||
|
|
||||||
SvtSysLocale::~SvtSysLocale()
|
SvtSysLocale::~SvtSysLocale()
|
||||||
{
|
{
|
||||||
MutexGuard aGuard( GetMutex() );
|
std::unique_lock aGuard( GetMutex() );
|
||||||
pImpl.reset();
|
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
|
const LocaleDataWrapper& SvtSysLocale::GetLocaleData() const
|
||||||
{
|
{
|
||||||
return *(pImpl->pLocaleData);
|
return *(pImpl->pLocaleData);
|
||||||
|
Reference in New Issue
Block a user