[PATCH] D31884: Don't delete lsan thread-local data until it's no longer required
Francis Ricci via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 11 13:10:01 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL299978: Don't delete lsan thread-local data until it's no longer required (authored by fjricci).
Changed prior to commit:
https://reviews.llvm.org/D31884?vs=94676&id=94881#toc
Repository:
rL LLVM
https://reviews.llvm.org/D31884
Files:
compiler-rt/trunk/lib/lsan/lsan_common_mac.cc
compiler-rt/trunk/lib/lsan/lsan_thread.cc
Index: compiler-rt/trunk/lib/lsan/lsan_common_mac.cc
===================================================================
--- compiler-rt/trunk/lib/lsan/lsan_common_mac.cc
+++ compiler-rt/trunk/lib/lsan/lsan_common_mac.cc
@@ -33,7 +33,17 @@
static pthread_key_t key;
static pthread_once_t key_once = PTHREAD_ONCE_INIT;
-static void make_tls_key() { CHECK_EQ(pthread_key_create(&key, NULL), 0); }
+// The main thread destructor requires the current thread id,
+// so we can't destroy it until it's been used and reset to invalid tid
+void restore_tid_data(void *ptr) {
+ thread_local_data_t *data = (thread_local_data_t *)ptr;
+ if (data->current_thread_id != kInvalidTid)
+ pthread_setspecific(key, data);
+}
+
+static void make_tls_key() {
+ CHECK_EQ(pthread_key_create(&key, restore_tid_data), 0);
+}
static thread_local_data_t *get_tls_val(bool alloc) {
pthread_once(&key_once, make_tls_key);
@@ -65,7 +75,11 @@
--*disable_counter;
}
-u32 GetCurrentThread() { return get_tls_val(true)->current_thread_id; }
+u32 GetCurrentThread() {
+ thread_local_data_t *data = get_tls_val(false);
+ CHECK(data);
+ return data->current_thread_id;
+}
void SetCurrentThread(u32 tid) { get_tls_val(true)->current_thread_id = tid; }
Index: compiler-rt/trunk/lib/lsan/lsan_thread.cc
===================================================================
--- compiler-rt/trunk/lib/lsan/lsan_thread.cc
+++ compiler-rt/trunk/lib/lsan/lsan_thread.cc
@@ -92,6 +92,7 @@
void ThreadFinish() {
thread_registry->FinishThread(GetCurrentThread());
+ SetCurrentThread(kInvalidTid);
}
ThreadContext *CurrentThreadContext() {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31884.94881.patch
Type: text/x-patch
Size: 1632 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170411/89504632/attachment.bin>
More information about the llvm-commits
mailing list