From e725eddf1345fb4f73225e1e7ccf065deb4a1028 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 11 May 2021 22:02:42 -0700 Subject: [PATCH] CPUDetect: Ensure we never get zero cores. --- Common/CPUDetect.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Common/CPUDetect.cpp b/Common/CPUDetect.cpp index e5bc722af9..aaa7c3e94a 100644 --- a/Common/CPUDetect.cpp +++ b/Common/CPUDetect.cpp @@ -26,6 +26,7 @@ #include #endif +#include #include #include #include @@ -369,7 +370,7 @@ void CPUInfo::Detect() { } // This seems to be the count per core. Hopefully all cores are the same, but we counted each above. - logical_cpu_count /= num_cores; + logical_cpu_count /= std::max(num_cores, 1); #elif PPSSPP_PLATFORM(LINUX) if (File::Exists("/sys/devices/system/cpu/present")) { // This may not count unplugged cores, but at least it's a best guess. @@ -396,7 +397,7 @@ void CPUInfo::Detect() { } // This seems to be the count per core. Hopefully all cores are the same, but we counted each above. - std::max(logical_cpu_count /= std::max(num_cores, 1), 1); + logical_cpu_count /= std::max(num_cores, 1); #elif PPSSPP_PLATFORM(MAC) int num = 0; size_t sz = sizeof(num); @@ -404,10 +405,12 @@ void CPUInfo::Detect() { num_cores = num; sz = sizeof(num); if (sysctlbyname("hw.logicalcpu_max", &num, &sz, nullptr, 0) == 0) { - logical_cpu_count = num / num_cores; + logical_cpu_count = num / std::max(num_cores, 1); } } #endif + if (logical_cpu_count <= 0) + logical_cpu_count = 1; } // Turn the cpu info into a string we can show