diff options
author | Howard Hinnant <hhinnant@apple.com> | 2012-01-23 23:55:58 +0000 |
---|---|---|
committer | Howard Hinnant <hhinnant@apple.com> | 2012-01-23 23:55:58 +0000 |
commit | fad744dd50bfc1637f0adb8de76919256a1ae81e (patch) | |
tree | 9574a7339c293901d2d4bd9ae053ef2f1901621b /libcxxabi/src/cxa_exception_storage.cpp | |
parent | 671caae892391bcbcd998209cbd8f0d147c98941 (diff) | |
download | bcm5719-llvm-fad744dd50bfc1637f0adb8de76919256a1ae81e.tar.gz bcm5719-llvm-fad744dd50bfc1637f0adb8de76919256a1ae81e.zip |
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).
llvm-svn: 148750
Diffstat (limited to 'libcxxabi/src/cxa_exception_storage.cpp')
-rw-r--r-- | libcxxabi/src/cxa_exception_storage.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/libcxxabi/src/cxa_exception_storage.cpp b/libcxxabi/src/cxa_exception_storage.cpp index 19d6eb83566..d648f295b34 100644 --- a/libcxxabi/src/cxa_exception_storage.cpp +++ b/libcxxabi/src/cxa_exception_storage.cpp @@ -42,7 +42,6 @@ extern "C" { namespace __cxxabiv1 { namespace { - pthread_once_t flag_ = PTHREAD_ONCE_INIT; pthread_key_t key_; void destruct_ (void *p) throw () { @@ -51,17 +50,15 @@ namespace { 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 @@ extern "C" { } __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_)); } |