Commit 0297c176 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

cut macro FOLLY_CL_USE_FOLLY_TLS

Summary: Replace the uses of `FOLLY_CL_USE_FOLLY_TLS` in some cases with C++ checks on `kIsMobile`.

Differential Revision: D27669672

fbshipit-source-id: 79a29896653f2fa62b10b488220d8cf83cba3d00
parent 483df6d0
......@@ -329,14 +329,12 @@ Getcpu::Func Getcpu::resolveVdsoFunc() {
#endif
}
#ifdef FOLLY_CL_USE_FOLLY_TLS
/////////////// SequentialThreadId
unsigned SequentialThreadId::get() {
static std::atomic<unsigned> global{0};
static FOLLY_TLS unsigned local{0};
static thread_local unsigned local{0};
return FOLLY_LIKELY(local) ? local : (local = ++global);
}
#endif
/////////////// HashingThreadId
unsigned HashingThreadId::get() {
......
......@@ -35,12 +35,6 @@
#include <folly/lang/Align.h>
#include <folly/lang/Exception.h>
#if !FOLLY_MOBILE && defined(FOLLY_TLS)
#define FOLLY_CL_USE_FOLLY_TLS 1
#else
#undef FOLLY_CL_USE_FOLLY_TLS
#endif
namespace folly {
// This file contains several classes that might be useful if you are
......@@ -145,11 +139,9 @@ struct Getcpu {
static Func resolveVdsoFunc();
};
#ifdef FOLLY_CL_USE_FOLLY_TLS
struct SequentialThreadId {
static unsigned get();
};
#endif
struct HashingThreadId {
static unsigned get();
......@@ -175,11 +167,8 @@ struct FallbackGetcpu {
}
};
#ifdef FOLLY_CL_USE_FOLLY_TLS
typedef FallbackGetcpu<SequentialThreadId> FallbackGetcpuType;
#else
typedef FallbackGetcpu<HashingThreadId> FallbackGetcpuType;
#endif
using FallbackGetcpuType = FallbackGetcpu<
conditional_t<kIsMobile, HashingThreadId, SequentialThreadId>>;
namespace detail {
......@@ -291,7 +280,6 @@ struct AccessSpreader : private detail::AccessSpreaderBase {
std::memory_order_relaxed);
}
#ifdef FOLLY_CL_USE_FOLLY_TLS
/// Returns the stripe associated with the current CPU. The returned
/// value will be < numStripes.
/// This function caches the current cpu in a thread-local variable for a
......@@ -300,16 +288,12 @@ struct AccessSpreader : private detail::AccessSpreaderBase {
/// current()).
static size_t cachedCurrent(
size_t numStripes, const GlobalState& s = state()) {
if (kIsMobile) {
return current(numStripes);
}
return s.table[std::min(size_t(kMaxCpus), numStripes)][cpuCache().cpu(s)]
.load(std::memory_order_relaxed);
}
#else
/// Fallback implementation when thread-local storage isn't available.
static size_t cachedCurrent(
size_t numStripes, const GlobalState& s = state()) {
return current(numStripes, s);
}
#endif
/// Returns the maximum stripe value that can be returned under any
/// dynamic configuration, based on the current compile-time platform
......@@ -336,12 +320,10 @@ struct AccessSpreader : private detail::AccessSpreaderBase {
unsigned cachedCpuUses_;
};
#ifdef FOLLY_CL_USE_FOLLY_TLS
FOLLY_EXPORT FOLLY_ALWAYS_INLINE static CpuCache& cpuCache() {
static thread_local CpuCache cpuCache;
return cpuCache;
}
#endif
/// Returns the best getcpu implementation for Atom
static Getcpu::Func pickGetcpuFunc() {
......
......@@ -1041,7 +1041,6 @@ TEST(Getcpu, VdsoGetcpu) {
}
#endif
#ifdef FOLLY_CL_USE_FOLLY_TLS
TEST(ThreadId, SimpleTls) {
unsigned cpu = 0;
auto rv =
......@@ -1052,7 +1051,6 @@ TEST(ThreadId, SimpleTls) {
folly::FallbackGetcpu<SequentialThreadId>::getcpu(&again, nullptr, nullptr);
EXPECT_EQ(cpu, again);
}
#endif
TEST(ThreadId, SimplePthread) {
unsigned cpu = 0;
......@@ -1065,7 +1063,6 @@ TEST(ThreadId, SimplePthread) {
EXPECT_EQ(cpu, again);
}
#ifdef FOLLY_CL_USE_FOLLY_TLS
static thread_local unsigned testingCpu = 0;
static int testingGetcpu(unsigned* cpu, unsigned* node, void* /* unused */) {
......@@ -1077,7 +1074,6 @@ static int testingGetcpu(unsigned* cpu, unsigned* node, void* /* unused */) {
}
return 0;
}
#endif
TEST(AccessSpreader, Simple) {
for (size_t s = 1; s < 200; ++s) {
......@@ -1109,7 +1105,6 @@ TEST(AccessSpreader, ConcurrentAccessCached) {
}
}
#ifdef FOLLY_CL_USE_FOLLY_TLS
#define DECLARE_SPREADER_TAG(tag, locality, func) \
namespace { \
template <typename dummy> \
......@@ -1174,5 +1169,3 @@ TEST(CoreRawAllocator, Basic) {
}
mems.clear();
}
#endif
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