1 //===-------------------- test_exception_storage.cpp ----------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 #include <__threading_support>
15 #include "../src/cxa_exception.h"
17 typedef __cxxabiv1::__cxa_eh_globals globals_t
;
19 void *thread_code (void *parm
) {
20 size_t *result
= (size_t *) parm
;
21 globals_t
*glob1
, *glob2
;
23 glob1
= __cxxabiv1::__cxa_get_globals ();
25 std::cerr
<< "Got null result from __cxa_get_globals" << std::endl
;
27 glob2
= __cxxabiv1::__cxa_get_globals_fast ();
29 std::cerr
<< "Got different globals!" << std::endl
;
31 *result
= (size_t) glob1
;
36 #ifndef _LIBCXXABI_HAS_NO_THREADS
38 size_t thread_globals
[ NUMTHREADS
] = { 0 };
39 std::__libcpp_thread_t threads
[ NUMTHREADS
];
45 #ifndef _LIBCXXABI_HAS_NO_THREADS
46 // Make the threads, let them run, and wait for them to finish
47 for ( int i
= 0; i
< NUMTHREADS
; ++i
)
48 std::__libcpp_thread_create ( threads
+ i
, thread_code
, (void *) (thread_globals
+ i
));
49 for ( int i
= 0; i
< NUMTHREADS
; ++i
)
50 std::__libcpp_thread_join ( &threads
[ i
] );
52 for ( int i
= 0; i
< NUMTHREADS
; ++i
)
53 if ( 0 == thread_globals
[ i
] ) {
54 std::cerr
<< "Thread #" << i
<< " had a zero global" << std::endl
;
58 std::sort ( thread_globals
, thread_globals
+ NUMTHREADS
);
59 for ( int i
= 1; i
< NUMTHREADS
; ++i
)
60 if ( thread_globals
[ i
- 1 ] == thread_globals
[ i
] ) {
61 std::cerr
<< "Duplicate thread globals (" << i
-1 << " and " << i
<< ")" << std::endl
;
64 #else // _LIBCXXABI_HAS_NO_THREADS
65 size_t thread_globals
;
66 // Check that __cxa_get_globals() is not NULL.
67 if (thread_code(&thread_globals
) == 0) {
70 #endif // !_LIBCXXABI_HAS_NO_THREADS