Skip to content

Commit 2b95568

Browse files
committed
No need for this "phantom" CPU thread
1 parent 4296eea commit 2b95568

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

linux/LinuxMachine.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,9 @@ static void LinuxMachine_scanCPUTime(LinuxMachine* this) {
408408
if (!file)
409409
CRT_fatalError("Cannot open " PROCSTATFILE);
410410

411-
// Add an extra phantom thread for a later loop
412-
assert(super->existingCPUs < UINT_MAX - 2);
413-
bool adjCpuIdProcessed[super->existingCPUs + 2];
411+
// One thread per CPU thread + one for the average
412+
assert(super->existingCPUs < UINT_MAX - 1);
413+
bool adjCpuIdProcessed[super->existingCPUs + 1];
414414
memset(adjCpuIdProcessed, 0, sizeof(adjCpuIdProcessed));
415415

416416
for (unsigned int i = 0; i <= super->existingCPUs; i++) {
@@ -485,9 +485,7 @@ static void LinuxMachine_scanCPUTime(LinuxMachine* this) {
485485
adjCpuIdProcessed[adjCpuId] = true;
486486
}
487487

488-
// Set the extra phantom thread as checked to make sure to mark trailing offline threads correctly in the loop
489-
adjCpuIdProcessed[super->existingCPUs + 1] = true;
490-
for (unsigned int i = 0; i <= super->existingCPUs + 1; i++) {
488+
for (unsigned int i = 0; i <= super->existingCPUs; i++) {
491489
if (!adjCpuIdProcessed[i]) {
492490
// Skipped an ID, but /proc/stat is ordered => threads in between are offline
493491
memset(&this->cpuData[i], 0, sizeof(CPUData));

0 commit comments

Comments
 (0)