eliminated CheckIfKernelSupportsTLS

We don't care about pre-2.6.0 kernels anymore. So we can assume that
if compile time check worked, then at runtime it'll work.
This commit is contained in:
Aliaksey Kandratsenka 2014-03-15 13:18:28 -07:00
parent 81291ac399
commit 4f051fddcd
4 changed files with 3 additions and 65 deletions

View File

@ -913,10 +913,6 @@ class TCMallocImplementation : public MallocExtension {
static int tcmallocguard_refcount = 0; // no lock needed: runs before main()
TCMallocGuard::TCMallocGuard() {
if (tcmallocguard_refcount++ == 0) {
#ifdef HAVE_TLS // this is true if the cc/ld/libc combo support TLS
// Check whether the kernel also supports TLS (needs to happen at runtime)
tcmalloc::CheckIfKernelSupportsTLS();
#endif
ReplaceSystemAlloc(); // defined in libc_override_*.h
tc_free(tc_malloc(1));
ThreadCache::InitTSD();

View File

@ -76,46 +76,6 @@ __thread ThreadCache::ThreadLocalData ThreadCache::threadlocal_data_
bool ThreadCache::tsd_inited_ = false;
pthread_key_t ThreadCache::heap_key_;
#if defined(HAVE_TLS)
bool kernel_supports_tls = false; // be conservative
# if defined(_WIN32) // windows has supported TLS since winnt, I think.
void CheckIfKernelSupportsTLS() {
kernel_supports_tls = true;
}
# elif !HAVE_DECL_UNAME // if too old for uname, probably too old for TLS
void CheckIfKernelSupportsTLS() {
kernel_supports_tls = false;
}
# else
# include <sys/utsname.h> // DECL_UNAME checked for <sys/utsname.h> too
void CheckIfKernelSupportsTLS() {
struct utsname buf;
if (uname(&buf) < 0) { // should be impossible
Log(kLog, __FILE__, __LINE__,
"uname failed assuming no TLS support (errno)", errno);
kernel_supports_tls = false;
} else if (strcasecmp(buf.sysname, "linux") == 0) {
// The linux case: the first kernel to support TLS was 2.6.0
if (buf.release[0] < '2' && buf.release[1] == '.') // 0.x or 1.x
kernel_supports_tls = false;
else if (buf.release[0] == '2' && buf.release[1] == '.' &&
buf.release[2] >= '0' && buf.release[2] < '6' &&
buf.release[3] == '.') // 2.0 - 2.5
kernel_supports_tls = false;
else
kernel_supports_tls = true;
} else if (strcasecmp(buf.sysname, "CYGWIN_NT-6.1-WOW64") == 0) {
// In my testing, this version of cygwin, at least, would hang
// when using TLS.
kernel_supports_tls = false;
} else { // some other kernel, we'll be optimisitic
kernel_supports_tls = true;
}
// TODO(csilvers): VLOG(1) the tls status once we support RAW_VLOG
}
# endif // HAVE_DECL_UNAME
#endif // HAVE_TLS
void ThreadCache::Init(pthread_t tid) {
size_ = 0;

View File

@ -59,17 +59,6 @@
namespace tcmalloc {
// Even if we have support for thread-local storage in the compiler
// and linker, the OS may not support it. We need to check that at
// runtime. Right now, we have to keep a manual set of "bad" OSes.
#if defined(HAVE_TLS)
extern bool kernel_supports_tls; // defined in thread_cache.cc
void CheckIfKernelSupportsTLS();
inline bool KernelSupportsTLS() {
return kernel_supports_tls;
}
#endif // HAVE_TLS
//-------------------------------------------------------------------
// Data kept per thread
//-------------------------------------------------------------------
@ -395,12 +384,11 @@ inline void ThreadCache::Deallocate(void* ptr, size_t cl) {
inline ThreadCache* ThreadCache::GetThreadHeap() {
#ifdef HAVE_TLS
// __thread is faster, but only when the kernel supports it
if (KernelSupportsTLS())
return threadlocal_data_.heap;
#endif
return threadlocal_data_.heap;
#else
return reinterpret_cast<ThreadCache *>(
perftools_pthread_getspecific(heap_key_));
#endif
}
inline ThreadCache* ThreadCache::GetCacheWhichMustBePresent() {

View File

@ -83,12 +83,6 @@ extern "C" PERFTOOLS_DLL_DECL void WriteToStderr(const char* buf, int len) {
// -----------------------------------------------------------------------
// Threads code
// Declared (not extern "C") in thread_cache.h
bool CheckIfKernelSupportsTLS() {
// TODO(csilvers): return true (all win's since win95, at least, support this)
return false;
}
// Windows doesn't support pthread_key_create's destr_function, and in
// fact it's a bit tricky to get code to run when a thread exits. This
// is cargo-cult magic from http://www.codeproject.com/threads/tls.asp.