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