diff options
author | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-07-17 13:15:51 +0100 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-07-18 11:52:22 +0200 |
commit | 3dcc288468eb2a71ba1381412dd7e25b9fb329d9 (patch) | |
tree | caa4b60aee95997980a45f4723e8a2c9cdd99ca6 /sdext/source/minimizer | |
parent | ec96dfdf2cf478c3f38873e1c4f01564ebb19b71 (diff) |
cid#1555824 Check of thread-shared field evades lock acquisition
Change-Id: Ic0e8e87138ca86a1618e110516f3d8cef481dec7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170626
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'sdext/source/minimizer')
-rw-r--r-- | sdext/source/minimizer/pppoptimizertoken.cxx | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/sdext/source/minimizer/pppoptimizertoken.cxx b/sdext/source/minimizer/pppoptimizertoken.cxx index 472992551b81..73d1280c3a29 100644 --- a/sdext/source/minimizer/pppoptimizertoken.cxx +++ b/sdext/source/minimizer/pppoptimizertoken.cxx @@ -23,15 +23,8 @@ #include <sal/macros.h> #include <unordered_map> #include <memory> -#include <mutex> typedef std::unordered_map< const char*, PPPOptimizerTokenEnum, rtl::CStringHash, rtl::CStringEqual> TypeNameHashMap; -static TypeNameHashMap* pHashMap = nullptr; -static std::mutex& getHashMapMutex() -{ - static std::mutex s_aHashMapProtection; - return s_aHashMapProtection; -} namespace { @@ -110,21 +103,19 @@ const TokenTable pTokenTableArray[] = { "NotFound", TK_NotFound } }; +static TypeNameHashMap* createHashMap() +{ + TypeNameHashMap* pH = new TypeNameHashMap; + const TokenTable* pPtr = pTokenTableArray; + const TokenTable* pEnd = pPtr + SAL_N_ELEMENTS( pTokenTableArray ); + for ( ; pPtr < pEnd; pPtr++ ) + (*pH)[ pPtr->pS ] = pPtr->pE; + return pH; +} + PPPOptimizerTokenEnum TKGet( std::u16string_view rToken ) { - if ( !pHashMap ) - { // init hash map - std::scoped_lock aGuard( getHashMapMutex() ); - if ( !pHashMap ) - { - TypeNameHashMap* pH = new TypeNameHashMap; - const TokenTable* pPtr = pTokenTableArray; - const TokenTable* pEnd = pPtr + SAL_N_ELEMENTS( pTokenTableArray ); - for ( ; pPtr < pEnd; pPtr++ ) - (*pH)[ pPtr->pS ] = pPtr->pE; - pHashMap = pH; - } - } + static TypeNameHashMap* pHashMap = createHashMap(); PPPOptimizerTokenEnum eRetValue = TK_NotFound; size_t i, nLen = rToken.size(); std::unique_ptr<char[]> pBuf(new char[ nLen + 1 ]); |