[Lldb-commits] [lldb] r305779 - Remove home-grown thread-local storage wrappers
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Tue Jun 20 01:11:43 PDT 2017
Author: labath
Date: Tue Jun 20 03:11:43 2017
New Revision: 305779
URL: http://llvm.org/viewvc/llvm-project?rev=305779&view=rev
Log:
Remove home-grown thread-local storage wrappers
Summary:
Use c++11 thread_local variables instead. As far as I am aware, they are
supported by all compilers/targets we care about.
Reviewers: zturner, jingham
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D34274
Modified:
lldb/trunk/include/lldb/Host/Host.h
lldb/trunk/source/Core/Timer.cpp
lldb/trunk/source/Host/common/Host.cpp
lldb/trunk/source/Host/windows/Host.cpp
Modified: lldb/trunk/include/lldb/Host/Host.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/Host.h?rev=305779&r1=305778&r2=305779&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/Host.h (original)
+++ lldb/trunk/include/lldb/Host/Host.h Tue Jun 20 03:11:43 2017
@@ -132,15 +132,6 @@ public:
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
Modified: lldb/trunk/source/Core/Timer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Timer.cpp?rev=305779&r1=305778&r2=305779&view=diff
==============================================================================
--- lldb/trunk/source/Core/Timer.cpp (original)
+++ lldb/trunk/source/Core/Timer.cpp Tue Jun 20 03:11:43 2017
@@ -38,20 +38,9 @@ static std::mutex &GetFileMutex() {
return *g_file_mutex_ptr;
}
-static void ThreadSpecificCleanup(void *p) {
- delete static_cast<TimerStack *>(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 @@ void Timer::SetQuiet(bool value) { g_qui
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<std::mutex> 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(Timer::Category &category,
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<std::mutex> 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<double>(total_dur).count(),
duration<double>(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();
Modified: lldb/trunk/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=305779&r1=305778&r2=305779&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Host.cpp (original)
+++ lldb/trunk/source/Host/common/Host.cpp Tue Jun 20 03:11:43 2017
@@ -406,25 +406,6 @@ const char *Host::GetSignalAsCString(int
#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) {
Modified: lldb/trunk/source/Host/windows/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/windows/Host.cpp?rev=305779&r1=305778&r2=305779&view=diff
==============================================================================
--- lldb/trunk/source/Host/windows/Host.cpp (original)
+++ lldb/trunk/source/Host/windows/Host.cpp Tue Jun 20 03:11:43 2017
@@ -101,19 +101,6 @@ lldb::thread_t Host::GetCurrentThread()
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);
}
More information about the lldb-commits
mailing list