Use std::mutex instead of FastOS_Mutex.
#include <vespa/fastlib/text/unicodeutil.h>
#include <vespa/fastlib/text/normwordfolder.h>
-#include <vespa/fastos/mutex.h>
+#include <mutex>
#include <cstring>
bool Fast_NormalizeWordFolder::_isInitialized = false;
-FastOS_Mutex _initMutex;
+std::mutex _initMutex;
bool Fast_NormalizeWordFolder::_doAccentRemoval = false;
bool Fast_NormalizeWordFolder::_doSmallToNormalKana = false;
bool Fast_NormalizeWordFolder::_doKatakanaToHiragana = false;
@@ -28,7 +28,8 @@ void
Fast_NormalizeWordFolder::Setup(uint32_t flags)
{
// Only allow setting these when not initialized or initializing...
- _initMutex.Lock();
+ {
+ std::unique_lock<std::mutex> initGuard(_initMutex);
_doAccentRemoval = (DO_ACCENT_REMOVAL & flags) != 0;
// _doSmallToNormalKana = (DO_SMALL_TO_NORMAL_KANA & flags) != 0;
// _doKatakanaToHiragana = (DO_KATAKANA_TO_HIRAGANA & flags) != 0;
@@ -38,7 +39,7 @@ Fast_NormalizeWordFolder::Setup(uint32_t flags)
_doLigatureSubstitution = (DO_LIGATURE_SUBSTITUTION & flags) != 0;
_doMulticharExpansion = (DO_MULTICHAR_EXPANSION & flags) != 0;
_isInitialized = false;
- _initMutex.Unlock();
+ }
Initialize();
}
@@ -47,7 +48,7 @@ Fast_NormalizeWordFolder::Initialize()
{
unsigned int i;
if (!_isInitialized) {
- _initMutex.Lock();
+ std::unique_lock<std::mutex> initGuard(_initMutex);
if (!_isInitialized) {
for (i = 0; i < 128; i++)
@@ -707,7 +708,6 @@ Fast_NormalizeWordFolder::Initialize()
//
_isInitialized = true;
}
- _initMutex.Unlock();
}
}
