mirror of
https://github.com/xzeldon/htop.git
synced 2024-12-23 22:55:46 +00:00
Replaces WRAP_SUBTRACT with saturatingSub inline function to reduce code duplication.
This commit is contained in:
parent
2f5b3ef733
commit
3770769ed1
2
Macros.h
2
Macros.h
@ -69,7 +69,7 @@
|
||||
#define IGNORE_WCASTQUAL_END
|
||||
#endif
|
||||
|
||||
/* This subtraction is used by NetBSD / OpenBSD for calculation of CPU usage items. */
|
||||
/* This subtraction is used by Linux / NetBSD / OpenBSD for calculation of CPU usage items. */
|
||||
static inline unsigned long long saturatingSub(unsigned long long a, unsigned long long b) {
|
||||
return a > b ? a - b : 0;
|
||||
}
|
||||
|
@ -1811,20 +1811,18 @@ static inline double LinuxProcessList_scanCPUTime(ProcessList* super) {
|
||||
// Since we do a subtraction (usertime - guest) and cputime64_to_clock_t()
|
||||
// used in /proc/stat rounds down numbers, it can lead to a case where the
|
||||
// integer overflow.
|
||||
#define WRAP_SUBTRACT(a,b) (((a) > (b)) ? (a) - (b) : 0)
|
||||
cpuData->userPeriod = WRAP_SUBTRACT(usertime, cpuData->userTime);
|
||||
cpuData->nicePeriod = WRAP_SUBTRACT(nicetime, cpuData->niceTime);
|
||||
cpuData->systemPeriod = WRAP_SUBTRACT(systemtime, cpuData->systemTime);
|
||||
cpuData->systemAllPeriod = WRAP_SUBTRACT(systemalltime, cpuData->systemAllTime);
|
||||
cpuData->idleAllPeriod = WRAP_SUBTRACT(idlealltime, cpuData->idleAllTime);
|
||||
cpuData->idlePeriod = WRAP_SUBTRACT(idletime, cpuData->idleTime);
|
||||
cpuData->ioWaitPeriod = WRAP_SUBTRACT(ioWait, cpuData->ioWaitTime);
|
||||
cpuData->irqPeriod = WRAP_SUBTRACT(irq, cpuData->irqTime);
|
||||
cpuData->softIrqPeriod = WRAP_SUBTRACT(softIrq, cpuData->softIrqTime);
|
||||
cpuData->stealPeriod = WRAP_SUBTRACT(steal, cpuData->stealTime);
|
||||
cpuData->guestPeriod = WRAP_SUBTRACT(virtalltime, cpuData->guestTime);
|
||||
cpuData->totalPeriod = WRAP_SUBTRACT(totaltime, cpuData->totalTime);
|
||||
#undef WRAP_SUBTRACT
|
||||
cpuData->userPeriod = saturatingSub(usertime, cpuData->userTime);
|
||||
cpuData->nicePeriod = saturatingSub(nicetime, cpuData->niceTime);
|
||||
cpuData->systemPeriod = saturatingSub(systemtime, cpuData->systemTime);
|
||||
cpuData->systemAllPeriod = saturatingSub(systemalltime, cpuData->systemAllTime);
|
||||
cpuData->idleAllPeriod = saturatingSub(idlealltime, cpuData->idleAllTime);
|
||||
cpuData->idlePeriod = saturatingSub(idletime, cpuData->idleTime);
|
||||
cpuData->ioWaitPeriod = saturatingSub(ioWait, cpuData->ioWaitTime);
|
||||
cpuData->irqPeriod = saturatingSub(irq, cpuData->irqTime);
|
||||
cpuData->softIrqPeriod = saturatingSub(softIrq, cpuData->softIrqTime);
|
||||
cpuData->stealPeriod = saturatingSub(steal, cpuData->stealTime);
|
||||
cpuData->guestPeriod = saturatingSub(virtalltime, cpuData->guestTime);
|
||||
cpuData->totalPeriod = saturatingSub(totaltime, cpuData->totalTime);
|
||||
cpuData->userTime = usertime;
|
||||
cpuData->niceTime = nicetime;
|
||||
cpuData->systemTime = systemtime;
|
||||
|
Loading…
Reference in New Issue
Block a user