[asan] move TSD code into asan_posix.cc
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@147913 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/asan/asan_posix.cc b/lib/asan/asan_posix.cc
index a6d0eda..2bc9e48 100644
--- a/lib/asan/asan_posix.cc
+++ b/lib/asan/asan_posix.cc
@@ -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_