Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multithread fix (#2) #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions sensors_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ static pthread_mutex_t read_mutex = PTHREAD_MUTEX_INITIALIZER;

static pthread_t thread;
static int thread_finished;
static int thread_active;

/* used to get the timer from Score-P */
static void scorep_plugin_libsensors_set_timer( uint64_t (*timer)(void)){
Expand Down Expand Up @@ -149,6 +150,7 @@ static int32_t scorep_plugin_libsensors_init()
counter_enabled=1;
thread=0;
thread_finished=1;
thread_active=0;
return 0;
}

Expand Down Expand Up @@ -248,9 +250,15 @@ SCOREP_Metric_Plugin_MetricProperties * scorep_plugin_libsensors_get_event_info(
static void scorep_plugin_libsensors_fini()
{
counter_enabled=0;
if ( thread != 0 ) {
pthread_join(thread, NULL);
if (1 == thread_active) {
int ret = pthread_join(thread, NULL);
if (0 != ret) {
fprintf(stderr, "failed to clean up measurement thread (%d): %s\n",
ret, strerror(errno));
}
thread_active=0;
}
pthread_mutex_destroy(&read_mutex);
sensors_cleanup();
}

Expand Down Expand Up @@ -306,11 +314,13 @@ static int32_t scorep_plugin_libsensors_add_counter(char * event_name)
return -ENOMEM;
}
// are all events added?
if (added_sensor_counters == number_sensors)
if (added_sensor_counters == number_sensors) {
if (pthread_create(&thread, NULL, &scorep_plugin_libsensors_thread_report, NULL)){
fprintf(stderr, "Score-P Sensors Plugin: Unable to start measurement thread.\n");
return -ECHILD;
}
thread_active=1;
}

return added_sensor_counters-1;
}
Expand Down