36 #if defined(HAVE_THREAD_LOCAL_STORAGE) 46 #ifdef ANY_THREAD_GETS_SIGNAL 57 #if defined(ANY_THREAD_GETS_SIGNAL) 59 char *error_ptc = NULL, *error_ptk = NULL;
60 void *symbol_ptc = NULL, *symbol_ptk = NULL, *handle = NULL;
62 handle = dlopen( NULL, RTLD_LAZY );
63 if ( handle == NULL ) {
69 symbol_ptc = dlsym( handle,
"pthread_self" );
70 if ( symbol_ptc == NULL ) {
71 error_ptc = dlerror( );
72 THRDBG(
"dlsym(%p,pthread_self) returned NULL: %s\n",
73 ( error_ptc ? error_ptc :
"No error, NULL symbol!" ) );
76 symbol_ptk = dlsym( handle,
"pthread_kill" );
77 if ( symbol_ptk == NULL ) {
78 error_ptk = dlerror( );
79 THRDBG(
"dlsym(%p,pthread_kill) returned NULL: %s\n",
80 ( error_ptk ? error_ptk :
"No error, NULL symbol!" ) );
117 thread->running_eventset =
120 if ( !
thread->running_eventset ) {
129 thread->running_eventset[
i] = NULL;
130 if (
thread->context[
i] == NULL ) {
131 for (
i--;
i >= 0;
i-- )
137 memset(
thread->context[
i], 0x00,
142 thread->tid = ( *_papi_hwi_thread_id_fn ) ( );
145 thread->tid = (
unsigned long ) getpid( );
156 THRDBG(
"Allocated thread %ld at %p, allocator: %ld\n",
thread->tid,
167 THRDBG(
"Freeing thread %ld at %p\n", ( *thread )->tid, *
thread );
170 if ( ( *thread )->context[
i] )
174 if ( ( *thread )->context )
177 if ( ( *thread )->running_eventset )
178 papi_free( ( *thread )->running_eventset );
191 THRDBG(
"_papi_hwi_thread_head is NULL\n" );
194 THRDBG(
"_papi_hwi_thread_head was thread %ld at %p\n",
200 THRDBG(
"_papi_hwi_thread_head was thread %ld at %p\n",
208 THRDBG(
"_papi_hwi_thread_head now thread %ld at %p\n",
213 #if defined(HAVE_THREAD_LOCAL_STORAGE) 217 THRDBG(
"TLS for thread %ld is now %p\n", entry->
tid,
232 THRDBG(
"_papi_hwi_thread_head was thread %ld at %p\n",
239 ( entry !=
tmp ) || ( prev == NULL );
tmp =
tmp->next ) {
243 if (
tmp != entry ) {
244 THRDBG(
"Thread %ld at %p was not found in the thread list!\n",
254 THRDBG(
"_papi_hwi_thread_head now NULL\n" );
256 prev->next =
tmp->next;
260 THRDBG(
"_papi_hwi_thread_head now thread %ld at %p\n",
263 THRDBG(
"Removed thread %p from list\n",
tmp );
268 #if defined(HAVE_THREAD_LOCAL_STORAGE) 270 THRDBG(
"TLS for thread %ld is now %p\n", entry->
tid,
292 if (
_papi_hwd[
i]->cmp_info.disabled)
continue;
307 #if defined(ANY_THREAD_GETS_SIGNAL) 318 int i,
retval, didsomething = 0;
331 THRDBG(
"Thread %ld sending signal %d to thread %ld\n",mytid,foo->
tid,
333 retval = (*_papi_hwi_thread_kill_fn)(foo->
tid,
354 #if !defined(ANY_THREAD_GETS_SIGNAL) 368 THRDBG(
"Set new thread id function to %p\n", id_fn );
377 THRDBG(
"Skipping set of thread id function\n" );
397 if ( ( ESI ) && (ESI->
master!=NULL) ) {
399 if ( ESI->
master == master ) {
425 tid = ( *_papi_hwi_thread_id_fn ) ( );
427 tid = (
unsigned long ) getpid( );
429 THRDBG(
"Want to shutdown thread %ld, alloc %ld, our_tid: %ld\n",
434 if ((
thread->tid==tid) || (
thread->allocator_tid == tid ) || force_shutdown) {
441 if (
_papi_hwd[
i]->cmp_info.disabled)
continue;
449 THRDBG(
"Skipping shutdown thread %ld at %p, thread %ld not allocator!\n",
461 unsigned long our_tid;
466 THRDBG(
"Did not find my thread for shutdown!\n" );
473 THRDBG(
"Shutting down %ld\n",our_tid);
495 THRDBG(
"looking at #%d %ld our_tid: %ld alloc_tid: %ld\n",
496 i,
tmp->tid,our_tid,
tmp->allocator_tid);
498 THRDBG(
"Also removing thread %ld\n",
tmp->tid);
515 #if defined(HAVE_THREAD_LOCAL_STORAGE) 520 #if defined(ANY_THREAD_GETS_SIGNAL) 535 #if defined(HAVE_THREAD_LOCAL_STORAGE) 540 #if defined(ANY_THREAD_GETS_SIGNAL) 557 int didsomething = 0;
566 memcpy( &where->
id[didsomething], &foo->
tid,
567 sizeof ( where->
id[didsomething] ) );
575 if ( ( where->
id ) || ( where->
data ) ) {
576 if ( didsomething >= where->
num )
584 where->
num = didsomething;
static void free_thread(ThreadInfo_t **thread)
int _papi_hwi_set_thread_id_fn(unsigned long(*id_fn)(void))
static int lookup_and_set_thread_symbols(void)
struct _ThreadInfo * next
#define THRDBG(format, args...)
static ThreadInfo_t * allocate_thread(int tid)
Return codes and api definitions.
volatile ThreadInfo_t * _papi_hwi_thread_head
void * thread_storage[PAPI_MAX_TLS]
int _papi_hwi_shutdown_global_threads(void)
inline_static int _papi_hwi_lock(int lck)
PAPI_os_info_t _papi_os_info
DynamicArray_t global_eventset_map
struct _ThreadInfo * master
inline_static int _papi_hwi_unlock(int lck)
#define PAPI_MULTIPLEXING
void PAPIERROR(char *format,...)
static void insert_thread(ThreadInfo_t *entry, int tid)
papi_mdi_t _papi_hwi_system_info
EventSetInfo_t ** dataSlotArray
static int _papi_hwi_thread_free_eventsets(long tid)
int _papi_hwi_broadcast_signal(unsigned int mytid)
EventSetInfo_t ** running_eventset
int _papi_hwi_gather_all_thrspec_data(int tag, PAPI_all_thr_spec_t *where)
#define THREAD_LOCAL_STORAGE_KEYWORD
inline_static ThreadInfo_t * _papi_hwi_lookup_thread(int custom_tid)
struct papi_vectors * _papi_hwd[]
THREAD_LOCAL_STORAGE_KEYWORD ThreadInfo_t * _papi_hwi_my_thread
void _papi_hwi_free_EventSet(EventSetInfo_t *ESI)
int _papi_hwi_shutdown_thread(ThreadInfo_t *thread, int force_shutdown)
static int remove_thread(ThreadInfo_t *entry)
int _papi_hwi_initialize_thread(ThreadInfo_t **dest, int tid)
int _papi_hwi_init_global_threads(void)
int(* _papi_hwi_thread_kill_fn)(int, int)
unsigned long(* _papi_hwi_thread_id_fn)(void)