Merge "Add check for pthread_self() when looking up a thread" am: b90837c3d3
am: 7e694a20fd

* commit '7e694a20fd4136f8aca9afa294dae663a49efacc':
  Add check for pthread_self() when looking up a thread
diff --git a/libc/bionic/pthread_internal.cpp b/libc/bionic/pthread_internal.cpp
index 1967ccf..8946f79 100644
--- a/libc/bionic/pthread_internal.cpp
+++ b/libc/bionic/pthread_internal.cpp
@@ -81,6 +81,12 @@
 
 pthread_internal_t* __pthread_internal_find(pthread_t thread_id) {
   pthread_internal_t* thread = reinterpret_cast<pthread_internal_t*>(thread_id);
+
+  // check if thread is pthread_self() before acquiring the lock
+  if (thread == __get_thread()) {
+    return thread;
+  }
+
   ScopedPthreadMutexLocker locker(&g_thread_list_lock);
 
   for (pthread_internal_t* t = g_thread_list; t != NULL; t = t->next) {