|
16 | 16 |
|
17 | 17 | #include "test_macros.h"
|
18 | 18 |
|
19 |
| -typedef __cxxabiv1::__cxa_eh_globals globals_t ; |
| 19 | +typedef __cxxabiv1::__cxa_eh_globals globals_t; |
20 | 20 |
|
21 |
| -void *thread_code (void *parm) { |
22 |
| - size_t *result = (size_t *) parm; |
23 |
| - globals_t *glob1, *glob2; |
| 21 | +void* thread_code(void* parm) { |
| 22 | + size_t* result = (size_t*)parm; |
| 23 | + globals_t *glob1, *glob2; |
24 | 24 |
|
25 |
| - glob1 = __cxxabiv1::__cxa_get_globals (); |
26 |
| - if ( NULL == glob1 ) |
27 |
| - std::printf("Got null result from __cxa_get_globals\n"); |
| 25 | + glob1 = __cxxabiv1::__cxa_get_globals(); |
| 26 | + if (NULL == glob1) |
| 27 | + std::printf("Got null result from __cxa_get_globals\n"); |
28 | 28 |
|
29 |
| - glob2 = __cxxabiv1::__cxa_get_globals_fast (); |
30 |
| - if ( glob1 != glob2 ) |
31 |
| - std::printf("Got different globals!\n"); |
| 29 | + glob2 = __cxxabiv1::__cxa_get_globals_fast(); |
| 30 | + if (glob1 != glob2) |
| 31 | + std::printf("Got different globals!\n"); |
32 | 32 |
|
33 |
| - *result = (size_t) glob1; |
| 33 | + *result = (size_t)glob1; |
34 | 34 | #ifndef TEST_HAS_NO_THREADS
|
35 |
| - sleep ( 1 ); |
| 35 | + sleep(1); |
36 | 36 | #endif
|
37 |
| - return parm; |
| 37 | + return parm; |
38 | 38 | }
|
39 | 39 |
|
40 | 40 | #ifndef TEST_HAS_NO_THREADS
|
41 |
| -#define NUMTHREADS 10 |
42 |
| -size_t thread_globals [ NUMTHREADS ] = { 0 }; |
43 |
| -std::__libcpp_thread_t threads [ NUMTHREADS ]; |
| 41 | +# define NUMTHREADS 10 |
| 42 | +size_t thread_globals[NUMTHREADS] = {0}; |
| 43 | +std::__libcpp_thread_t threads[NUMTHREADS]; |
44 | 44 | #endif
|
45 | 45 |
|
46 | 46 | int main() {
|
47 | 47 | #ifndef TEST_HAS_NO_THREADS
|
48 |
| -// Make the threads, let them run, and wait for them to finish |
49 |
| - for ( int i = 0; i < NUMTHREADS; ++i ) |
50 |
| - std::__libcpp_thread_create ( threads + i, thread_code, (void *) (thread_globals + i)); |
51 |
| - for ( int i = 0; i < NUMTHREADS; ++i ) |
52 |
| - std::__libcpp_thread_join ( &threads [ i ] ); |
| 48 | + // Make the threads, let them run, and wait for them to finish |
| 49 | + for (int i = 0; i < NUMTHREADS; ++i) |
| 50 | + std::__libcpp_thread_create(threads + i, thread_code, (void*)(thread_globals + i)); |
| 51 | + for (int i = 0; i < NUMTHREADS; ++i) |
| 52 | + std::__libcpp_thread_join(&threads[i]); |
53 | 53 |
|
54 |
| - int retVal = 0; |
55 |
| - for ( int i = 0; i < NUMTHREADS; ++i ) { |
56 |
| - if ( 0 == thread_globals [ i ] ) { |
57 |
| - std::printf("Thread #%d had a zero global\n", i); |
58 |
| - retVal = 1; |
59 |
| - } |
| 54 | + int retVal = 0; |
| 55 | + for (int i = 0; i < NUMTHREADS; ++i) { |
| 56 | + if (0 == thread_globals[i]) { |
| 57 | + std::printf("Thread #%d had a zero global\n", i); |
| 58 | + retVal = 1; |
60 | 59 | }
|
| 60 | + } |
61 | 61 |
|
62 |
| - std::sort ( thread_globals, thread_globals + NUMTHREADS ); |
63 |
| - for ( int i = 1; i < NUMTHREADS; ++i ) { |
64 |
| - if ( thread_globals [ i - 1 ] == thread_globals [ i ] ) { |
65 |
| - std::printf("Duplicate thread globals (%d and %d)\n", i-1, i); |
66 |
| - retVal = 2; |
67 |
| - } |
| 62 | + std::sort(thread_globals, thread_globals + NUMTHREADS); |
| 63 | + for (int i = 1; i < NUMTHREADS; ++i) { |
| 64 | + if (thread_globals[i - 1] == thread_globals[i]) { |
| 65 | + std::printf("Duplicate thread globals (%d and %d)\n", i - 1, i); |
| 66 | + retVal = 2; |
68 | 67 | }
|
69 |
| - return retVal; |
70 |
| -#else // TEST_HAS_NO_THREADS |
71 |
| - size_t thread_globals; |
72 |
| - thread_code(&thread_globals); |
73 |
| - // Check that __cxa_get_globals() is not NULL. |
74 |
| - return (thread_globals == 0) ? 1 : 0; |
| 68 | + } |
| 69 | + return retVal; |
| 70 | +#else // TEST_HAS_NO_THREADS |
| 71 | + size_t thread_globals; |
| 72 | + thread_code(&thread_globals); |
| 73 | + // Check that __cxa_get_globals() is not NULL. |
| 74 | + return (thread_globals == 0) ? 1 : 0; |
75 | 75 | #endif // !TEST_HAS_NO_THREADS
|
76 | 76 | }
|
0 commit comments