From 4bc739a54c4ba9063e91bef06ff226dab118792d Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Thu, 4 Feb 2016 16:21:01 -0800 Subject: [PATCH] Add check for pthread_self() when looking up a thread Check if thread_id is in fact pthread_self before locking on g_thread_list_lock in __pthread_internal_find. The main reason for doing this is not performance but to allow the linker use raise() which was not working because pthread_kill() couldn't find pthread_self() thread because the global thread list is initialized in libc.so and the linker's version of this list is empty. Bug: http://b/25867917 Change-Id: I18fe620e8cd465b30f0e1ff45fff32958f3c5c00 --- libc/bionic/pthread_internal.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libc/bionic/pthread_internal.cpp b/libc/bionic/pthread_internal.cpp index 1967ccf8c..8946f79af 100644 --- a/libc/bionic/pthread_internal.cpp +++ b/libc/bionic/pthread_internal.cpp @@ -81,6 +81,12 @@ void __pthread_internal_remove_and_free(pthread_internal_t* thread) { pthread_internal_t* __pthread_internal_find(pthread_t thread_id) { pthread_internal_t* thread = reinterpret_cast(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) {