[llvm-commits] [compiler-rt] r147913 - in /compiler-rt/trunk/lib/asan: asan_internal.h asan_posix.cc asan_thread_registry.cc asan_thread_registry.h
Kostya Serebryany
kcc at google.com
Tue Jan 10 18:21:06 PST 2012
Author: kcc
Date: Tue Jan 10 20:21:06 2012
New Revision: 147913
URL: http://llvm.org/viewvc/llvm-project?rev=147913&view=rev
Log:
[asan] move TSD code into asan_posix.cc
Modified:
compiler-rt/trunk/lib/asan/asan_internal.h
compiler-rt/trunk/lib/asan/asan_posix.cc
compiler-rt/trunk/lib/asan/asan_thread_registry.cc
compiler-rt/trunk/lib/asan/asan_thread_registry.h
Modified: compiler-rt/trunk/lib/asan/asan_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=147913&r1=147912&r2=147913&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Tue Jan 10 20:21:06 2012
@@ -108,6 +108,12 @@
bool AsanInterceptsSignal(int signum);
void InstallSignalHandlers();
int GetPid();
+uintptr_t GetThreadSelf();
+
+// Wrapper for TLS/TSD.
+void AsanTSDInit();
+void *AsanTSDGet();
+void AsanTSDSet(void *tsd);
// Opens the file 'file_name" and reads up to 'max_len' bytes.
// The resulting buffer is mmaped and stored in '*buff'.
Modified: compiler-rt/trunk/lib/asan/asan_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_posix.cc?rev=147913&r1=147912&r2=147913&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_posix.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_posix.cc Tue Jan 10 20:21:06 2012
@@ -18,6 +18,7 @@
#include "asan_stack.h"
#include "asan_thread_registry.h"
+#include <pthread.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/resource.h>
@@ -72,6 +73,30 @@
return getpid();
}
+uintptr_t GetThreadSelf() {
+ return (uintptr_t)pthread_self();
+}
+
+// ---------------------- TSD ---------------- {{{1
+
+static pthread_key_t tsd_key;
+static bool tsd_key_inited = false;
+void AsanTSDInit() {
+ CHECK(!tsd_key_inited);
+ tsd_key_inited = true;
+ CHECK(0 == pthread_key_create(&tsd_key, 0));
+}
+
+void *AsanTSDGet() {
+ CHECK(tsd_key_inited);
+ return pthread_getspecific(tsd_key);
+}
+
+void AsanTSDSet(void *tsd) {
+ CHECK(tsd_key_inited);
+ pthread_setspecific(tsd_key, tsd);
+}
+
} // namespace __asan
#endif // __linux__ || __APPLE_
Modified: compiler-rt/trunk/lib/asan/asan_thread_registry.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_thread_registry.cc?rev=147913&r1=147912&r2=147913&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_thread_registry.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_thread_registry.cc Tue Jan 10 20:21:06 2012
@@ -17,9 +17,6 @@
#include "asan_thread.h"
#include "asan_thread_registry.h"
-#include <limits.h>
-#include <pthread.h>
-
namespace __asan {
static AsanThreadRegistry asan_thread_registry(__asan::LINKER_INITIALIZED);
@@ -35,8 +32,7 @@
mu_(x) { }
void AsanThreadRegistry::Init() {
- CHECK(0 == pthread_key_create(&tls_key_, 0));
- tls_key_created_ = true;
+ AsanTSDInit();
main_thread_.set_summary(&main_thread_summary_);
main_thread_summary_.set_thread(&main_thread_);
SetCurrent(&main_thread_);
@@ -70,9 +66,7 @@
}
AsanThread *AsanThreadRegistry::GetCurrent() {
- CHECK(tls_key_created_);
- AsanThreadSummary *summary =
- (AsanThreadSummary *)pthread_getspecific(tls_key_);
+ AsanThreadSummary *summary = (AsanThreadSummary *)AsanTSDGet();
if (!summary) return 0;
return summary->thread();
}
@@ -80,17 +74,12 @@
void AsanThreadRegistry::SetCurrent(AsanThread *t) {
CHECK(t->summary());
if (FLAG_v >= 2) {
- Report("SetCurrent: %p for thread %p\n", t->summary(), pthread_self());
+ Report("SetCurrent: %p for thread %p\n", t->summary(), GetThreadSelf());
}
// Make sure we do not reset the current AsanThread.
- intptr_t old_key = (intptr_t)pthread_getspecific(tls_key_);
- CHECK(!old_key);
- CHECK(0 == pthread_setspecific(tls_key_, t->summary()));
- CHECK(pthread_getspecific(tls_key_) == t->summary());
-}
-
-pthread_key_t AsanThreadRegistry::GetTlsKey() {
- return tls_key_;
+ CHECK(AsanTSDGet() == 0);
+ AsanTSDSet(t->summary());
+ CHECK(AsanTSDGet() == t->summary());
}
AsanStats &AsanThreadRegistry::GetCurrentThreadStats() {
Modified: compiler-rt/trunk/lib/asan/asan_thread_registry.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_thread_registry.h?rev=147913&r1=147912&r2=147913&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_thread_registry.h (original)
+++ compiler-rt/trunk/lib/asan/asan_thread_registry.h Tue Jan 10 20:21:06 2012
@@ -38,7 +38,6 @@
// Get the current thread. May return NULL.
AsanThread *GetCurrent();
void SetCurrent(AsanThread *t);
- pthread_key_t GetTlsKey();
int GetCurrentTidOrMinusOne() {
AsanThread *t = GetCurrent();
@@ -71,12 +70,6 @@
AsanStats accumulated_stats_;
int n_threads_;
AsanLock mu_;
- // For each thread tls_key_ stores the pointer to the corresponding
- // AsanThread.
- pthread_key_t tls_key_;
- // This flag is updated only once at program startup, and then read
- // by concurrent threads.
- bool tls_key_created_;
};
// Returns a single instance of registry.
More information about the llvm-commits
mailing list