diff options
-rw-r--r-- | include/unotools/useroptions.hxx | 2 | ||||
-rw-r--r-- | unotools/source/config/useroptions.cxx | 34 |
2 files changed, 18 insertions, 18 deletions
diff --git a/include/unotools/useroptions.hxx b/include/unotools/useroptions.hxx index adc5f5055d5b..d21482dcca2d 100644 --- a/include/unotools/useroptions.hxx +++ b/include/unotools/useroptions.hxx @@ -60,8 +60,6 @@ public: SvtUserOptions (); virtual ~SvtUserOptions () override; - static osl::Mutex& GetInitMutex (); - // get the address token OUString GetCompany () const; OUString GetFirstName () const; diff --git a/unotools/source/config/useroptions.cxx b/unotools/source/config/useroptions.cxx index ffe01cca497c..448850fb84fc 100644 --- a/unotools/source/config/useroptions.cxx +++ b/unotools/source/config/useroptions.cxx @@ -259,34 +259,36 @@ bool SvtUserOptions::Impl::IsTokenReadonly (UserOptToken nToken) const beans::PropertyAttribute::READONLY); } +static std::mutex& GetInitMutex() +{ + static std::mutex gMutex; + return gMutex; +} + + SvtUserOptions::SvtUserOptions () { // Global access, must be guarded (multithreading) - osl::MutexGuard aGuard(GetInitMutex()); + std::unique_lock aGuard(GetInitMutex()); - if (xSharedImpl.expired()) + xImpl = xSharedImpl.lock(); + if (!xImpl) { xImpl = std::make_shared<Impl>(); xSharedImpl = xImpl; + aGuard.unlock(); // because holdConfigItem will call this constructor ItemHolder1::holdConfigItem(EItem::UserOptions); } - xImpl = xSharedImpl.lock(); xImpl->AddListener(this); } SvtUserOptions::~SvtUserOptions() { // Global access, must be guarded (multithreading) - osl::MutexGuard aGuard( GetInitMutex() ); + std::unique_lock aGuard( GetInitMutex() ); xImpl->RemoveListener(this); } -osl::Mutex& SvtUserOptions::GetInitMutex() -{ - static osl::Mutex gMutex; - return gMutex; -} - OUString SvtUserOptions::GetCompany () const { return GetToken(UserOptToken::Company); } OUString SvtUserOptions::GetFirstName () const { return GetToken(UserOptToken::FirstName); } OUString SvtUserOptions::GetLastName () const { return GetToken(UserOptToken::LastName); } @@ -307,37 +309,37 @@ OUString SvtUserOptions::GetEncryptionKey () const { return GetToken(UserOptTok bool SvtUserOptions::IsTokenReadonly (UserOptToken nToken) const { - osl::MutexGuard aGuard(GetInitMutex()); + std::unique_lock aGuard(GetInitMutex()); return xImpl->IsTokenReadonly(nToken); } OUString SvtUserOptions::GetToken (UserOptToken nToken) const { - osl::MutexGuard aGuard(GetInitMutex()); + std::unique_lock aGuard(GetInitMutex()); return xImpl->GetToken(nToken); } void SvtUserOptions::SetToken (UserOptToken nToken, OUString const& rNewToken) { - osl::MutexGuard aGuard(GetInitMutex()); + std::unique_lock aGuard(GetInitMutex()); xImpl->SetToken(nToken, rNewToken); } void SvtUserOptions::SetBoolValue (UserOptToken nToken, bool bNewValue) { - osl::MutexGuard aGuard(GetInitMutex()); + std::unique_lock aGuard(GetInitMutex()); xImpl->SetBoolValue(nToken, bNewValue); } bool SvtUserOptions::GetEncryptToSelf() const { - osl::MutexGuard aGuard(GetInitMutex()); + std::unique_lock aGuard(GetInitMutex()); return xImpl->GetBoolValue(UserOptToken::EncryptToSelf); } OUString SvtUserOptions::GetFullName () const { - osl::MutexGuard aGuard(GetInitMutex()); + std::unique_lock aGuard(GetInitMutex()); return xImpl->GetFullName(); } |