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

prefer thread_local over FOLLY_TLS in most cases

Reviewed By: Mizuchi

Differential Revision: D27559375

fbshipit-source-id: aad3cc1a5bef017a52d2530068ca18be2eb50cd1
parent eb3f0d20
......@@ -37,7 +37,7 @@
#include <folly/lang/Exception.h>
#include <folly/system/ThreadId.h>
#if !FOLLY_MOBILE && defined(FOLLY_TLS)
#if !FOLLY_MOBILE
#define FOLLY_CL_USE_FOLLY_TLS 1
#else
#undef FOLLY_CL_USE_FOLLY_TLS
......@@ -162,14 +162,14 @@ struct SequentialThreadId {
private:
static Atom<unsigned> prevId;
static FOLLY_TLS unsigned currentId;
static thread_local unsigned currentId;
};
template <template <typename> class Atom>
Atom<unsigned> SequentialThreadId<Atom>::prevId(0);
template <template <typename> class Atom>
FOLLY_TLS unsigned SequentialThreadId<Atom>::currentId(0);
thread_local unsigned SequentialThreadId<Atom>::currentId(0);
#endif
struct HashingThreadId {
......@@ -341,7 +341,7 @@ struct AccessSpreader : private detail::AccessSpreaderBase {
};
#ifdef FOLLY_CL_USE_FOLLY_TLS
static FOLLY_TLS CpuCache cpuCache;
static thread_local CpuCache cpuCache;
#endif
static bool initialized;
......@@ -384,7 +384,7 @@ typename AccessSpreader<Atom>::CompactStripe
#ifdef FOLLY_CL_USE_FOLLY_TLS
template <template <typename> class Atom>
FOLLY_TLS
thread_local
typename AccessSpreader<Atom>::CpuCache AccessSpreader<Atom>::cpuCache;
#endif
......
......@@ -37,7 +37,7 @@ EmptyTagVectorType kEmptyTagVector = {};
//// Debug and ASAN stuff
#if defined(FOLLY_TLS) && (!defined(NDEBUG) || FOLLY_LIBRARY_SANITIZE_ADDRESS)
#define FOLLY_F14_DETAIL_TLS_SIZE_T FOLLY_TLS std::size_t
#define FOLLY_F14_DETAIL_TLS_SIZE_T thread_local std::size_t
#else
#define FOLLY_F14_DETAIL_TLS_SIZE_T std::atomic<std::size_t>
#endif
......
......@@ -53,12 +53,6 @@
#include <folly/container/detail/F14IntrinsicsAvailability.h>
#include <folly/container/detail/F14Mask.h>
#if FOLLY_LIBRARY_SANITIZE_ADDRESS && defined(FOLLY_TLS)
#define FOLLY_F14_TLS_IF_ASAN FOLLY_TLS
#else
#define FOLLY_F14_TLS_IF_ASAN
#endif
#if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
#if FOLLY_F14_CRC_INTRINSIC_AVAILABLE
......
......@@ -58,9 +58,9 @@ struct SkipAtForkHandlers<true> {
static void set(bool value) { value_ = value; }
private:
static FOLLY_TLS bool value_;
static thread_local bool value_;
};
FOLLY_TLS bool SkipAtForkHandlers<true>::value_{false};
thread_local bool SkipAtForkHandlers<true>::value_{false};
#endif
struct AtForkTask {
......
......@@ -91,8 +91,8 @@ void MemoryIdler::flushLocalMallocCaches() {
#if (FOLLY_X64 || FOLLY_PPC64) && defined(_GNU_SOURCE) && \
defined(__linux__) && !FOLLY_MOBILE && !FOLLY_SANITIZE_ADDRESS
static FOLLY_TLS uintptr_t tls_stackLimit;
static FOLLY_TLS size_t tls_stackSize;
static thread_local uintptr_t tls_stackLimit;
static thread_local size_t tls_stackSize;
static size_t pageSize() {
static const size_t s_pageSize = sysconf(_SC_PAGESIZE);
......
......@@ -77,7 +77,7 @@ StaticMetaBase::StaticMetaBase(ThreadEntry* (*threadEntry)(), bool strict)
ThreadEntryList* StaticMetaBase::getThreadEntryList() {
#ifdef FOLLY_TLD_USE_FOLLY_TLS
static FOLLY_TLS ThreadEntryList threadEntryListSingleton;
static thread_local ThreadEntryList threadEntryListSingleton;
return &threadEntryListSingleton;
#else
class PthreadKey {
......
......@@ -416,8 +416,8 @@ struct FOLLY_EXPORT StaticMeta final : StaticMetaBase {
// cached fast path, leaving only one branch here and one indirection below.
uint32_t id = ent->getOrInvalid();
#ifdef FOLLY_TLD_USE_FOLLY_TLS
static FOLLY_TLS ThreadEntry* threadEntry{};
static FOLLY_TLS size_t capacity{};
static thread_local ThreadEntry* threadEntry{};
static thread_local size_t capacity{};
#else
ThreadEntry* threadEntry{};
size_t capacity{};
......@@ -448,7 +448,7 @@ struct FOLLY_EXPORT StaticMeta final : StaticMetaBase {
if (!threadEntry) {
ThreadEntryList* threadEntryList = StaticMeta::getThreadEntryList();
#ifdef FOLLY_TLD_USE_FOLLY_TLS
static FOLLY_TLS ThreadEntry threadEntrySingleton;
static thread_local ThreadEntry threadEntrySingleton;
threadEntry = &threadEntrySingleton;
#else
threadEntry = new ThreadEntry();
......
......@@ -28,10 +28,10 @@ namespace {
// If we somehow ended up in an invalid state, we don't want to print any stack
// trace at all because in could be bogus
FOLLY_TLS bool invalid;
thread_local bool invalid;
FOLLY_TLS StackTraceStack uncaughtExceptions;
FOLLY_TLS StackTraceStack caughtExceptions;
thread_local StackTraceStack uncaughtExceptions;
thread_local StackTraceStack caughtExceptions;
} // namespace
......
......@@ -63,7 +63,7 @@ void throwCallback(
void* ex, std::type_info*, void (**deleter)(void*)) noexcept {
// Make this code reentrant safe in case we throw an exception while
// handling an exception. Thread local variables are zero initialized.
static FOLLY_TLS bool handlingThrow;
static thread_local bool handlingThrow;
if (handlingThrow) {
return;
}
......
......@@ -23,7 +23,7 @@
namespace folly {
namespace detail {
static FOLLY_TLS uint32_t tls_lastCpuBufferSlot = 0;
static thread_local uint32_t tls_lastCpuBufferSlot = 0;
template <typename DigestT>
DigestBuilder<DigestT>::DigestBuilder(size_t bufferSize, size_t digestSize)
......
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