diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-07-22 09:39:49 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2024-07-26 13:04:32 +0200 |
commit | 92eea298224897c47dab903b607b7ae53196f7ee (patch) | |
tree | c4c9e66e1b854fd31225f2fa7f4c8242809fc134 /sc | |
parent | a38e6e65057f0380f07dae724be3b8b33ca3afee (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>
(cherry picked from commit 4b6390290fcfdea882fde93facef00ac33dd8b88)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170957
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'sc')
-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 d26f07f5c664..a4bba4f2e08d 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; } |