From 6caa3d95ee837703f8f094ffbff5592627417711 Mon Sep 17 00:00:00 2001 From: Mark McDuff Date: Thu, 16 Jul 2015 16:27:21 -0700 Subject: [PATCH] use thread_local instead of ThreadLocal for some statics in Random MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Summary: Exit synchronization is the worst! The worst! Reviewed By: @​bmaurer Differential Revision: D2253073 --- folly/Random.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/folly/Random.cpp b/folly/Random.cpp index 62eb8f9f..9b960de0 100644 --- a/folly/Random.cpp +++ b/folly/Random.cpp @@ -108,18 +108,13 @@ void BufferedRandomDevice::getSlow(unsigned char* data, size_t size) { ptr_ += size; } - } // namespace void Random::secureRandom(void* data, size_t size) { - static ThreadLocal bufferedRandomDevice; - bufferedRandomDevice->get(data, size); + static thread_local BufferedRandomDevice bufferedRandomDevice; + bufferedRandomDevice.get(data, size); } -ThreadLocalPRNG::ThreadLocalPRNG() { - static folly::ThreadLocal localInstance; - local_ = localInstance.get(); -} class ThreadLocalPRNG::LocalInstancePRNG { public: @@ -128,6 +123,11 @@ class ThreadLocalPRNG::LocalInstancePRNG { Random::DefaultGenerator rng; }; +ThreadLocalPRNG::ThreadLocalPRNG() { + static thread_local ThreadLocalPRNG::LocalInstancePRNG localInstance; + local_ = &localInstance; +} + uint32_t ThreadLocalPRNG::getImpl(LocalInstancePRNG* local) { return local->rng(); } -- 2.34.1