2011-12-07 02:01:47 +08:00
|
|
|
//===-------------------- test_exception_storage.cpp ----------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
// Source Licenses. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-05-07 05:30:56 +08:00
|
|
|
#include "../src/config.h"
|
|
|
|
|
2011-07-20 22:53:53 +08:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iostream>
|
2014-05-07 05:30:56 +08:00
|
|
|
#if !LIBCXXABI_SINGLE_THREADED
|
|
|
|
# include <pthread.h>
|
|
|
|
#endif
|
2012-01-28 08:30:38 +08:00
|
|
|
#include <unistd.h>
|
2011-07-20 22:53:53 +08:00
|
|
|
|
2012-01-28 08:30:38 +08:00
|
|
|
#include "../src/cxa_exception.hpp"
|
2011-07-20 22:53:53 +08:00
|
|
|
|
|
|
|
typedef __cxxabiv1::__cxa_eh_globals globals_t ;
|
|
|
|
|
|
|
|
void *thread_code (void *parm) {
|
|
|
|
size_t *result = (size_t *) parm;
|
|
|
|
globals_t *glob1, *glob2;
|
|
|
|
|
|
|
|
glob1 = __cxxabiv1::__cxa_get_globals ();
|
|
|
|
if ( NULL == glob1 )
|
|
|
|
std::cerr << "Got null result from __cxa_get_globals" << std::endl;
|
|
|
|
|
|
|
|
glob2 = __cxxabiv1::__cxa_get_globals_fast ();
|
|
|
|
if ( glob1 != glob2 )
|
|
|
|
std::cerr << "Got different globals!" << std::endl;
|
|
|
|
|
|
|
|
*result = (size_t) glob1;
|
|
|
|
sleep ( 1 );
|
|
|
|
return parm;
|
|
|
|
}
|
|
|
|
|
2014-05-07 05:30:56 +08:00
|
|
|
#if !LIBCXXABI_SINGLE_THREADED
|
2011-07-20 22:53:53 +08:00
|
|
|
#define NUMTHREADS 10
|
|
|
|
size_t thread_globals [ NUMTHREADS ] = { 0 };
|
|
|
|
pthread_t threads [ NUMTHREADS ];
|
2014-05-07 05:30:56 +08:00
|
|
|
#endif
|
2011-07-20 22:53:53 +08:00
|
|
|
|
|
|
|
void print_sizes ( size_t *first, size_t *last ) {
|
|
|
|
std::cout << "{ " << std::hex;
|
|
|
|
for ( size_t *iter = first; iter != last; ++iter )
|
|
|
|
std::cout << *iter << " ";
|
|
|
|
std::cout << "}" << std::dec << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main ( int argc, char *argv [] ) {
|
|
|
|
int retVal = 0;
|
|
|
|
|
2014-05-07 05:30:56 +08:00
|
|
|
#if LIBCXXABI_SINGLE_THREADED
|
|
|
|
size_t thread_globals;
|
|
|
|
retVal = thread_code(&thread_globals) != 0;
|
|
|
|
#else
|
2011-07-20 22:53:53 +08:00
|
|
|
// Make the threads, let them run, and wait for them to finish
|
|
|
|
for ( int i = 0; i < NUMTHREADS; ++i )
|
|
|
|
pthread_create( threads + i, NULL, thread_code, (void *) (thread_globals + i));
|
|
|
|
for ( int i = 0; i < NUMTHREADS; ++i )
|
|
|
|
pthread_join ( threads [ i ], NULL );
|
|
|
|
|
|
|
|
for ( int i = 0; i < NUMTHREADS; ++i )
|
|
|
|
if ( 0 == thread_globals [ i ] ) {
|
|
|
|
std::cerr << "Thread #" << i << " had a zero global" << std::endl;
|
|
|
|
retVal = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// print_sizes ( thread_globals, thread_globals + NUMTHREADS );
|
|
|
|
std::sort ( thread_globals, thread_globals + NUMTHREADS );
|
2012-02-01 04:01:06 +08:00
|
|
|
for ( int i = 1; i < NUMTHREADS; ++i )
|
|
|
|
if ( thread_globals [ i - 1 ] == thread_globals [ i ] ) {
|
2011-07-20 22:53:53 +08:00
|
|
|
std::cerr << "Duplicate thread globals (" << i-1 << " and " << i << ")" << std::endl;
|
|
|
|
retVal = 2;
|
|
|
|
}
|
|
|
|
// print_sizes ( thread_globals, thread_globals + NUMTHREADS );
|
2014-05-07 05:30:56 +08:00
|
|
|
|
|
|
|
#endif
|
2011-07-20 22:53:53 +08:00
|
|
|
return retVal;
|
|
|
|
}
|