[cfe-commits] [libcxx] r116500 - in /libcxx/trunk: include/future include/thread src/condition_variable.cpp src/future.cpp src/thread.cpp

Howard Hinnant hhinnant at apple.com
Thu Oct 14 12:18:05 PDT 2010


Author: hhinnant
Date: Thu Oct 14 14:18:04 2010
New Revision: 116500

URL: http://llvm.org/viewvc/llvm-project?rev=116500&view=rev
Log:
Convert __thread_local_data to the singleton pattern

Modified:
    libcxx/trunk/include/future
    libcxx/trunk/include/thread
    libcxx/trunk/src/condition_variable.cpp
    libcxx/trunk/src/future.cpp
    libcxx/trunk/src/thread.cpp

Modified: libcxx/trunk/include/future
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/future?rev=116500&r1=116499&r2=116500&view=diff
==============================================================================
--- libcxx/trunk/include/future (original)
+++ libcxx/trunk/include/future Thu Oct 14 14:18:04 2010
@@ -677,7 +677,7 @@
         throw future_error(make_error_code(future_errc::promise_already_satisfied));
     ::new(&__value_) _R(_STD::forward<_Arg>(__arg));
     this->__state_ |= base::__constructed;
-    __thread_local_data->__make_ready_at_thread_exit(this);
+    __thread_local_data()->__make_ready_at_thread_exit(this);
     __lk.unlock();
 }
 
@@ -750,7 +750,7 @@
         throw future_error(make_error_code(future_errc::promise_already_satisfied));
     __value_ = &__arg;
     this->__state_ |= base::__constructed;
-    __thread_local_data->__make_ready_at_thread_exit(this);
+    __thread_local_data()->__make_ready_at_thread_exit(this);
     __lk.unlock();
 }
 

Modified: libcxx/trunk/include/thread
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/thread?rev=116500&r1=116499&r2=116500&view=diff
==============================================================================
--- libcxx/trunk/include/thread (original)
+++ libcxx/trunk/include/thread Thu Oct 14 14:18:04 2010
@@ -318,13 +318,13 @@
     void __make_ready_at_thread_exit(__assoc_sub_state*);
 };
 
-extern __thread_specific_ptr<__thread_struct> __thread_local_data;
+__thread_specific_ptr<__thread_struct>& __thread_local_data();
 
 template <class _F>
 void*
 __thread_proxy(void* __vp)
 {
-    __thread_local_data.reset(new __thread_struct);
+    __thread_local_data().reset(new __thread_struct);
     std::unique_ptr<_F> __p(static_cast<_F*>(__vp));
     (*__p)();
     return nullptr;

Modified: libcxx/trunk/src/condition_variable.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/condition_variable.cpp?rev=116500&r1=116499&r2=116500&view=diff
==============================================================================
--- libcxx/trunk/src/condition_variable.cpp (original)
+++ libcxx/trunk/src/condition_variable.cpp Thu Oct 14 14:18:04 2010
@@ -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

Modified: libcxx/trunk/src/future.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/future.cpp?rev=116500&r1=116499&r2=116500&view=diff
==============================================================================
--- libcxx/trunk/src/future.cpp (original)
+++ libcxx/trunk/src/future.cpp Thu Oct 14 14:18:04 2010
@@ -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();
 }
 

Modified: libcxx/trunk/src/thread.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/thread.cpp?rev=116500&r1=116499&r2=116500&view=diff
==============================================================================
--- libcxx/trunk/src/thread.cpp (original)
+++ libcxx/trunk/src/thread.cpp Thu Oct 14 14:18:04 2010
@@ -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
 





More information about the cfe-commits mailing list