[compiler-rt] r341610 - [hwasan] change the thread list so that main_thread can also be removed
Kostya Serebryany via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 6 17:16:55 PDT 2018
Author: kcc
Date: Thu Sep 6 17:16:55 2018
New Revision: 341610
URL: http://llvm.org/viewvc/llvm-project?rev=341610&view=rev
Log:
[hwasan] change the thread list so that main_thread can also be removed
Modified:
compiler-rt/trunk/lib/hwasan/hwasan_thread.cc
compiler-rt/trunk/lib/hwasan/hwasan_thread.h
Modified: compiler-rt/trunk/lib/hwasan/hwasan_thread.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_thread.cc?rev=341610&r1=341609&r2=341610&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_thread.cc (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_thread.cc Thu Sep 6 17:16:55 2018
@@ -24,7 +24,7 @@ static u32 RandomSeed() {
return seed;
}
-Thread *Thread::main_thread;
+Thread *Thread::thread_list_head;
SpinMutex Thread::thread_list_mutex;
Thread::ThreadStats Thread::thread_stats;
@@ -33,22 +33,26 @@ void Thread::InsertIntoThreadList(Thread
SpinMutexLock l(&thread_list_mutex);
thread_stats.n_live_threads++;
thread_stats.total_stack_size += t->stack_size();
- if (!main_thread) {
- main_thread = t;
+ if (!thread_list_head) {
+ thread_list_head = t;
return;
}
- Thread *last = main_thread;
+ Thread *last = thread_list_head;
while (last->next_)
last = last->next_;
last->next_ = t;
}
void Thread::RemoveFromThreadList(Thread *t) {
- if (t == main_thread) return; // Do nothing (happens due to pthread_exit).
SpinMutexLock l(&thread_list_mutex);
thread_stats.n_live_threads--;
thread_stats.total_stack_size -= t->stack_size();
- Thread *prev = main_thread;
+ if (t == thread_list_head) {
+ thread_list_head = t->next_;
+ t->next_ = nullptr;
+ return;
+ }
+ Thread *prev = thread_list_head;
Thread *cur = prev->next_;
CHECK(cur);
while (cur) {
Modified: compiler-rt/trunk/lib/hwasan/hwasan_thread.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/hwasan/hwasan_thread.h?rev=341610&r1=341609&r2=341610&view=diff
==============================================================================
--- compiler-rt/trunk/lib/hwasan/hwasan_thread.h (original)
+++ compiler-rt/trunk/lib/hwasan/hwasan_thread.h Thu Sep 6 17:16:55 2018
@@ -62,7 +62,7 @@ class Thread {
template <class CB>
static void VisitAllLiveThreads(CB cb) {
SpinMutexLock l(&thread_list_mutex);
- Thread *t = main_thread;
+ Thread *t = thread_list_head;
while (t) {
cb(t);
t = t->next_;
@@ -113,7 +113,7 @@ class Thread {
static void RemoveFromThreadList(Thread *t);
Thread *next_; // All live threads form a linked list.
static SpinMutex thread_list_mutex;
- static Thread *main_thread;
+ static Thread *thread_list_head;
static ThreadStats thread_stats;
u64 unique_id_; // counting from zero.
More information about the llvm-commits
mailing list