Commit 2b9c0388 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

make SequentialThreadId not a template

Summary:
`SequentialThreadId` is only ever instantiated with `std::atomic` so just make it no longer a template.

This permits moving the implementation into the source file.

Reviewed By: Mizuchi

Differential Revision: D27669406

fbshipit-source-id: ec2cddbff433df31434548b61111a34ca2da5cef
parent 266ca3b2
......@@ -320,7 +320,11 @@ Getcpu::Func Getcpu::resolveVdsoFunc() {
#ifdef FOLLY_CL_USE_FOLLY_TLS
/////////////// SequentialThreadId
template struct SequentialThreadId<std::atomic>;
unsigned SequentialThreadId::get() {
static std::atomic<unsigned> global{0};
static FOLLY_TLS unsigned local{0};
return FOLLY_LIKELY(local) ? local : (local = ++global);
}
#endif
namespace detail {
......
......@@ -148,32 +148,9 @@ struct Getcpu {
};
#ifdef FOLLY_CL_USE_FOLLY_TLS
template <template <typename> class Atom>
struct SequentialThreadId {
/// Returns the thread id assigned to the current thread
static unsigned get() {
auto rv = currentId;
if (UNLIKELY(rv == 0)) {
rv = currentId = ++prevId;
}
return rv;
}
private:
static Atom<unsigned> prevId;
static FOLLY_TLS unsigned currentId;
static unsigned get();
};
template <template <typename> class Atom>
Atom<unsigned> SequentialThreadId<Atom>::prevId(0);
template <template <typename> class Atom>
FOLLY_TLS unsigned SequentialThreadId<Atom>::currentId(0);
// Suppress this instantiation in other translation units. It is
// instantiated in CacheLocality.cpp
extern template struct SequentialThreadId<std::atomic>;
#endif
struct HashingThreadId {
......@@ -201,7 +178,7 @@ struct FallbackGetcpu {
};
#ifdef FOLLY_CL_USE_FOLLY_TLS
typedef FallbackGetcpu<SequentialThreadId<std::atomic>> FallbackGetcpuType;
typedef FallbackGetcpu<SequentialThreadId> FallbackGetcpuType;
#else
typedef FallbackGetcpu<HashingThreadId> FallbackGetcpuType;
#endif
......
......@@ -47,7 +47,7 @@ using namespace folly;
DECLARE_SPREADER_TAG(
ThreadLocalTag,
CacheLocality::system<>(),
folly::FallbackGetcpu<SequentialThreadId<std::atomic>>::getcpu)
folly::FallbackGetcpu<SequentialThreadId>::getcpu)
DECLARE_SPREADER_TAG(
PthreadSelfTag,
CacheLocality::system<>(),
......
......@@ -1044,13 +1044,12 @@ TEST(Getcpu, VdsoGetcpu) {
#ifdef FOLLY_CL_USE_FOLLY_TLS
TEST(ThreadId, SimpleTls) {
unsigned cpu = 0;
auto rv = folly::FallbackGetcpu<SequentialThreadId<std::atomic>>::getcpu(
&cpu, nullptr, nullptr);
auto rv =
folly::FallbackGetcpu<SequentialThreadId>::getcpu(&cpu, nullptr, nullptr);
EXPECT_EQ(rv, 0);
EXPECT_TRUE(cpu > 0);
unsigned again;
folly::FallbackGetcpu<SequentialThreadId<std::atomic>>::getcpu(
&again, nullptr, nullptr);
folly::FallbackGetcpu<SequentialThreadId>::getcpu(&again, nullptr, nullptr);
EXPECT_EQ(cpu, again);
}
#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