Revert "Remove the global thread list."
This reverts commit b0e8c565a622b5519e03d4416b0b5b1a5f20d7f5.
Breaks swiftshader (http:/b/34883464).
Change-Id: I7b21193ba8a78f07d7ac65e41d0fe8516940a83b
diff --git a/libc/bionic/pthread_setname_np.cpp b/libc/bionic/pthread_setname_np.cpp
index 669ef04..6d2880e 100644
--- a/libc/bionic/pthread_setname_np.cpp
+++ b/libc/bionic/pthread_setname_np.cpp
@@ -43,7 +43,12 @@
#define MAX_TASK_COMM_LEN 16
static int __open_task_comm_fd(pthread_t t, int flags) {
- pthread_internal_t* thread = reinterpret_cast<pthread_internal_t*>(t);
+ pthread_internal_t* thread = __pthread_internal_find(t);
+ if (thread == nullptr) {
+ errno = ENOENT;
+ return -1;
+ }
+
char comm_name[64];
snprintf(comm_name, sizeof(comm_name), "/proc/self/task/%d/comm", thread->tid);
return open(comm_name, O_CLOEXEC | flags);