Index: lldb/trunk/include/lldb/Host/Host.h =================================================================== --- lldb/trunk/include/lldb/Host/Host.h +++ lldb/trunk/include/lldb/Host/Host.h @@ -132,15 +132,6 @@ static const char *GetSignalAsCString(int signo); - typedef void (*ThreadLocalStorageCleanupCallback)(void *p); - - static lldb::thread_key_t - ThreadLocalStorageCreate(ThreadLocalStorageCleanupCallback callback); - - static void *ThreadLocalStorageGet(lldb::thread_key_t key); - - static void ThreadLocalStorageSet(lldb::thread_key_t key, void *value); - //------------------------------------------------------------------ /// Given an address in the current process (the process that /// is running the LLDB code), return the name of the module that Index: lldb/trunk/source/Core/Timer.cpp =================================================================== --- lldb/trunk/source/Core/Timer.cpp +++ lldb/trunk/source/Core/Timer.cpp @@ -38,20 +38,9 @@ return *g_file_mutex_ptr; } -static void ThreadSpecificCleanup(void *p) { - delete static_cast(p); -} - -static TimerStack *GetTimerStackForCurrentThread() { - static lldb::thread_key_t g_key = - Host::ThreadLocalStorageCreate(ThreadSpecificCleanup); - - void *timer_stack = Host::ThreadLocalStorageGet(g_key); - if (timer_stack == NULL) { - Host::ThreadLocalStorageSet(g_key, new TimerStack); - timer_stack = Host::ThreadLocalStorageGet(g_key); - } - return (TimerStack *)timer_stack; +static TimerStack &GetTimerStackForCurrentThread() { + static thread_local TimerStack g_stack; + return g_stack; } Timer::Category::Category(const char *cat) : m_name(cat) { @@ -66,16 +55,14 @@ Timer::Timer(Timer::Category &category, const char *format, ...) : m_category(category), m_total_start(std::chrono::steady_clock::now()) { - TimerStack *stack = GetTimerStackForCurrentThread(); - if (!stack) - return; + TimerStack &stack = GetTimerStackForCurrentThread(); - stack->push_back(this); - if (g_quiet && stack->size() <= g_display_depth) { + stack.push_back(this); + if (g_quiet && stack.size() <= g_display_depth) { std::lock_guard lock(GetFileMutex()); // Indent - ::fprintf(stdout, "%*s", int(stack->size() - 1) * TIMER_INDENT_AMOUNT, ""); + ::fprintf(stdout, "%*s", int(stack.size() - 1) * TIMER_INDENT_AMOUNT, ""); // Print formatted string va_list args; va_start(args, format); @@ -90,26 +77,23 @@ Timer::~Timer() { using namespace std::chrono; - TimerStack *stack = GetTimerStackForCurrentThread(); - if (!stack) - return; - auto stop_time = steady_clock::now(); auto total_dur = stop_time - m_total_start; auto timer_dur = total_dur - m_child_duration; - if (g_quiet && stack->size() <= g_display_depth) { + TimerStack &stack = GetTimerStackForCurrentThread(); + if (g_quiet && stack.size() <= g_display_depth) { std::lock_guard lock(GetFileMutex()); ::fprintf(stdout, "%*s%.9f sec (%.9f sec)\n", - int(stack->size() - 1) * TIMER_INDENT_AMOUNT, "", + int(stack.size() - 1) * TIMER_INDENT_AMOUNT, "", duration(total_dur).count(), duration(timer_dur).count()); } - assert(stack->back() == this); - stack->pop_back(); - if (!stack->empty()) - stack->back()->ChildDuration(total_dur); + assert(stack.back() == this); + stack.pop_back(); + if (!stack.empty()) + stack.back()->ChildDuration(total_dur); // Keep total results for each category so we can dump results. m_category.m_nanos += std::chrono::nanoseconds(timer_dur).count(); Index: lldb/trunk/source/Host/common/Host.cpp =================================================================== --- lldb/trunk/source/Host/common/Host.cpp +++ lldb/trunk/source/Host/common/Host.cpp @@ -406,25 +406,6 @@ #endif -#ifndef _WIN32 - -lldb::thread_key_t -Host::ThreadLocalStorageCreate(ThreadLocalStorageCleanupCallback callback) { - pthread_key_t key; - ::pthread_key_create(&key, callback); - return key; -} - -void *Host::ThreadLocalStorageGet(lldb::thread_key_t key) { - return ::pthread_getspecific(key); -} - -void Host::ThreadLocalStorageSet(lldb::thread_key_t key, void *value) { - ::pthread_setspecific(key, value); -} - -#endif - #if !defined(__APPLE__) // see Host.mm bool Host::GetBundleDirectory(const FileSpec &file, FileSpec &bundle) { Index: lldb/trunk/source/Host/windows/Host.cpp =================================================================== --- lldb/trunk/source/Host/windows/Host.cpp +++ lldb/trunk/source/Host/windows/Host.cpp @@ -101,19 +101,6 @@ return lldb::thread_t(::GetCurrentThread()); } -lldb::thread_key_t -Host::ThreadLocalStorageCreate(ThreadLocalStorageCleanupCallback callback) { - return TlsAlloc(); -} - -void *Host::ThreadLocalStorageGet(lldb::thread_key_t key) { - return ::TlsGetValue(key); -} - -void Host::ThreadLocalStorageSet(lldb::thread_key_t key, void *value) { - ::TlsSetValue(key, value); -} - void Host::Kill(lldb::pid_t pid, int signo) { TerminateProcess((HANDLE)pid, 1); }