Commit 92d8ef30 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

prefer thread_local over FOLLY_TLS in F14

Reviewed By: Orvid

Differential Revision: D27582035

fbshipit-source-id: 0f0c35adca1c44dcd0ef88f2443f769d7991e6aa
parent f68ed33b
......@@ -36,30 +36,29 @@ EmptyTagVectorType kEmptyTagVector = {};
//// Debug and ASAN stuff
#if defined(FOLLY_TLS) && (!defined(NDEBUG) || FOLLY_LIBRARY_SANITIZE_ADDRESS)
#define FOLLY_F14_DETAIL_TLS_SIZE_T thread_local std::size_t
#else
#define FOLLY_F14_DETAIL_TLS_SIZE_T std::atomic<std::size_t>
#endif
bool tlsPendingSafeInserts(std::ptrdiff_t delta) {
static FOLLY_F14_DETAIL_TLS_SIZE_T value{0};
static std::atomic<size_t> value_non_tl{0};
static thread_local std::atomic<size_t> value_tl{0};
auto& value = kIsDebug || kIsLibrarySanitizeAddress ? value_tl : value_non_tl;
FOLLY_SAFE_DCHECK(delta >= -1, "");
std::size_t v = value;
std::size_t v = value.load(std::memory_order_relaxed);
if (delta > 0 || (delta == -1 && v > 0)) {
v += delta;
v = std::min(std::numeric_limits<std::size_t>::max() / 2, v);
value = v;
value.store(v, std::memory_order_relaxed);
}
return v != 0;
}
std::size_t tlsMinstdRand(std::size_t n) {
static std::atomic<uint32_t> state_non_tl{0};
static thread_local std::atomic<uint32_t> state_tl{0};
auto& state = kIsDebug || kIsLibrarySanitizeAddress ? state_tl : state_non_tl;
FOLLY_SAFE_DCHECK(n > 0, "");
static FOLLY_F14_DETAIL_TLS_SIZE_T state{0};
auto s = static_cast<uint32_t>(state);
auto s = state.load(std::memory_order_relaxed);
if (s == 0) {
uint64_t seed = static_cast<uint64_t>(
std::chrono::steady_clock::now().time_since_epoch().count());
......@@ -67,7 +66,7 @@ std::size_t tlsMinstdRand(std::size_t n) {
}
s = static_cast<uint32_t>((s * uint64_t{48271}) % uint64_t{2147483647});
state = s;
state.store(s, std::memory_order_relaxed);
return std::size_t{s} % n;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment