summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2021-12-23 19:42:19 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-12-24 19:10:25 +0100
commitac511d90cdf9d28eb8809c30be9fa08b42ea0bd3 (patch)
tree2478a0bef5b9c92648f8087a3e5d3918c7fc8619 /unotools
parent4621e719c283cb24ec6b884b55a6719a321336f3 (diff)
osl::Mutex->std::mutex in SvtUserOptions
Change-Id: Ib16cc05a8d9c3e7ef828223e8b1067eeb7faf809 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127399 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'unotools')
-rw-r--r--unotools/source/config/useroptions.cxx34
1 files changed, 18 insertions, 16 deletions
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();
}