Let g_thread_list_lock only protect g_thread_list.
As glibc/netbsd don't protect access to thread struct members by a global
lock, we don't want to do it either. This change reduces the
responsibility of g_thread_list_lock to only protect g_thread_list.
Bug: 19636317
Change-Id: I897890710653dac165d8fa4452c7ecf74abdbf2b
diff --git a/libc/bionic/pthread_create.cpp b/libc/bionic/pthread_create.cpp
index a4bd054..ef3ce05 100644
--- a/libc/bionic/pthread_create.cpp
+++ b/libc/bionic/pthread_create.cpp
@@ -83,7 +83,7 @@
}
}
-int __init_thread(pthread_internal_t* thread, bool add_to_thread_list) {
+int __init_thread(pthread_internal_t* thread) {
int error = 0;
if (__predict_true((thread->attr.flags & PTHREAD_ATTR_FLAG_DETACHED) == 0)) {
@@ -108,10 +108,6 @@
thread->cleanup_stack = NULL;
- if (add_to_thread_list) {
- _pthread_internal_add(thread);
- }
-
return error;
}
@@ -265,7 +261,7 @@
return clone_errno;
}
- int init_errno = __init_thread(thread, true);
+ int init_errno = __init_thread(thread);
if (init_errno != 0) {
// Mark the thread detached and replace its start_routine with a no-op.
// Letting the thread run is the easiest way to clean up its resources.
@@ -276,7 +272,7 @@
}
// Publish the pthread_t and unlock the mutex to let the new thread start running.
- *thread_out = reinterpret_cast<pthread_t>(thread);
+ *thread_out = __pthread_internal_add(thread);
pthread_mutex_unlock(&thread->startup_handshake_mutex);
return 0;