Fixed clang-build error in util/thread_local.cc

Summary:
This patch fixes the following clang-build error in util/thread_local.cc by using a cleaner macro blocker:

12:26:31 util/thread_local.cc:157:19: error: declaration shadows a static data member of 'rocksdb::ThreadLocalPtr::StaticMeta' [-Werror,-Wshadow]
12:26:31       ThreadData* tls_ =
12:26:31                   ^
12:26:31 util/thread_local.cc:19:66: note: previous declaration is here
12:26:31 __thread ThreadLocalPtr::ThreadData* ThreadLocalPtr::StaticMeta::tls_ = nullptr;
12:26:31                                                                  ^

Test Plan: db_test

Reviewers: sdong, anthony, IslamAbdelRahman, igor

Reviewed By: igor

Subscribers: dhruba

Differential Revision: https://reviews.facebook.net/D44043
This commit is contained in:
Yueh-Hsuan Chiang 2015-08-11 13:30:49 -07:00
parent cee1e8a080
commit e61fafbe7a
2 changed files with 13 additions and 7 deletions

View File

@ -15,7 +15,7 @@
namespace rocksdb {
port::Mutex ThreadLocalPtr::StaticMeta::mutex_;
#if !defined(OS_MACOSX) && !defined(OS_WIN)
#if ROCKSDB_SUPPORT_THREAD_LOCAL
__thread ThreadLocalPtr::ThreadData* ThreadLocalPtr::StaticMeta::tls_ = nullptr;
#endif
@ -149,19 +149,20 @@ ThreadLocalPtr::StaticMeta::StaticMeta() : next_instance_id_(0) {
// of memory backing destructed statically-scoped objects. Perhaps
// registering with atexit(3) would be more robust.
//
// This is not required on Windows. Also, it's not required on Mac
// as ThreadLocal is not supported in Mac.
#if !defined(OS_MACOSX) && !defined(IOS_CROSS_COMPILE) && !defined(OS_WIN)
// This is not required on Windows.
#if !defined(OS_WIN)
static struct A {
~A() {
#if !(ROCKSDB_SUPPORT_THREAD_LOCAL)
ThreadData* tls_ =
static_cast<ThreadData*>(pthread_getspecific(Instance()->pthread_key_));
#endif
if (tls_) {
OnThreadExit(tls_);
}
}
} a;
#endif
#endif // !defined(OS_WIN)
head_.next = &head_;
head_.prev = &head_;
@ -190,7 +191,7 @@ void ThreadLocalPtr::StaticMeta::RemoveThreadData(
}
ThreadLocalPtr::ThreadData* ThreadLocalPtr::StaticMeta::GetThreadLocal() {
#if defined(OS_MACOSX) || defined(OS_WIN)
#if !(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_ =

View File

@ -17,6 +17,11 @@
#include "util/autovector.h"
#include "port/port.h"
#ifndef ROCKSDB_SUPPORT_THREAD_LOCAL
#define ROCKSDB_SUPPORT_THREAD_LOCAL \
!defined(OS_WIN) && !defined(OS_MACOSX) && !defined(IOS_CROSS_COMPILE)
#endif
namespace rocksdb {
// Cleanup function that will be called for a stored thread local
@ -149,7 +154,7 @@ class ThreadLocalPtr {
// protect inst, next_instance_id_, free_instance_ids_, head_,
// ThreadData.entries
static port::Mutex mutex_;
#if !defined(OS_MACOSX) && !defined(OS_WIN)
#if ROCKSDB_SUPPORT_THREAD_LOCAL
// Thread local storage
static __thread ThreadData* tls_;
#endif