Commit 4a150ab2 authored by Dan Melnic's avatar Dan Melnic Committed by Facebook Github Bot

Use FOLLY_CL_USE_FOLLY_TLS for CacheLocality to avoid an iOS build issue

Summary: Use FOLLY_CL_USE_FOLLY_TLS for CacheLocality to avoid an iOS build issue

Reviewed By: mzlee

Differential Revision: D17085507

fbshipit-source-id: acd407c9e0045eb4d8a59348a20874dbe75fd651
parent 54f83501
...@@ -311,7 +311,7 @@ Getcpu::Func Getcpu::resolveVdsoFunc() { ...@@ -311,7 +311,7 @@ Getcpu::Func Getcpu::resolveVdsoFunc() {
#endif #endif
} }
#ifdef FOLLY_TLS #ifdef FOLLY_CL_USE_FOLLY_TLS
/////////////// SequentialThreadId /////////////// SequentialThreadId
template struct SequentialThreadId<std::atomic>; template struct SequentialThreadId<std::atomic>;
#endif #endif
......
...@@ -37,6 +37,12 @@ ...@@ -37,6 +37,12 @@
#include <folly/lang/Exception.h> #include <folly/lang/Exception.h>
#include <folly/system/ThreadId.h> #include <folly/system/ThreadId.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
...@@ -141,7 +147,7 @@ struct Getcpu { ...@@ -141,7 +147,7 @@ struct Getcpu {
static Func resolveVdsoFunc(); static Func resolveVdsoFunc();
}; };
#ifdef FOLLY_TLS #ifdef FOLLY_CL_USE_FOLLY_TLS
template <template <typename> class Atom> template <template <typename> class Atom>
struct SequentialThreadId { struct SequentialThreadId {
/// Returns the thread id assigned to the current thread /// Returns the thread id assigned to the current thread
...@@ -196,7 +202,7 @@ struct FallbackGetcpu { ...@@ -196,7 +202,7 @@ struct FallbackGetcpu {
} }
}; };
#ifdef FOLLY_TLS #ifdef FOLLY_CL_USE_FOLLY_TLS
typedef FallbackGetcpu<SequentialThreadId<std::atomic>> FallbackGetcpuType; typedef FallbackGetcpu<SequentialThreadId<std::atomic>> FallbackGetcpuType;
#else #else
typedef FallbackGetcpu<HashingThreadId> FallbackGetcpuType; typedef FallbackGetcpu<HashingThreadId> FallbackGetcpuType;
...@@ -251,7 +257,7 @@ struct AccessSpreader { ...@@ -251,7 +257,7 @@ struct AccessSpreader {
[cpu % kMaxCpus]; [cpu % kMaxCpus];
} }
#ifdef FOLLY_TLS #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
...@@ -317,7 +323,7 @@ struct AccessSpreader { ...@@ -317,7 +323,7 @@ struct AccessSpreader {
unsigned cachedCpuUses_{0}; unsigned cachedCpuUses_{0};
}; };
#ifdef FOLLY_TLS #ifdef FOLLY_CL_USE_FOLLY_TLS
static FOLLY_TLS CpuCache cpuCache; static FOLLY_TLS CpuCache cpuCache;
#endif #endif
...@@ -385,7 +391,7 @@ template <template <typename> class Atom> ...@@ -385,7 +391,7 @@ template <template <typename> class Atom>
typename AccessSpreader<Atom>::CompactStripe typename AccessSpreader<Atom>::CompactStripe
AccessSpreader<Atom>::widthAndCpuToStripe[kMaxCpus + 1][kMaxCpus] = {}; AccessSpreader<Atom>::widthAndCpuToStripe[kMaxCpus + 1][kMaxCpus] = {};
#ifdef FOLLY_TLS #ifdef FOLLY_CL_USE_FOLLY_TLS
template <template <typename> class Atom> template <template <typename> class Atom>
FOLLY_TLS FOLLY_TLS
typename AccessSpreader<Atom>::CpuCache AccessSpreader<Atom>::cpuCache; typename AccessSpreader<Atom>::CpuCache AccessSpreader<Atom>::cpuCache;
......
...@@ -1042,7 +1042,7 @@ TEST(Getcpu, VdsoGetcpu) { ...@@ -1042,7 +1042,7 @@ TEST(Getcpu, VdsoGetcpu) {
} }
#endif #endif
#ifdef FOLLY_TLS #ifdef FOLLY_CL_USE_FOLLY_TLS
TEST(ThreadId, SimpleTls) { TEST(ThreadId, SimpleTls) {
unsigned cpu = 0; unsigned cpu = 0;
auto rv = folly::FallbackGetcpu<SequentialThreadId<std::atomic>>::getcpu( auto rv = folly::FallbackGetcpu<SequentialThreadId<std::atomic>>::getcpu(
...@@ -1067,7 +1067,7 @@ TEST(ThreadId, SimplePthread) { ...@@ -1067,7 +1067,7 @@ TEST(ThreadId, SimplePthread) {
EXPECT_EQ(cpu, again); EXPECT_EQ(cpu, again);
} }
#ifdef FOLLY_TLS #ifdef FOLLY_CL_USE_FOLLY_TLS
static FOLLY_TLS unsigned testingCpu = 0; static FOLLY_TLS unsigned testingCpu = 0;
static int testingGetcpu(unsigned* cpu, unsigned* node, void* /* unused */) { static int testingGetcpu(unsigned* cpu, unsigned* node, void* /* unused */) {
...@@ -1111,7 +1111,7 @@ TEST(AccessSpreader, ConcurrentAccessCached) { ...@@ -1111,7 +1111,7 @@ TEST(AccessSpreader, ConcurrentAccessCached) {
} }
} }
#ifdef FOLLY_TLS #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> \
......
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