From: Mark McDuff Date: Thu, 16 Jul 2015 23:27:21 +0000 (-0700) Subject: use thread_local instead of ThreadLocal for some statics in Random X-Git-Tag: deprecate-dynamic-initializer~426 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6caa3d95ee837703f8f094ffbff5592627417711;p=folly.git use thread_local instead of ThreadLocal for some statics in Random Summary: Exit synchronization is the worst! The worst! Reviewed By: @​bmaurer Differential Revision: D2253073 --- 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(); }