pthread_key.cpp: factor out get_thread_key_data

This change makes it easier to move the location of the pthread keys
(e.g. into the bionic_tls struct).

Bug: http://b/78026329
Test: bionic unit tests
Test: disassembly of libc.so doesn't change
Change-Id: Ib75d9dab8726de96856af91ec3daa2c5cdbc2178
diff --git a/libc/bionic/pthread_key.cpp b/libc/bionic/pthread_key.cpp
index f3878a6..0356ccc 100644
--- a/libc/bionic/pthread_key.cpp
+++ b/libc/bionic/pthread_key.cpp
@@ -69,12 +69,16 @@
   return (key < (KEY_VALID_FLAG | BIONIC_PTHREAD_KEY_COUNT));
 }
 
+static inline pthread_key_data_t* get_thread_key_data() {
+  return __get_thread()->key_data;
+}
+
 // Called from pthread_exit() to remove all pthread keys. This must call the destructor of
 // all keys that have a non-NULL data value and a non-NULL destructor.
 __LIBC_HIDDEN__ void pthread_key_clean_all() {
   // Because destructors can do funky things like deleting/creating other keys,
   // we need to implement this in a loop.
-  pthread_key_data_t* key_data = __get_thread()->key_data;
+  pthread_key_data_t* key_data = get_thread_key_data();
   for (size_t rounds = PTHREAD_DESTRUCTOR_ITERATIONS; rounds > 0; --rounds) {
     size_t called_destructor_count = 0;
     for (size_t i = 0; i < BIONIC_PTHREAD_KEY_COUNT; ++i) {
@@ -158,7 +162,7 @@
   }
   key &= ~KEY_VALID_FLAG;
   uintptr_t seq = atomic_load_explicit(&key_map[key].seq, memory_order_relaxed);
-  pthread_key_data_t* data = &(__get_thread()->key_data[key]);
+  pthread_key_data_t* data = &get_thread_key_data()[key];
   // It is user's responsibility to synchornize between the creation and use of pthread keys,
   // so we use memory_order_relaxed when checking the sequence number.
   if (__predict_true(SeqOfKeyInUse(seq) && data->seq == seq)) {
@@ -178,7 +182,7 @@
   key &= ~KEY_VALID_FLAG;
   uintptr_t seq = atomic_load_explicit(&key_map[key].seq, memory_order_relaxed);
   if (__predict_true(SeqOfKeyInUse(seq))) {
-    pthread_key_data_t* data = &(__get_thread()->key_data[key]);
+    pthread_key_data_t* data = &get_thread_key_data()[key];
     data->seq = seq;
     data->data = const_cast<void*>(ptr);
     return 0;