Properly query sysconf settting and use NAN if unavailable

This also fixes an issue with time returned negative if sysconf(_SC_CLK_TCK) returned an error.
This commit is contained in:
Benny Baumann 2020-09-07 11:56:12 +02:00 committed by cgzones
parent 29ec115143
commit d0d3deb73c
1 changed files with 10 additions and 2 deletions

View File

@ -219,10 +219,18 @@ void ProcessList_delete(ProcessList* pl) {
free(this); free(this);
} }
static double jiffy = 0.0; static double jiffy = NAN;
static inline unsigned long long LinuxProcess_adjustTime(unsigned long long t) { static inline unsigned long long LinuxProcess_adjustTime(unsigned long long t) {
if(jiffy == 0.0) jiffy = sysconf(_SC_CLK_TCK); if(isnan(jiffy)) {
errno = 0;
long sc_jiffy = sysconf(_SC_CLK_TCK);
if(errno || -1 == sc_jiffy) {
jiffy = NAN;
return t; // Assume 100Hz clock
}
jiffy = sc_jiffy;
}
double jiffytime = 1.0 / jiffy; double jiffytime = 1.0 / jiffy;
return (unsigned long long) t * jiffytime * 100; return (unsigned long long) t * jiffytime * 100;
} }