Author: hhinnant
Date: Mon Jan 23 17:55:58 2012
New Revision: 148750

URL: http://llvm.org/viewvc/llvm-project?rev=148750&view=rev
Log:
A lot of the code in cxa_exception.cpp depends on __cxa_get_globals_fast() 
returning null if __cxa_get_globals() hasn't been called yet.  However it 
doesn't reliably do that, at least on OS X if __cxa_get_globals_fast() is 
called prior to pthread_key_create() running.  Our choice is to either limit 
our use of __cxa_get_globals_fast() more than we have, or to have 
__cxa_get_globals_fast() initialize with pthread_key_create() if necessary.  I 
chose the latter, and replaced pthread_once with a C++11 local static (which 
should do the same thing).

Modified:
    libcxxabi/trunk/src/cxa_exception_storage.cpp

Modified: libcxxabi/trunk/src/cxa_exception_storage.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxxabi/trunk/src/cxa_exception_storage.cpp?rev=148750&r1=148749&r2=148750&view=diff
==============================================================================
--- libcxxabi/trunk/src/cxa_exception_storage.cpp (original)
+++ libcxxabi/trunk/src/cxa_exception_storage.cpp Mon Jan 23 17:55:58 2012
@@ -42,7 +42,6 @@
 
 namespace __cxxabiv1 {
 namespace {
-    pthread_once_t flag_ = PTHREAD_ONCE_INIT;
     pthread_key_t  key_;
 
     void destruct_ (void *p) throw () {
@@ -51,17 +50,15 @@
             abort_message("cannot zero out thread value for 
__cxa_get_globals()");
         }
 
-    void construct_ () throw () {
+    int construct_ () throw () {
         if ( 0 != pthread_key_create ( &key_, destruct_ ) )
             abort_message("cannot create pthread key for __cxa_get_globals()");
+        return 0;
         }
 }   
 
 extern "C" {
     __cxa_eh_globals * __cxa_get_globals () throw () {
-    //  First time through, create the key.
-        if ( 0 != pthread_once ( &flag_, construct_ ) ) 
-            abort_message("cannot run pthread_once for __cxa_get_globals()");
 
     //  Try to get the globals for this thread
         __cxa_eh_globals* retVal = __cxa_get_globals_fast ();
@@ -79,6 +76,8 @@
         }
 
     __cxa_eh_globals * __cxa_get_globals_fast () throw () {
+    //  First time through, create the key.
+        static int init = construct_();
         return static_cast<__cxa_eh_globals*>(::pthread_getspecific(key_));
         }
     


_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to