mirror of https://github.com/facebook/rocksdb.git
Remove ROCKSDB_SUPPORT_THREAD_LOCAL define because it's a part of C++11 (#10015)
Summary: ROCKSDB_SUPPORT_THREAD_LOCAL definition has been removed. `__thread`(#define) has been replaced with `thread_local`(C++ keyword) across the code base. Pull Request resolved: https://github.com/facebook/rocksdb/pull/10015 Reviewed By: siying Differential Revision: D36485491 Pulled By: pdillinger fbshipit-source-id: 6522d212514ee190b90b4e2750c80c7e34013c78
This commit is contained in:
parent
e3a3dbf2be
commit
0a43061f8d
|
@ -337,9 +337,6 @@ endif()
|
||||||
# Reset the required flags
|
# Reset the required flags
|
||||||
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
|
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
|
||||||
|
|
||||||
# thread_local is part of C++11 and later (TODO: clean up this define)
|
|
||||||
add_definitions(-DROCKSDB_SUPPORT_THREAD_LOCAL)
|
|
||||||
|
|
||||||
option(WITH_IOSTATS_CONTEXT "Enable IO stats context" ON)
|
option(WITH_IOSTATS_CONTEXT "Enable IO stats context" ON)
|
||||||
if (NOT WITH_IOSTATS_CONTEXT)
|
if (NOT WITH_IOSTATS_CONTEXT)
|
||||||
add_definitions(-DNIOSTATS_CONTEXT)
|
add_definitions(-DNIOSTATS_CONTEXT)
|
||||||
|
|
|
@ -800,9 +800,6 @@ if [ "$?" = 0 ]; then
|
||||||
COMMON_FLAGS="$COMMON_FLAGS -DHAVE_UINT128_EXTENSION"
|
COMMON_FLAGS="$COMMON_FLAGS -DHAVE_UINT128_EXTENSION"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# thread_local is part of C++11 and later (TODO: clean up this define)
|
|
||||||
COMMON_FLAGS="$COMMON_FLAGS -DROCKSDB_SUPPORT_THREAD_LOCAL"
|
|
||||||
|
|
||||||
if [ "$FBCODE_BUILD" != "true" -a "$PLATFORM" = OS_LINUX ]; then
|
if [ "$FBCODE_BUILD" != "true" -a "$PLATFORM" = OS_LINUX ]; then
|
||||||
$CXX $COMMON_FLAGS $PLATFORM_SHARED_CFLAGS -x c++ -c - -o test_dl.o 2>/dev/null <<EOF
|
$CXX $COMMON_FLAGS $PLATFORM_SHARED_CFLAGS -x c++ -c - -o test_dl.o 2>/dev/null <<EOF
|
||||||
void dummy_func() {}
|
void dummy_func() {}
|
||||||
|
|
|
@ -147,7 +147,7 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CFLAGS+=" $DEPS_INCLUDE"
|
CFLAGS+=" $DEPS_INCLUDE"
|
||||||
CFLAGS+=" -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX -DROCKSDB_FALLOCATE_PRESENT -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_RANGESYNC_PRESENT -DROCKSDB_SCHED_GETCPU_PRESENT -DROCKSDB_SUPPORT_THREAD_LOCAL -DHAVE_SSE42"
|
CFLAGS+=" -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX -DROCKSDB_FALLOCATE_PRESENT -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_RANGESYNC_PRESENT -DROCKSDB_SCHED_GETCPU_PRESENT -DHAVE_SSE42"
|
||||||
CXXFLAGS+=" $CFLAGS"
|
CXXFLAGS+=" $CFLAGS"
|
||||||
|
|
||||||
EXEC_LDFLAGS=" $SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS $NUMA_LIB $TBB_LIBS"
|
EXEC_LDFLAGS=" $SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS $NUMA_LIB $TBB_LIBS"
|
||||||
|
|
|
@ -144,7 +144,7 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CFLAGS+=" $DEPS_INCLUDE"
|
CFLAGS+=" $DEPS_INCLUDE"
|
||||||
CFLAGS+=" -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX -DROCKSDB_FALLOCATE_PRESENT -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_RANGESYNC_PRESENT -DROCKSDB_SCHED_GETCPU_PRESENT -DROCKSDB_SUPPORT_THREAD_LOCAL -DHAVE_SSE42 -DROCKSDB_IOURING_PRESENT"
|
CFLAGS+=" -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX -DROCKSDB_FALLOCATE_PRESENT -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_RANGESYNC_PRESENT -DROCKSDB_SCHED_GETCPU_PRESENT -DHAVE_SSE42 -DROCKSDB_IOURING_PRESENT"
|
||||||
CXXFLAGS+=" $CFLAGS"
|
CXXFLAGS+=" $CFLAGS"
|
||||||
|
|
||||||
EXEC_LDFLAGS=" $SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS $NUMA_LIB $TBB_LIBS $LIBURING_LIBS $BENCHMARK_LIBS"
|
EXEC_LDFLAGS=" $SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS $NUMA_LIB $TBB_LIBS $LIBURING_LIBS $BENCHMARK_LIBS"
|
||||||
|
|
|
@ -154,7 +154,7 @@ CFLAGS+=" -isystem $KERNEL_HEADERS_INCLUDE/linux "
|
||||||
CFLAGS+=" -isystem $KERNEL_HEADERS_INCLUDE "
|
CFLAGS+=" -isystem $KERNEL_HEADERS_INCLUDE "
|
||||||
|
|
||||||
CFLAGS+=" $DEPS_INCLUDE"
|
CFLAGS+=" $DEPS_INCLUDE"
|
||||||
CFLAGS+=" -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX -DROCKSDB_FALLOCATE_PRESENT -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_RANGESYNC_PRESENT -DROCKSDB_SCHED_GETCPU_PRESENT -DROCKSDB_SUPPORT_THREAD_LOCAL -DHAVE_SSE42 -DROCKSDB_IOURING_PRESENT"
|
CFLAGS+=" -DROCKSDB_PLATFORM_POSIX -DROCKSDB_LIB_IO_POSIX -DROCKSDB_FALLOCATE_PRESENT -DROCKSDB_MALLOC_USABLE_SIZE -DROCKSDB_RANGESYNC_PRESENT -DROCKSDB_SCHED_GETCPU_PRESENT -DHAVE_SSE42 -DROCKSDB_IOURING_PRESENT"
|
||||||
CXXFLAGS+=" $CFLAGS"
|
CXXFLAGS+=" $CFLAGS"
|
||||||
|
|
||||||
EXEC_LDFLAGS=" $SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS $NUMA_LIB $TBB_LIBS $LIBURING_LIBS $BENCHMARK_LIBS"
|
EXEC_LDFLAGS=" $SNAPPY_LIBS $ZLIB_LIBS $BZIP_LIBS $LZ4_LIBS $ZSTD_LIBS $GFLAGS_LIBS $NUMA_LIB $TBB_LIBS $LIBURING_LIBS $BENCHMARK_LIBS"
|
||||||
|
|
|
@ -12,14 +12,6 @@
|
||||||
#include "db_stress_tool/db_stress_shared_state.h"
|
#include "db_stress_tool/db_stress_shared_state.h"
|
||||||
|
|
||||||
namespace ROCKSDB_NAMESPACE {
|
namespace ROCKSDB_NAMESPACE {
|
||||||
#if defined(ROCKSDB_SUPPORT_THREAD_LOCAL)
|
|
||||||
#if defined(OS_SOLARIS)
|
|
||||||
__thread bool SharedState::ignore_read_error;
|
|
||||||
#else
|
|
||||||
thread_local bool SharedState::ignore_read_error;
|
thread_local bool SharedState::ignore_read_error;
|
||||||
#endif // OS_SOLARIS
|
|
||||||
#else
|
|
||||||
bool SharedState::ignore_read_error;
|
|
||||||
#endif // ROCKSDB_SUPPORT_THREAD_LOCAL
|
|
||||||
} // namespace ROCKSDB_NAMESPACE
|
} // namespace ROCKSDB_NAMESPACE
|
||||||
#endif // GFLAGS
|
#endif // GFLAGS
|
||||||
|
|
|
@ -53,15 +53,7 @@ class SharedState {
|
||||||
// local variable updated via sync points to keep track of errors injected
|
// local variable updated via sync points to keep track of errors injected
|
||||||
// while reading filter blocks in order to ignore the Get/MultiGet result
|
// while reading filter blocks in order to ignore the Get/MultiGet result
|
||||||
// for those calls
|
// for those calls
|
||||||
#if defined(ROCKSDB_SUPPORT_THREAD_LOCAL)
|
|
||||||
#if defined(OS_SOLARIS)
|
|
||||||
static __thread bool ignore_read_error;
|
|
||||||
#else
|
|
||||||
static thread_local bool ignore_read_error;
|
static thread_local bool ignore_read_error;
|
||||||
#endif // OS_SOLARIS
|
|
||||||
#else
|
|
||||||
static bool ignore_read_error;
|
|
||||||
#endif // ROCKSDB_SUPPORT_THREAD_LOCAL
|
|
||||||
|
|
||||||
SharedState(Env* /*env*/, StressTest* stress_test)
|
SharedState(Env* /*env*/, StressTest* stress_test)
|
||||||
: cv_(&mu_),
|
: cv_(&mu_),
|
||||||
|
|
|
@ -81,10 +81,8 @@ struct IOStatsContext {
|
||||||
// If RocksDB is compiled with -DNIOSTATS_CONTEXT, then a pointer to a global,
|
// If RocksDB is compiled with -DNIOSTATS_CONTEXT, then a pointer to a global,
|
||||||
// non-thread-local IOStatsContext object will be returned. Attempts to update
|
// non-thread-local IOStatsContext object will be returned. Attempts to update
|
||||||
// this object will be ignored, and reading from it will also be no-op.
|
// this object will be ignored, and reading from it will also be no-op.
|
||||||
// Otherwise,
|
// Otherwise, a pointer to a thread-local IOStatsContext object will be
|
||||||
// a) if thread-local is supported on the platform, then a pointer to
|
// returned.
|
||||||
// a thread-local IOStatsContext object will be returned.
|
|
||||||
// b) if thread-local is NOT supported, then compilation will fail.
|
|
||||||
//
|
//
|
||||||
// This function never returns nullptr.
|
// This function never returns nullptr.
|
||||||
IOStatsContext* get_iostats_context();
|
IOStatsContext* get_iostats_context();
|
||||||
|
|
|
@ -22,8 +22,7 @@
|
||||||
|
|
||||||
#include "rocksdb/rocksdb_namespace.h"
|
#include "rocksdb/rocksdb_namespace.h"
|
||||||
|
|
||||||
#if !defined(ROCKSDB_LITE) && !defined(NROCKSDB_THREAD_STATUS) && \
|
#if !defined(ROCKSDB_LITE) && !defined(NROCKSDB_THREAD_STATUS)
|
||||||
defined(ROCKSDB_SUPPORT_THREAD_LOCAL)
|
|
||||||
#define ROCKSDB_USING_THREAD_STATUS
|
#define ROCKSDB_USING_THREAD_STATUS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,7 @@
|
||||||
|
|
||||||
namespace ROCKSDB_NAMESPACE {
|
namespace ROCKSDB_NAMESPACE {
|
||||||
|
|
||||||
#ifdef ROCKSDB_SUPPORT_THREAD_LOCAL
|
thread_local size_t ConcurrentArena::tls_cpuid = 0;
|
||||||
__thread size_t ConcurrentArena::tls_cpuid = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
// If the shard block size is too large, in the worst case, every core
|
// If the shard block size is too large, in the worst case, every core
|
||||||
|
@ -36,11 +34,9 @@ ConcurrentArena::ConcurrentArena(size_t block_size, AllocTracker* tracker,
|
||||||
|
|
||||||
ConcurrentArena::Shard* ConcurrentArena::Repick() {
|
ConcurrentArena::Shard* ConcurrentArena::Repick() {
|
||||||
auto shard_and_index = shards_.AccessElementAndIndex();
|
auto shard_and_index = shards_.AccessElementAndIndex();
|
||||||
#ifdef ROCKSDB_SUPPORT_THREAD_LOCAL
|
|
||||||
// even if we are cpu 0, use a non-zero tls_cpuid so we can tell we
|
// even if we are cpu 0, use a non-zero tls_cpuid so we can tell we
|
||||||
// have repicked
|
// have repicked
|
||||||
tls_cpuid = shard_and_index.second | shards_.Size();
|
tls_cpuid = shard_and_index.second | shards_.Size();
|
||||||
#endif
|
|
||||||
return shard_and_index.first;
|
return shard_and_index.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,11 +97,7 @@ class ConcurrentArena : public Allocator {
|
||||||
Shard() : free_begin_(nullptr), allocated_and_unused_(0) {}
|
Shard() : free_begin_(nullptr), allocated_and_unused_(0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef ROCKSDB_SUPPORT_THREAD_LOCAL
|
static thread_local size_t tls_cpuid;
|
||||||
static __thread size_t tls_cpuid;
|
|
||||||
#else
|
|
||||||
enum ZeroFirstEnum : size_t { tls_cpuid = 0 };
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char padding0[56] ROCKSDB_FIELD_UNUSED;
|
char padding0[56] ROCKSDB_FIELD_UNUSED;
|
||||||
|
|
||||||
|
|
|
@ -13,11 +13,8 @@ namespace ROCKSDB_NAMESPACE {
|
||||||
// Should not be used because the counters are not thread-safe.
|
// Should not be used because the counters are not thread-safe.
|
||||||
// Put here just to make get_iostats_context() simple without ifdef.
|
// Put here just to make get_iostats_context() simple without ifdef.
|
||||||
static IOStatsContext iostats_context;
|
static IOStatsContext iostats_context;
|
||||||
#elif defined(ROCKSDB_SUPPORT_THREAD_LOCAL)
|
|
||||||
__thread IOStatsContext iostats_context;
|
|
||||||
#else
|
#else
|
||||||
#error \
|
thread_local IOStatsContext iostats_context;
|
||||||
"No thread-local support. Disable iostats context with -DNIOSTATS_CONTEXT."
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
IOStatsContext* get_iostats_context() {
|
IOStatsContext* get_iostats_context() {
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
#include "monitoring/perf_step_timer.h"
|
#include "monitoring/perf_step_timer.h"
|
||||||
#include "rocksdb/iostats_context.h"
|
#include "rocksdb/iostats_context.h"
|
||||||
|
|
||||||
#if defined(ROCKSDB_SUPPORT_THREAD_LOCAL) && !defined(NIOSTATS_CONTEXT)
|
#if !defined(NIOSTATS_CONTEXT)
|
||||||
namespace ROCKSDB_NAMESPACE {
|
namespace ROCKSDB_NAMESPACE {
|
||||||
extern __thread IOStatsContext iostats_context;
|
extern thread_local IOStatsContext iostats_context;
|
||||||
} // namespace ROCKSDB_NAMESPACE
|
} // namespace ROCKSDB_NAMESPACE
|
||||||
|
|
||||||
// increment a specific counter by the specified value
|
// increment a specific counter by the specified value
|
||||||
|
@ -40,7 +40,7 @@ extern __thread IOStatsContext iostats_context;
|
||||||
PerfLevel::kEnableTimeAndCPUTimeExceptForMutex); \
|
PerfLevel::kEnableTimeAndCPUTimeExceptForMutex); \
|
||||||
iostats_step_timer_##metric.Start();
|
iostats_step_timer_##metric.Start();
|
||||||
|
|
||||||
#else // ROCKSDB_SUPPORT_THREAD_LOCAL && !NIOSTATS_CONTEXT
|
#else // !NIOSTATS_CONTEXT
|
||||||
|
|
||||||
#define IOSTATS_ADD(metric, value)
|
#define IOSTATS_ADD(metric, value)
|
||||||
#define IOSTATS_ADD_IF_POSITIVE(metric, value)
|
#define IOSTATS_ADD_IF_POSITIVE(metric, value)
|
||||||
|
@ -53,4 +53,4 @@ extern __thread IOStatsContext iostats_context;
|
||||||
#define IOSTATS_TIMER_GUARD(metric)
|
#define IOSTATS_TIMER_GUARD(metric)
|
||||||
#define IOSTATS_CPU_TIMER_GUARD(metric, clock) static_cast<void>(clock)
|
#define IOSTATS_CPU_TIMER_GUARD(metric, clock) static_cast<void>(clock)
|
||||||
|
|
||||||
#endif // ROCKSDB_SUPPORT_THREAD_LOCAL && !NIOSTATS_CONTEXT
|
#endif // !NIOSTATS_CONTEXT
|
||||||
|
|
|
@ -13,14 +13,8 @@ namespace ROCKSDB_NAMESPACE {
|
||||||
// Should not be used because the counters are not thread-safe.
|
// Should not be used because the counters are not thread-safe.
|
||||||
// Put here just to make get_perf_context() simple without ifdef.
|
// Put here just to make get_perf_context() simple without ifdef.
|
||||||
PerfContext perf_context;
|
PerfContext perf_context;
|
||||||
#elif defined(ROCKSDB_SUPPORT_THREAD_LOCAL)
|
|
||||||
#if defined(OS_SOLARIS)
|
|
||||||
__thread PerfContext perf_context;
|
|
||||||
#else // OS_SOLARIS
|
|
||||||
thread_local PerfContext perf_context;
|
|
||||||
#endif // OS_SOLARIS
|
|
||||||
#else
|
#else
|
||||||
#error "No thread-local support. Disable perf context with -DNPERF_CONTEXT."
|
thread_local PerfContext perf_context;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PerfContext* get_perf_context() {
|
PerfContext* get_perf_context() {
|
||||||
|
@ -28,7 +22,7 @@ PerfContext* get_perf_context() {
|
||||||
}
|
}
|
||||||
|
|
||||||
PerfContext::~PerfContext() {
|
PerfContext::~PerfContext() {
|
||||||
#if !defined(NPERF_CONTEXT) && defined(ROCKSDB_SUPPORT_THREAD_LOCAL) && !defined(OS_SOLARIS)
|
#if !defined(NPERF_CONTEXT) && !defined(OS_SOLARIS)
|
||||||
ClearPerLevelPerfContext();
|
ClearPerLevelPerfContext();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,11 +9,11 @@
|
||||||
#include "util/stop_watch.h"
|
#include "util/stop_watch.h"
|
||||||
|
|
||||||
namespace ROCKSDB_NAMESPACE {
|
namespace ROCKSDB_NAMESPACE {
|
||||||
#if defined(NPERF_CONTEXT) || !defined(ROCKSDB_SUPPORT_THREAD_LOCAL)
|
#if defined(NPERF_CONTEXT)
|
||||||
extern PerfContext perf_context;
|
extern PerfContext perf_context;
|
||||||
#else
|
#else
|
||||||
#if defined(OS_SOLARIS)
|
#if defined(OS_SOLARIS)
|
||||||
extern __thread PerfContext perf_context_;
|
extern thread_local PerfContext perf_context_;
|
||||||
#define perf_context (*get_perf_context())
|
#define perf_context (*get_perf_context())
|
||||||
#else
|
#else
|
||||||
extern thread_local PerfContext perf_context;
|
extern thread_local PerfContext perf_context;
|
||||||
|
|
|
@ -9,11 +9,7 @@
|
||||||
|
|
||||||
namespace ROCKSDB_NAMESPACE {
|
namespace ROCKSDB_NAMESPACE {
|
||||||
|
|
||||||
#ifdef ROCKSDB_SUPPORT_THREAD_LOCAL
|
thread_local PerfLevel perf_level = kEnableCount;
|
||||||
__thread PerfLevel perf_level = kEnableCount;
|
|
||||||
#else
|
|
||||||
PerfLevel perf_level = kEnableCount;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void SetPerfLevel(PerfLevel level) {
|
void SetPerfLevel(PerfLevel level) {
|
||||||
assert(level > kUninitialized);
|
assert(level > kUninitialized);
|
||||||
|
|
|
@ -9,10 +9,6 @@
|
||||||
|
|
||||||
namespace ROCKSDB_NAMESPACE {
|
namespace ROCKSDB_NAMESPACE {
|
||||||
|
|
||||||
#ifdef ROCKSDB_SUPPORT_THREAD_LOCAL
|
extern thread_local PerfLevel perf_level;
|
||||||
extern __thread PerfLevel perf_level;
|
|
||||||
#else
|
|
||||||
extern PerfLevel perf_level;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace ROCKSDB_NAMESPACE
|
} // namespace ROCKSDB_NAMESPACE
|
||||||
|
|
|
@ -16,7 +16,8 @@ namespace ROCKSDB_NAMESPACE {
|
||||||
|
|
||||||
#ifdef ROCKSDB_USING_THREAD_STATUS
|
#ifdef ROCKSDB_USING_THREAD_STATUS
|
||||||
|
|
||||||
__thread ThreadStatusData* ThreadStatusUpdater::thread_status_data_ = nullptr;
|
thread_local ThreadStatusData* ThreadStatusUpdater::thread_status_data_ =
|
||||||
|
nullptr;
|
||||||
|
|
||||||
void ThreadStatusUpdater::RegisterThread(ThreadStatus::ThreadType ttype,
|
void ThreadStatusUpdater::RegisterThread(ThreadStatus::ThreadType ttype,
|
||||||
uint64_t thread_id) {
|
uint64_t thread_id) {
|
||||||
|
|
|
@ -196,7 +196,7 @@ class ThreadStatusUpdater {
|
||||||
protected:
|
protected:
|
||||||
#ifdef ROCKSDB_USING_THREAD_STATUS
|
#ifdef ROCKSDB_USING_THREAD_STATUS
|
||||||
// The thread-local variable for storing thread status.
|
// The thread-local variable for storing thread status.
|
||||||
static __thread ThreadStatusData* thread_status_data_;
|
static thread_local ThreadStatusData* thread_status_data_;
|
||||||
|
|
||||||
// Returns the pointer to the thread status data only when the
|
// Returns the pointer to the thread status data only when the
|
||||||
// thread status data is non-null and has enable_tracking == true.
|
// thread status data is non-null and has enable_tracking == true.
|
||||||
|
|
|
@ -12,9 +12,9 @@
|
||||||
namespace ROCKSDB_NAMESPACE {
|
namespace ROCKSDB_NAMESPACE {
|
||||||
|
|
||||||
#ifdef ROCKSDB_USING_THREAD_STATUS
|
#ifdef ROCKSDB_USING_THREAD_STATUS
|
||||||
__thread ThreadStatusUpdater* ThreadStatusUtil::thread_updater_local_cache_ =
|
thread_local ThreadStatusUpdater*
|
||||||
nullptr;
|
ThreadStatusUtil::thread_updater_local_cache_ = nullptr;
|
||||||
__thread bool ThreadStatusUtil::thread_updater_initialized_ = false;
|
thread_local bool ThreadStatusUtil::thread_updater_initialized_ = false;
|
||||||
|
|
||||||
void ThreadStatusUtil::RegisterThread(const Env* env,
|
void ThreadStatusUtil::RegisterThread(const Env* env,
|
||||||
ThreadStatus::ThreadType thread_type) {
|
ThreadStatus::ThreadType thread_type) {
|
||||||
|
|
|
@ -94,7 +94,7 @@ class ThreadStatusUtil {
|
||||||
// When this variable is set to true, thread_updater_local_cache_
|
// When this variable is set to true, thread_updater_local_cache_
|
||||||
// will not be updated until this variable is again set to false
|
// will not be updated until this variable is again set to false
|
||||||
// in UnregisterThread().
|
// in UnregisterThread().
|
||||||
static __thread bool thread_updater_initialized_;
|
static thread_local bool thread_updater_initialized_;
|
||||||
|
|
||||||
// The thread-local cached ThreadStatusUpdater that caches the
|
// The thread-local cached ThreadStatusUpdater that caches the
|
||||||
// thread_status_updater_ of the first Env that uses any ThreadStatusUtil
|
// thread_status_updater_ of the first Env that uses any ThreadStatusUtil
|
||||||
|
@ -109,7 +109,7 @@ class ThreadStatusUtil {
|
||||||
// When thread_updater_initialized_ is set to true, this variable
|
// When thread_updater_initialized_ is set to true, this variable
|
||||||
// will not be updated until this thread_updater_initialized_ is
|
// will not be updated until this thread_updater_initialized_ is
|
||||||
// again set to false in UnregisterThread().
|
// again set to false in UnregisterThread().
|
||||||
static __thread ThreadStatusUpdater* thread_updater_local_cache_;
|
static thread_local ThreadStatusUpdater* thread_updater_local_cache_;
|
||||||
#else
|
#else
|
||||||
static bool thread_updater_initialized_;
|
static bool thread_updater_initialized_;
|
||||||
static ThreadStatusUpdater* thread_updater_local_cache_;
|
static ThreadStatusUpdater* thread_updater_local_cache_;
|
||||||
|
|
|
@ -25,11 +25,6 @@
|
||||||
|
|
||||||
#define ROCKSDB_NOEXCEPT noexcept
|
#define ROCKSDB_NOEXCEPT noexcept
|
||||||
|
|
||||||
// thread_local is part of C++11 and later (TODO: clean up this define)
|
|
||||||
#ifndef __thread
|
|
||||||
#define __thread thread_local
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#undef PLATFORM_IS_LITTLE_ENDIAN
|
#undef PLATFORM_IS_LITTLE_ENDIAN
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
#include <machine/endian.h>
|
#include <machine/endian.h>
|
||||||
|
|
|
@ -60,11 +60,6 @@ using ssize_t = SSIZE_T;
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define __attribute__(A)
|
#define __attribute__(A)
|
||||||
|
|
||||||
// thread_local is part of C++11 and later (TODO: clean up this define)
|
|
||||||
#ifndef __thread
|
|
||||||
#define __thread thread_local
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace ROCKSDB_NAMESPACE {
|
namespace ROCKSDB_NAMESPACE {
|
||||||
|
|
|
@ -14,11 +14,7 @@
|
||||||
#include "port/likely.h"
|
#include "port/likely.h"
|
||||||
#include "util/thread_local.h"
|
#include "util/thread_local.h"
|
||||||
|
|
||||||
#ifdef ROCKSDB_SUPPORT_THREAD_LOCAL
|
#define STORAGE_DECL static thread_local
|
||||||
#define STORAGE_DECL static __thread
|
|
||||||
#else
|
|
||||||
#define STORAGE_DECL static
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace ROCKSDB_NAMESPACE {
|
namespace ROCKSDB_NAMESPACE {
|
||||||
|
|
||||||
|
|
|
@ -140,20 +140,15 @@ private:
|
||||||
// The private mutex. Developers should always use Mutex() instead of
|
// The private mutex. Developers should always use Mutex() instead of
|
||||||
// using this variable directly.
|
// using this variable directly.
|
||||||
port::Mutex mutex_;
|
port::Mutex mutex_;
|
||||||
#ifdef ROCKSDB_SUPPORT_THREAD_LOCAL
|
|
||||||
// Thread local storage
|
// Thread local storage
|
||||||
static __thread ThreadData* tls_;
|
static thread_local ThreadData* tls_;
|
||||||
#endif
|
|
||||||
|
|
||||||
// Used to make thread exit trigger possible if !defined(OS_MACOSX).
|
// Used to make thread exit trigger possible if !defined(OS_MACOSX).
|
||||||
// Otherwise, used to retrieve thread data.
|
// Otherwise, used to retrieve thread data.
|
||||||
pthread_key_t pthread_key_;
|
pthread_key_t pthread_key_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
thread_local ThreadData* ThreadLocalPtr::StaticMeta::tls_ = nullptr;
|
||||||
#ifdef ROCKSDB_SUPPORT_THREAD_LOCAL
|
|
||||||
__thread ThreadData* ThreadLocalPtr::StaticMeta::tls_ = nullptr;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Windows doesn't support a per-thread destructor with its
|
// Windows doesn't support a per-thread destructor with its
|
||||||
// TLS primitives. So, we build it manually by inserting a
|
// TLS primitives. So, we build it manually by inserting a
|
||||||
|
@ -263,13 +258,10 @@ ThreadLocalPtr::StaticMeta* ThreadLocalPtr::Instance() {
|
||||||
// the following variable will go first, then OnThreadExit, therefore causing
|
// the following variable will go first, then OnThreadExit, therefore causing
|
||||||
// invalid access.
|
// invalid access.
|
||||||
//
|
//
|
||||||
// The above problem can be solved by using thread_local to store tls_ instead
|
// The above problem can be solved by using thread_local to store tls_.
|
||||||
// of using __thread. The major difference between thread_local and __thread
|
// thread_local supports dynamic construction and destruction of
|
||||||
// is that thread_local supports dynamic construction and destruction of
|
|
||||||
// non-primitive typed variables. As a result, we can guarantee the
|
// non-primitive typed variables. As a result, we can guarantee the
|
||||||
// destruction order even when the main thread dies before any child threads.
|
// destruction order even when the main thread dies before any child threads.
|
||||||
// However, thread_local is not supported in all compilers that accept -std=c++11
|
|
||||||
// (e.g., eg Mac with XCode < 8. XCode 8+ supports thread_local).
|
|
||||||
static ThreadLocalPtr::StaticMeta* inst = new ThreadLocalPtr::StaticMeta();
|
static ThreadLocalPtr::StaticMeta* inst = new ThreadLocalPtr::StaticMeta();
|
||||||
return inst;
|
return inst;
|
||||||
}
|
}
|
||||||
|
@ -328,10 +320,6 @@ ThreadLocalPtr::StaticMeta::StaticMeta()
|
||||||
#if !defined(OS_WIN)
|
#if !defined(OS_WIN)
|
||||||
static struct A {
|
static struct A {
|
||||||
~A() {
|
~A() {
|
||||||
#ifndef ROCKSDB_SUPPORT_THREAD_LOCAL
|
|
||||||
ThreadData* tls_ =
|
|
||||||
static_cast<ThreadData*>(pthread_getspecific(Instance()->pthread_key_));
|
|
||||||
#endif
|
|
||||||
if (tls_) {
|
if (tls_) {
|
||||||
OnThreadExit(tls_);
|
OnThreadExit(tls_);
|
||||||
}
|
}
|
||||||
|
@ -366,13 +354,6 @@ void ThreadLocalPtr::StaticMeta::RemoveThreadData(
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadData* ThreadLocalPtr::StaticMeta::GetThreadLocal() {
|
ThreadData* ThreadLocalPtr::StaticMeta::GetThreadLocal() {
|
||||||
#ifndef ROCKSDB_SUPPORT_THREAD_LOCAL
|
|
||||||
// Make this local variable name look like a member variable so that we
|
|
||||||
// can share all the code below
|
|
||||||
ThreadData* tls_ =
|
|
||||||
static_cast<ThreadData*>(pthread_getspecific(Instance()->pthread_key_));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (UNLIKELY(tls_ == nullptr)) {
|
if (UNLIKELY(tls_ == nullptr)) {
|
||||||
auto* inst = Instance();
|
auto* inst = Instance();
|
||||||
tls_ = new ThreadData(inst);
|
tls_ = new ThreadData(inst);
|
||||||
|
|
Loading…
Reference in New Issue