|
PAPI
5.0.1.0
|


Go to the source code of this file.
CVS: $Id$
Definition in file threads.h.
| #define THREAD_LOCAL_STORAGE_KEYWORD |
| int _papi_hwi_broadcast_signal | ( | unsigned int | mytid | ) |

| void _papi_hwi_cleanup_thread_list | ( | void | ) |
| int _papi_hwi_gather_all_thrspec_data | ( | int | tag, |
| PAPI_all_thr_spec_t * | where | ||
| ) |
< Used with setting up array
< Used with setting up array
< No error
Definition at line 557 of file threads.c.
{
int didsomething = 0;
ThreadInfo_t *foo = NULL;
_papi_hwi_lock( THREADS_LOCK );
for ( foo = ( ThreadInfo_t * ) _papi_hwi_thread_head; foo != NULL;
foo = foo->next ) {
/* If we want thread ID's */
if ( where->id )
memcpy( &where->id[didsomething], &foo->tid,
sizeof ( where->id[didsomething] ) );
/* If we want data pointers */
if ( where->data )
where->data[didsomething] = foo->thread_storage[tag];
didsomething++;
if ( ( where->id ) || ( where->data ) ) {
if ( didsomething >= where->num )
break;
}
if ( foo->next == _papi_hwi_thread_head )
break;
}
where->num = didsomething;
_papi_hwi_unlock( THREADS_LOCK );
return ( PAPI_OK );
}


| int _papi_hwi_get_thr_context | ( | void ** | ) |
| int _papi_hwi_init_global_threads | ( | void | ) |
< Used with setting up array
< No error
< Used with setting up array
Definition at line 530 of file threads.c.
{
int retval;
ThreadInfo_t *tmp;
_papi_hwi_lock( GLOBAL_LOCK );
#if defined(HAVE_THREAD_LOCAL_STORAGE)
_papi_hwi_my_thread = NULL;
#endif
_papi_hwi_thread_head = NULL;
_papi_hwi_thread_id_fn = NULL;
#if defined(ANY_THREAD_GETS_SIGNAL)
_papi_hwi_thread_kill_fn = NULL;
#endif
retval = _papi_hwi_initialize_thread( &tmp , 0);
if ( retval == PAPI_OK ) {
retval = lookup_and_set_thread_symbols( );
}
_papi_hwi_unlock( GLOBAL_LOCK );
return ( retval );
}


| int _papi_hwi_initialize_thread | ( | ThreadInfo_t ** | dest, |
| int | tid | ||
| ) |
< Insufficient memory
< No error
Definition at line 276 of file threads.c.
{
int retval;
ThreadInfo_t *thread;
int i;
if ( ( thread = allocate_thread( tid ) ) == NULL ) {
*dest = NULL;
return PAPI_ENOMEM;
}
/* Call the component to fill in anything special. */
for ( i = 0; i < papi_num_components; i++ ) {
if (_papi_hwd[i]->cmp_info.disabled) continue;
retval = _papi_hwd[i]->init_thread( thread->context[i] );
if ( retval ) {
free_thread( &thread );
*dest = NULL;
return retval;
}
}
insert_thread( thread, tid );
*dest = thread;
return PAPI_OK;
}


| int _papi_hwi_insert_in_thread_list | ( | ThreadInfo_t * | ptr | ) |
| inline_static int _papi_hwi_lock | ( | int | lck | ) |
Definition at line 64 of file threads.h.
{
if ( _papi_hwi_thread_id_fn ) {
_papi_hwd_lock( lck );
THRDBG( "Lock %d\n", lck );
} else {
( void ) lck; /* unused if !defined(DEBUG) */
THRDBG( "Skipped lock %d\n", lck );
}
return ( PAPI_OK );
}

| inline_static int _papi_hwi_lookup_or_create_thread | ( | ThreadInfo_t ** | here, |
| int | tid | ||
| ) |
Definition at line 145 of file threads.h.
{
ThreadInfo_t *tmp = _papi_hwi_lookup_thread( tid );
int retval = PAPI_OK;
if ( tmp == NULL )
retval = _papi_hwi_initialize_thread( &tmp, tid );
if ( retval == PAPI_OK )
*here = tmp;
return ( retval );
}


| inline_static ThreadInfo_t* _papi_hwi_lookup_thread | ( | int | custom_tid | ) |
Definition at line 92 of file threads.h.
{
unsigned long int tid;
ThreadInfo_t *tmp;
if (custom_tid==0) {
#ifdef HAVE_THREAD_LOCAL_STORAGE
THRDBG( "TLS returning %p\n", _papi_hwi_my_thread );
return ( _papi_hwi_my_thread );
#else
if ( _papi_hwi_thread_id_fn == NULL ) {
THRDBG( "Threads not initialized, returning master thread at %p\n",
_papi_hwi_thread_head );
return ( ( ThreadInfo_t * ) _papi_hwi_thread_head );
}
tid = ( *_papi_hwi_thread_id_fn ) ( );
#endif
}
else {
tid=custom_tid;
}
THRDBG( "Threads initialized, looking for thread 0x%lx\n", tid );
_papi_hwi_lock( THREADS_LOCK );
tmp = ( ThreadInfo_t * ) _papi_hwi_thread_head;
while ( tmp != NULL ) {
THRDBG( "Examining thread tid 0x%lx at %p\n", tmp->tid, tmp );
if ( tmp->tid == tid )
break;
tmp = tmp->next;
if ( tmp == _papi_hwi_thread_head ) {
tmp = NULL;
break;
}
}
if ( tmp ) {
_papi_hwi_thread_head = tmp;
THRDBG( "Found thread %ld at %p\n", tid, tmp );
} else {
THRDBG( "Did not find tid %ld\n", tid );
}
_papi_hwi_unlock( THREADS_LOCK );
return ( tmp );
}


| int _papi_hwi_set_thread_id_fn | ( | unsigned long int(*)(void) | id_fn | ) |
| int _papi_hwi_shutdown_global_threads | ( | void | ) |
< Internal error, please send mail to the developers
Definition at line 457 of file threads.c.
{
int err,num_threads,i;
ThreadInfo_t *tmp,*next;
unsigned long our_tid;
tmp = _papi_hwi_lookup_thread( 0 );
if ( tmp == NULL ) {
THRDBG( "Did not find my thread for shutdown!\n" );
err = PAPI_EBUG;
}
else {
our_tid=tmp->tid;
THRDBG("Shutting down %ld\n",our_tid);
err = _papi_hwi_shutdown_thread( tmp );
/* count threads */
tmp = ( ThreadInfo_t * ) _papi_hwi_thread_head;
num_threads=0;
while(tmp!=NULL) {
num_threads++;
if (tmp->next==_papi_hwi_thread_head) break;
tmp=tmp->next;
}
/* Shut down all threads allocated by this thread */
/* Urgh it's a circular list where we removed in the loop */
/* so the only sane way to do it is get a count in advance */
tmp = ( ThreadInfo_t * ) _papi_hwi_thread_head;
for(i=0;i<num_threads;i++) {
next=tmp->next;
THRDBG("looking at #%d %ld our_tid: %ld alloc_tid: %ld\n",
i,tmp->tid,our_tid,tmp->allocator_tid);
if (tmp->allocator_tid==our_tid) {
THRDBG("Also removing thread %ld\n",tmp->tid);
err = _papi_hwi_shutdown_thread( tmp );
}
tmp=next;
}
}
#ifdef DEBUG
if ( ISLEVEL( DEBUG_THREADS ) ) {
if ( _papi_hwi_thread_head ) {
THRDBG( "Thread head %p still exists!\n", _papi_hwi_thread_head );
}
}
#endif
#if defined(HAVE_THREAD_LOCAL_STORAGE)
_papi_hwi_my_thread = NULL;
#endif
_papi_hwi_thread_head = NULL;
_papi_hwi_thread_id_fn = NULL;
#if defined(ANY_THREAD_GETS_SIGNAL)
_papi_hwi_thread_kill_fn = NULL;
#endif
return err;
}


| void _papi_hwi_shutdown_the_thread_list | ( | void | ) |
| int _papi_hwi_shutdown_thread | ( | ThreadInfo_t * | thread | ) |
< No error
< No error
< Internal error, please send mail to the developers
Definition at line 418 of file threads.c.
{
int retval = PAPI_OK;
unsigned long tid;
int i, failure = 0;
if ( _papi_hwi_thread_id_fn )
tid = ( *_papi_hwi_thread_id_fn ) ( );
else
tid = ( unsigned long ) getpid( );
THRDBG("Want to shutdown thread %ld, alloc %ld, our_tid: %ld\n",
thread->tid,
thread->allocator_tid,
tid);
if ((thread->tid==tid) || ( thread->allocator_tid == tid )) {
_papi_hwi_thread_free_eventsets(tid);
remove_thread( thread );
THRDBG( "Shutting down thread %ld at %p\n", thread->tid, thread );
for( i = 0; i < papi_num_components; i++ ) {
if (_papi_hwd[i]->cmp_info.disabled) continue;
retval = _papi_hwd[i]->shutdown_thread( thread->context[i]);
if ( retval != PAPI_OK ) failure = retval;
}
free_thread( &thread );
return ( failure );
}
THRDBG( "Skipping shutdown thread %ld at %p, thread %ld not allocator!\n",
thread->tid, thread, tid );
return PAPI_EBUG;
}


| inline_static int _papi_hwi_unlock | ( | int | lck | ) |
Definition at line 78 of file threads.h.
{
if ( _papi_hwi_thread_id_fn ) {
_papi_hwd_unlock( lck );
THRDBG( "Unlock %d\n", lck );
} else {
( void ) lck; /* unused if !defined(DEBUG) */
THRDBG( "Skipped unlock %d\n", lck );
}
return ( PAPI_OK );
}

| volatile ThreadInfo_t* _papi_hwi_thread_head |
| unsigned long int( * _papi_hwi_thread_id_fn)(void) |
| int( * _papi_hwi_thread_kill_fn)(int, int) |
Function that sends a signal to other threads