OSDN Git Service

Make __get_thread inlined.
authorYabin Cui <yabinc@google.com>
Wed, 18 Mar 2015 21:14:02 +0000 (14:14 -0700)
committerYabin Cui <yabinc@google.com>
Thu, 19 Mar 2015 02:35:34 +0000 (19:35 -0700)
Bug: 19825434

Change-Id: Ifb672a45a5776b83625a25654ed0d6f7fc368ae3

libc/bionic/ndk_cruft.cpp
libc/bionic/pthread_internal.h
libc/bionic/pthread_internals.cpp

index 109c523..8b34495 100644 (file)
@@ -346,6 +346,14 @@ extern "C" void* dlmalloc(size_t size) {
   return malloc(size);
 }
 
+#define __get_thread __real_get_thread
+#include "pthread_internal.h"
+#undef __get_thread
+// Various third-party apps contain a backport of our pthread_rwlock implementation that uses this.
+extern "C" pthread_internal_t* __get_thread() {
+  return __real_get_thread();
+}
+
 #endif // !defined(__LP64__)
 
 // This is never implemented in bionic, only needed for ABI compatibility with the NDK.
index 8da99dd..99882ae 100644 (file)
@@ -113,8 +113,10 @@ __LIBC_HIDDEN__ void __init_tls(pthread_internal_t* thread);
 __LIBC_HIDDEN__ void __init_alternate_signal_stack(pthread_internal_t*);
 __LIBC_HIDDEN__ void _pthread_internal_add(pthread_internal_t* thread);
 
-/* Various third-party apps contain a backport of our pthread_rwlock implementation that uses this. */
-extern "C" __LIBC64_HIDDEN__ pthread_internal_t* __get_thread(void);
+// Make __get_thread() inlined for performance reason. See http://b/19825434.
+static inline __always_inline pthread_internal_t* __get_thread() {
+  return reinterpret_cast<pthread_internal_t*>(__get_tls()[TLS_SLOT_THREAD_ID]);
+}
 
 __LIBC_HIDDEN__ void pthread_key_clean_all(void);
 __LIBC_HIDDEN__ void _pthread_internal_remove_locked(pthread_internal_t* thread, bool free_thread);
index 14061d1..0dd88fe 100644 (file)
@@ -68,7 +68,3 @@ void _pthread_internal_add(pthread_internal_t* thread) {
   }
   g_thread_list = thread;
 }
-
-pthread_internal_t* __get_thread(void) {
-  return reinterpret_cast<pthread_internal_t*>(__get_tls()[TLS_SLOT_THREAD_ID]);
-}