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