diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-07-22 09:39:49 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-07-25 13:23:52 +0200 |
commit | 4b6390290fcfdea882fde93facef00ac33dd8b88 (patch) | |
tree | be6f2aa06cccb0911b58f9a2efecd77a7998247a /sc/source | |
parent | 4aa2d5ede17ddf7345804deb200983367990a7e2 (diff) |
cid#1557678 Check of thread-shared field evades lock acquisition
and
cid#1556287 Check of thread-shared field evades lock acquisition
(1) std::mutex can be initialised at load time, since it is a
single-word object, i.e. no need to use a static function local.
(2) std::mutex is really fast, so no need to use tricky double-checked
locking
Change-Id: Ieb2239908204baaaccfe9d1e0e2c8ed369d108fb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170833
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc/source')
-rw-r--r-- | sc/source/core/tool/compiler.cxx | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index 28aa2c73a9c5..f8bdb096f54d 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -187,8 +187,11 @@ void ScCompiler::fillFromAddInCollectionEnglishName( const NonConstOpCodeMapPtr& } } +static std::mutex gCharClassMutex; + void ScCompiler::DeInit() { + std::scoped_lock aGuard(gCharClassMutex); if (pCharClassEnglish) { delete pCharClassEnglish; @@ -224,38 +227,26 @@ bool ScCompiler::IsEnglishSymbol( const OUString& rName ) return !aIntName.isEmpty(); // no valid function name } -static std::mutex& getCharClassMutex() -{ - static std::mutex aMutex; - return aMutex; -} - const CharClass* ScCompiler::GetCharClassEnglish() { + std::scoped_lock aGuard(gCharClassMutex); if (!pCharClassEnglish) { - std::scoped_lock aGuard(getCharClassMutex()); - if (!pCharClassEnglish) - { - pCharClassEnglish = new CharClass( ::comphelper::getProcessComponentContext(), - LanguageTag( LANGUAGE_ENGLISH_US)); - } + pCharClassEnglish = new CharClass( ::comphelper::getProcessComponentContext(), + LanguageTag( LANGUAGE_ENGLISH_US)); } return pCharClassEnglish; } const CharClass* ScCompiler::GetCharClassLocalized() { + // Switching UI language requires restart; if not, we would have to + // keep track of that. + std::scoped_lock aGuard(gCharClassMutex); if (!pCharClassLocalized) { - // Switching UI language requires restart; if not, we would have to - // keep track of that. - std::scoped_lock aGuard(getCharClassMutex()); - if (!pCharClassLocalized) - { - pCharClassLocalized = new CharClass( ::comphelper::getProcessComponentContext(), - Application::GetSettings().GetUILanguageTag()); - } + pCharClassLocalized = new CharClass( ::comphelper::getProcessComponentContext(), + Application::GetSettings().GetUILanguageTag()); } return pCharClassLocalized; } |