[libcxx-commits] [PATCH] D113054: [libcxxabi][SystemZ][z/OS] Update libcxxabi/src/cxa_exception_storage.cpp to support POSIX(OFF)
Daniel McIntosh via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Nov 4 18:37:36 PDT 2021
DanielMcIntosh-IBM updated this revision to Diff 384937.
DanielMcIntosh-IBM added a comment.
Address review comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D113054/new/
https://reviews.llvm.org/D113054
Files:
libcxxabi/src/cxa_exception_storage.cpp
libcxxabi/test/test_exception_storage.pass.cpp
Index: libcxxabi/test/test_exception_storage.pass.cpp
===================================================================
--- libcxxabi/test/test_exception_storage.pass.cpp
+++ libcxxabi/test/test_exception_storage.pass.cpp
@@ -45,33 +45,40 @@
#endif
int main() {
-#ifndef _LIBCXXABI_HAS_NO_THREADS
-// Make the threads, let them run, and wait for them to finish
- for ( int i = 0; i < NUMTHREADS; ++i )
- std::__libcpp_thread_create ( threads + i, thread_code, (void *) (thread_globals + i));
- for ( int i = 0; i < NUMTHREADS; ++i )
- std::__libcpp_thread_join ( &threads [ i ] );
+#ifdef _LIBCXXABI_HAS_NO_THREADS
+ size_t thread_globals;
+ thread_code(&thread_globals);
+ // Check that __cxa_get_globals() is not NULL.
+ return (thread_globals == 0) ? 1 : 0;
+#else // !_LIBCXXABI_HAS_NO_THREADS
+ // If threads are disabled at runtime, revert to single-threaded test.
+ if (!std::__libcpp_is_threading_api_enabled()) {
+ thread_code((void*)thread_globals);
+ // Check that __cxa_get_globals() is not NULL.
+ return (thread_globals[0] == 0) ? 1 : 0;
+ }
- int retVal = 0;
- for ( int i = 0; i < NUMTHREADS; ++i ) {
- if ( 0 == thread_globals [ i ] ) {
- std::printf("Thread #%d had a zero global\n", i);
- retVal = 1;
- }
+ // Make the threads, let them run, and wait for them to finish
+ for (int i = 0; i < NUMTHREADS; ++i)
+ std::__libcpp_thread_create(threads + i, thread_code, (void*)(thread_globals + i));
+ for (int i = 0; i < NUMTHREADS; ++i)
+ std::__libcpp_thread_join(&threads[i]);
+
+ int retVal = 0;
+ for (int i = 0; i < NUMTHREADS; ++i) {
+ if (0 == thread_globals[i]) {
+ std::printf("Thread #%d had a zero global\n", i);
+ retVal = 1;
}
+ }
- std::sort ( thread_globals, thread_globals + NUMTHREADS );
- for ( int i = 1; i < NUMTHREADS; ++i ) {
- if ( thread_globals [ i - 1 ] == thread_globals [ i ] ) {
- std::printf("Duplicate thread globals (%d and %d)\n", i-1, i);
- retVal = 2;
- }
+ std::sort(thread_globals, thread_globals + NUMTHREADS);
+ for (int i = 1; i < NUMTHREADS; ++i) {
+ if (thread_globals[i - 1] == thread_globals[i]) {
+ std::printf("Duplicate thread globals (%d and %d)\n", i - 1, i);
+ retVal = 2;
}
- return retVal;
-#else // _LIBCXXABI_HAS_NO_THREADS
- size_t thread_globals;
- thread_code(&thread_globals);
- // Check that __cxa_get_globals() is not NULL.
- return (thread_globals == 0) ? 1 : 0;
+ }
+ return retVal;
#endif // !_LIBCXXABI_HAS_NO_THREADS
}
Index: libcxxabi/src/cxa_exception_storage.cpp
===================================================================
--- libcxxabi/src/cxa_exception_storage.cpp
+++ libcxxabi/src/cxa_exception_storage.cpp
@@ -92,10 +92,15 @@
// to the Itanium ABI and is taken advantage of in several places in
// libc++abi.
__cxa_eh_globals *__cxa_get_globals_fast() {
- // First time through, create the key.
- if (0 != std::__libcpp_execute_once(&flag_, construct_))
- abort_message("execute once failure in __cxa_get_globals_fast()");
- return static_cast<__cxa_eh_globals*>(std::__libcpp_tls_get(key_));
+ // If threads are disabled at runtime, revert to single-threaded implementation.
+ if (!std::__libcpp_is_threading_api_enabled()) {
+ static __cxa_eh_globals eh_globals;
+ return &eh_globals;
+ }
+ // First time through, create the key.
+ if (0 != std::__libcpp_execute_once(&flag_, construct_))
+ abort_message("execute once failure in __cxa_get_globals_fast()");
+ return static_cast<__cxa_eh_globals*>(std::__libcpp_tls_get(key_));
}
} // extern "C"
} // namespace __cxxabiv1
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113054.384937.patch
Type: text/x-patch
Size: 3778 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20211105/2b21b656/attachment-0001.bin>
More information about the libcxx-commits
mailing list