Skip to content
Snippets Groups Projects

ProcStats : Use mutex lock to make fetch() thread safe.

Merged Christopher Rob Jones requested to merge jonrob/Gaudi:ProcStats-thread-safe into master
All threads resolved!
Compare and Show latest version
1 file
+ 8
16
Compare changes
  • Side-by-side
  • Inline
+ 8
16
@@ -263,16 +263,13 @@ bool ProcStats::fetch( procInfo& f ) {
#if defined( __linux__ ) or defined( __APPLE__ )
linux_proc pinfo;
auto read_proc = [&]() {
int cnt{0};
char buf[500];
bool ok = true;
int cnt{0};
char buf[500];
linux_proc pinfo;
m_ufd.lseek( 0, SEEK_SET );
if ( ( cnt = m_ufd.read( buf, sizeof( buf ) ) ) < 0 ) {
std::cerr << "ProcStats : LINUX Read of Proc file failed:" << std::endl;
return false;
}
if ( ( cnt = m_ufd.read( buf, sizeof( buf ) ) ) < 0 ) { ok = false; }
if ( cnt > 0 ) {
buf[std::min( static_cast<std::size_t>( cnt ), sizeof( buf ) - 1 )] = '\0';
sscanf(
@@ -292,19 +289,14 @@ bool ProcStats::fetch( procInfo& f ) {
const auto pr_rssize = static_cast<double>( pinfo.rss );
f.vsize = pr_size / ( 1024 * 1024 );
f.rss = pr_rssize * m_pg_size / ( 1024 * 1024 );
if ( 0 == pinfo.vsize ) { ok = false; }
}
return true;
return ok;
};
// attempt to read from proc
if ( !read_proc() ) {
std::cerr << "ProcStats : -> Will try reopening process proc stats" << std::endl;
open_ufd();
if ( !read_proc() ) { return false; }
}
if ( 0 == pinfo.vsize ) {
std::cerr << "ProcStats : 0==vsize -> Will try reopening process proc stats" << std::endl;
std::cerr << "ProcStats : -> Problems reading proc file. Will try reopening..." << std::endl;
open_ufd();
if ( !read_proc() ) { return false; }
}
Loading