Convert __thread_local_data to the singleton pattern

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@116500 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/src/condition_variable.cpp b/src/condition_variable.cpp
index 3bafa8c..6727a02 100644
--- a/src/condition_variable.cpp
+++ b/src/condition_variable.cpp
@@ -64,7 +64,7 @@
 void
 notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk)
 {
-    __thread_local_data->notify_all_at_thread_exit(&cond, lk.release());
+    __thread_local_data()->notify_all_at_thread_exit(&cond, lk.release());
 }
 
 _LIBCPP_END_NAMESPACE_STD
diff --git a/src/future.cpp b/src/future.cpp
index 29b5864..f291fe5 100644
--- a/src/future.cpp
+++ b/src/future.cpp
@@ -83,7 +83,7 @@
     if (__has_value())
         throw future_error(make_error_code(future_errc::promise_already_satisfied));
     __state_ |= __constructed;
-    __thread_local_data->__make_ready_at_thread_exit(this);
+    __thread_local_data()->__make_ready_at_thread_exit(this);
     __lk.unlock();
 }
 
@@ -106,7 +106,7 @@
     if (__has_value())
         throw future_error(make_error_code(future_errc::promise_already_satisfied));
     __exception_ = __p;
-    __thread_local_data->__make_ready_at_thread_exit(this);
+    __thread_local_data()->__make_ready_at_thread_exit(this);
     __lk.unlock();
 }
 
diff --git a/src/thread.cpp b/src/thread.cpp
index 3d388e9..aa07513 100644
--- a/src/thread.cpp
+++ b/src/thread.cpp
@@ -83,7 +83,12 @@
 
 }  // this_thread
 
-__thread_specific_ptr<__thread_struct> __thread_local_data;
+__thread_specific_ptr<__thread_struct>&
+__thread_local_data()
+{
+    static __thread_specific_ptr<__thread_struct> __p;
+    return __p;
+}
 
 // __thread_struct_imp