summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2017-06-20 08:11:43 +0000
committerPavel Labath <labath@google.com>2017-06-20 08:11:43 +0000
commitf891812b7bac04a52c5b82d1bfe0e81891974728 (patch)
tree4d333bb7db599be6d56a6970bc588faebe3c24b2
parent6c5c542986cdfc012d360ae38ef9b0cfbd0bb6d0 (diff)
downloadbcm5719-llvm-f891812b7bac04a52c5b82d1bfe0e81891974728.tar.gz
bcm5719-llvm-f891812b7bac04a52c5b82d1bfe0e81891974728.zip
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 llvm-svn: 305779
-rw-r--r--lldb/include/lldb/Host/Host.h9
-rw-r--r--lldb/source/Core/Timer.cpp44
-rw-r--r--lldb/source/Host/common/Host.cpp19
-rw-r--r--lldb/source/Host/windows/Host.cpp13
4 files changed, 14 insertions, 71 deletions
diff --git a/lldb/include/lldb/Host/Host.h b/lldb/include/lldb/Host/Host.h
index e396ca20a5e..bf48e207f1f 100644
--- a/lldb/include/lldb/Host/Host.h
+++ b/lldb/include/lldb/Host/Host.h
@@ -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
diff --git a/lldb/source/Core/Timer.cpp b/lldb/source/Core/Timer.cpp
index 6de4516f721..59c3e13a717 100644
--- a/lldb/source/Core/Timer.cpp
+++ b/lldb/source/Core/Timer.cpp
@@ -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_quiet = value; }
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, const char *format, ...)
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();
diff --git a/lldb/source/Host/common/Host.cpp b/lldb/source/Host/common/Host.cpp
index 5fc7a801d51..af0b5724892 100644
--- a/lldb/source/Host/common/Host.cpp
+++ b/lldb/source/Host/common/Host.cpp
@@ -406,25 +406,6 @@ const char *Host::GetSignalAsCString(int signo) {
#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) {
diff --git a/lldb/source/Host/windows/Host.cpp b/lldb/source/Host/windows/Host.cpp
index e1acd23d5c8..69a7c2ef4f7 100644
--- a/lldb/source/Host/windows/Host.cpp
+++ b/lldb/source/Host/windows/Host.cpp
@@ -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);
}
OpenPOWER on IntegriCloud