typedef uint32_t uint32;
typedef uint64_t uint64;
-static constexpr uint8 kuint8max = ((uint8)0xFF);
-static constexpr uint16 kuint16max = ((uint16)0xFFFF);
-static constexpr uint32 kuint32max = ((uint32)0xFFFFFFFF);
-static constexpr uint64 kuint64max = ((uint64)(0xFFFFFFFFFFFFFFFF));
-static constexpr int8 kint8min = ((int8)~0x7F);
-static constexpr int8 kint8max = ((int8)0x7F);
-static constexpr int16 kint16min = ((int16)~0x7FFF);
-static constexpr int16 kint16max = ((int16)0x7FFF);
-static constexpr int32 kint32min = ((int32)~0x7FFFFFFF);
-static constexpr int32 kint32max = ((int32)0x7FFFFFFF);
-static constexpr int64 kint64min = ((int64)(~0x7FFFFFFFFFFFFFFF));
-static constexpr int64 kint64max = ((int64)(0x7FFFFFFFFFFFFFFF));
-
static constexpr uint32 kUnicodeError = 0xFFFD;
#if defined(OS_WIN) && defined(UNICODE) && defined(_UNICODE)
#include "util.h"
+#include <atomic>
#include <iostream>
namespace sentencepiece {
namespace {
constexpr unsigned int kDefaultSeed = static_cast<unsigned int>(-1);
-static unsigned int g_seed = kDefaultSeed;
-static int g_minloglevel = 0;
+static std::atomic<unsigned int> g_seed = kDefaultSeed;
+static std::atomic<int> g_minloglevel = 0;
} // namespace
void SetRandomGeneratorSeed(unsigned int seed) {
- if (seed != kDefaultSeed) g_seed = seed;
+ if (seed != kDefaultSeed) g_seed.store(seed);
}
uint32 GetRandomGeneratorSeed() {
- return g_seed == kDefaultSeed ? std::random_device{}() : g_seed;
+ return g_seed == kDefaultSeed ? std::random_device{}() : g_seed.load();
}
namespace logging {
-int GetMinLogLevel() { return g_minloglevel; }
-void SetMinLogLevel(int v) { g_minloglevel = v; }
+int GetMinLogLevel() { return g_minloglevel.load(); }
+void SetMinLogLevel(int v) { g_minloglevel.store(v); }
} // namespace logging
namespace string_util {