void VTThrd_destroy(VTThrd* thrd, uint32_t tid) { #if !defined(VT_DISABLE_RFG) RFG_Regions_free(thrd->rfg_regions); #endif /* VT_DISABLE_RFG */ VTGen_destroy(thrd->gen); #if defined(VT_RUSAGE) if ( vt_rusage_num() > 0 ) { if ( thrd->ru_obj ) { vt_rusage_free(thrd->ru_obj); thrd->ru_obj = NULL; } if ( thrd->ru_valv ) { free(thrd->ru_valv); thrd->ru_valv = NULL; } } #endif /* VT_RUSAGE */ #if defined(VT_METR) if ( vt_metric_num() > 0 && thrd->is_virtual_thread == 0 ) { if ( thrd->metv ) { vt_metric_free(thrd->metv, tid); thrd->metv = NULL; } if ( thrd->offv ) { free(thrd->offv); thrd->offv = NULL; } if ( thrd->valv ) { free(thrd->valv); thrd->valv = NULL; } } #endif /* VT_METR */ free(thrd); /* decrement the thread object counter */ #if (defined(VT_MT) || defined(VT_HYB) || defined(VT_JAVA)) VTTHRD_LOCK_ENV(); VTThrdn--; vt_cntl_msg(2, "Thread object #%u destroyed, leaving %u", tid, VTThrdn); VTTHRD_UNLOCK_ENV(); #else /* VT_MT || VT_HYB || VT_JAVA */ VTThrdn--; vt_cntl_msg(2, "Thread object #%u destroyed, leaving %u", tid, VTThrdn); #endif /* VT_MT || VT_HYB || VT_JAVA */ }
static void pthread_key_destructor(void* data) { uint32_t tid = *((uint32_t*)data); #if defined(VT_METR) if (vt_is_alive && vt_metric_num() > 0 && VTThrdv[tid]->metv) { /* shut down metrics */ vt_metric_free(VTThrdv[tid]->metv, tid); VTThrdv[tid]->metv = NULL; } #endif /* VT_METR */ if (tid == 0) { /* register termination of main() thread (*tid==0) */ masterThreadTerminated = 1; /* TODO: It's unclear whether/where the lists of idle thread-IDs should be freed. Maybe at this point? */ } else if (vt_is_alive && reuseThreadIds) { /* store thread-ID for reuse */ pthread_mutex_lock(&threadReuseMutex); idle_tid_list_push_back(VTThrdv[tid]->parent_tid, tid); pthread_mutex_unlock(&threadReuseMutex); /* store last metric values */ #if defined(VT_METR) if (vt_metric_num() > 0 && VTThrdv[tid]->offv && VTThrdv[tid]->valv) memcpy(VTThrdv[tid]->offv, VTThrdv[tid]->valv, vt_metric_num() * sizeof(uint64_t)); #endif /* VT_METR */ /* only disable plugin counters, so they can be reused */ #if defined(VT_PLUGIN_CNTR) /* if we really use plugins and this thread also uses some */ if (vt_plugin_cntr_used && VTThrdv[tid]->plugin_cntr_defines) vt_plugin_cntr_thread_disable_counters(VTThrdv[tid]); #endif /* VT_PLUGIN_CNTR */ } /* free thread-specific data */ free(data); }
void VTThrd_delete(VTThrd* thrd, uint32_t tid) { if ( !thrd ) return; #if !defined(VT_DISABLE_RFG) if ( thrd->rfg_regions ) RFG_Regions_free(thrd->rfg_regions); #endif /* VT_DISABLE_RFG */ /* must be called before VTGen_delete */ #if defined(VT_PLUGIN_CNTR) /* if we really use plugins and this thread also uses some */ if ( vt_plugin_cntr_used && thrd->plugin_cntr_defines ){ vt_plugin_cntr_thread_exit(thrd); } #endif /* VT_PLUGIN_CNTR */ if ( thrd->gen ) VTGen_delete(thrd->gen); #if defined(VT_RUSAGE) if ( vt_rusage_num() > 0 ) { if ( thrd->ru_obj ) { vt_rusage_free(thrd->ru_obj); thrd->ru_obj = NULL; } if ( thrd->ru_valv ) { free(thrd->ru_valv); thrd->ru_valv = NULL; } } #endif /* VT_RUSAGE */ #if defined(VT_METR) if ( vt_metric_num() > 0 && thrd->is_virtual_thread == 0 ) { if ( thrd->metv ) { vt_metric_free(thrd->metv, tid); thrd->metv = NULL; } if ( thrd->offv ) { free( thrd->offv ); thrd->offv = NULL; } if ( thrd->valv ) { free(thrd->valv); thrd->valv = NULL; } } #endif /* VT_METR */ free(thrd); /* decrement the thread object counter */ #if (defined(VT_MT) || defined(VT_HYB) || defined(VT_JAVA)) VTTHRD_LOCK_ENV(); VTThrdn--; vt_cntl_msg(2, "Thread object #%u deleted, leaving %u", tid, VTThrdn); VTTHRD_UNLOCK_ENV(); #else /* VT_MT || VT_HYB || VT_JAVA */ VTThrdn--; vt_cntl_msg(2, "Thread object #%u deleted, leaving %u", tid, VTThrdn); #endif /* VT_MT || VT_HYB || VT_JAVA */ }