mirror of
https://github.com/intel/llvm.git
synced 2026-01-28 19:43:38 +08:00
[hwasan] change the thread list so that main_thread can also be removed
llvm-svn: 341610
This commit is contained in:
@@ -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 *t) {
|
||||
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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user