Remove PTHREAD_ATTR_FLAG_MAIN_THREAD.
Make this change because I think it is more reasonable to check stack info
in pthread_getattr_np. I believe pthread_attr_t is not tied with any thread,
and can't have a flag saying who using it is the main thread.
This change also helps refactor of g_thread_list_lock.
Bug: 19636317
Change-Id: Iedbb85a391ac3e1849dd036d01445dac4bc63db9
diff --git a/libc/bionic/pthread_attr.cpp b/libc/bionic/pthread_attr.cpp
index c65ccc1..be1c252 100644
--- a/libc/bionic/pthread_attr.cpp
+++ b/libc/bionic/pthread_attr.cpp
@@ -152,9 +152,6 @@
}
int pthread_attr_getstack(const pthread_attr_t* attr, void** stack_base, size_t* stack_size) {
- if ((attr->flags & PTHREAD_ATTR_FLAG_MAIN_THREAD) != 0) {
- return __pthread_attr_getstack_main_thread(stack_base, stack_size);
- }
*stack_base = attr->stack_base;
*stack_size = attr->stack_size;
return 0;
@@ -171,7 +168,13 @@
}
int pthread_getattr_np(pthread_t t, pthread_attr_t* attr) {
- *attr = reinterpret_cast<pthread_internal_t*>(t)->attr;
+ pthread_internal_t* thread = reinterpret_cast<pthread_internal_t*>(t);
+ *attr = thread->attr;
+ // The main thread's stack information is not stored in thread->attr, and we need to
+ // collect that at runtime.
+ if (thread->tid == getpid()) {
+ return __pthread_attr_getstack_main_thread(&attr->stack_base, &attr->stack_size);
+ }
return 0;
}