Skip to content

Commit

Permalink
Removing sleep during shutdown if the background thread is already done.
Browse files Browse the repository at this point in the history
  • Loading branch information
khuck committed Apr 10, 2024
1 parent 4e97df1 commit 1d19a72
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/apex/proc_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ namespace apex {
break;
}
if (done) break;
reading = true;
if (apex_options::use_tau()) {
tau_listener::Tau_start_wrapper("proc_data_reader::read_proc: main loop");
}
Expand Down Expand Up @@ -873,7 +874,10 @@ namespace apex {
if (apex_options::use_tau()) {
tau_listener::Tau_stop_wrapper("proc_data_reader::read_proc: main loop");
}
reading = false;
}
// in case we broke from while loop
reading = false;
#ifdef APEX_HAVE_LM_SENSORS
delete(mysensors);
#endif
Expand Down
9 changes: 6 additions & 3 deletions src/apex/proc_read.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class proc_data_reader {
private:
//pthread_wrapper * worker_thread;
std::atomic<bool> done;
std::atomic<bool> reading;
std::thread worker_thread;
std::condition_variable cv;
std::mutex cv_m;
Expand All @@ -61,7 +62,7 @@ class proc_data_reader {
};
*/
void* read_proc(void);
proc_data_reader(void) : done(false) {
proc_data_reader(void) : done(false), reading(false) {
worker_thread = std::thread(&proc_data_reader::read_proc, this);
worker_thread.detach();
}
Expand All @@ -73,8 +74,10 @@ class proc_data_reader {
if (worker_thread.joinable()) {
worker_thread.join();
}
// this is helpful if we are sampling frequently
usleep(apex_options::proc_period());
if(reading) {
// this is helpful if we are sampling frequently
usleep(apex_options::proc_period());
}
}

~proc_data_reader(void) {
Expand Down

0 comments on commit 1d19a72

Please sign in to comment.