#include <random>
#include <array>
-#include <glog/logging.h>
#include <folly/CallOnce.h>
#include <folly/File.h>
#include <folly/FileUtil.h>
+#include <folly/SingletonThreadLocal.h>
#include <folly/ThreadLocal.h>
#include <folly/portability/SysTime.h>
#include <folly/portability/Unistd.h>
+#include <glog/logging.h>
#ifdef _MSC_VER
# include <wincrypt.h>
ptr_ += size;
}
+struct RandomTag {};
-} // namespace
+} // namespace
void Random::secureRandom(void* data, size_t size) {
- static ThreadLocal<BufferedRandomDevice> bufferedRandomDevice;
- bufferedRandomDevice->get(data, size);
+ static SingletonThreadLocal<BufferedRandomDevice, RandomTag>
+ bufferedRandomDevice;
+ bufferedRandomDevice.get().get(data, size);
}
class ThreadLocalPRNG::LocalInstancePRNG {
public:
- LocalInstancePRNG() : rng(Random::create()) { }
+ LocalInstancePRNG() : rng(Random::create()) {}
Random::DefaultGenerator rng;
};
ThreadLocalPRNG::ThreadLocalPRNG() {
- static folly::ThreadLocal<ThreadLocalPRNG::LocalInstancePRNG> localInstance;
- local_ = localInstance.get();
+ static SingletonThreadLocal<ThreadLocalPRNG::LocalInstancePRNG, RandomTag>
+ localInstancePRNG;
+ local_ = &localInstancePRNG.get();
}
uint32_t ThreadLocalPRNG::getImpl(LocalInstancePRNG* local) {
return local->rng();
}
-
}