sc/source/core/tool/compiler.cxx | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-)
New commits: commit 4b6390290fcfdea882fde93facef00ac33dd8b88 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Mon Jul 22 09:39:49 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Jul 25 13:23:52 2024 +0200 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.gran...@collabora.co.uk> 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; }