Commit 37d9cd90 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

use thread_local in AccessSpreader

Summary: To get this to link across platforms, requires moving the thread-locals into functions. To avoid curious performance hits, requires removing the field initializers.

Differential Revision: D27699178

fbshipit-source-id: 7617b8e4aedeccae4cd95ffe606d1414dc352705
parent cb45060b
......@@ -275,7 +275,7 @@ struct AccessSpreader : private detail::AccessSpreaderBase {
/// current()).
static size_t cachedCurrent(size_t numStripes) {
return widthAndCpuToStripe[std::min(size_t(kMaxCpus), numStripes)]
[cpuCache.cpu()];
[cpuCache().cpu()];
}
#else
/// Fallback implementation when thread-local storage isn't available.
......@@ -317,12 +317,15 @@ struct AccessSpreader : private detail::AccessSpreaderBase {
private:
static constexpr unsigned kMaxCachedCpuUses = 32;
unsigned cachedCpu_{0};
unsigned cachedCpuUses_{0};
unsigned cachedCpu_;
unsigned cachedCpuUses_;
};
#ifdef FOLLY_CL_USE_FOLLY_TLS
static FOLLY_TLS CpuCache cpuCache;
FOLLY_EXPORT FOLLY_ALWAYS_INLINE static CpuCache& cpuCache() {
static thread_local CpuCache cpuCache;
return cpuCache;
}
#endif
static bool initialized;
......@@ -363,12 +366,6 @@ template <template <typename> class Atom>
typename AccessSpreader<Atom>::CompactStripe
AccessSpreader<Atom>::widthAndCpuToStripe[kMaxCpus + 1][kMaxCpus] = {};
#ifdef FOLLY_CL_USE_FOLLY_TLS
template <template <typename> class Atom>
FOLLY_TLS
typename AccessSpreader<Atom>::CpuCache AccessSpreader<Atom>::cpuCache;
#endif
template <template <typename> class Atom>
bool AccessSpreader<Atom>::initialized = AccessSpreader<Atom>::initialize();
......
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