Files
FEX-Emu--FEX/External/FEXCore/Source/Utils/CPUInfo.cpp
T
Ryan Houdek 1248f3573c CPUInfo: Switch away from using get_nprocs_conf
Allocates memory behind our backs. Needed to make CI glibc allocator
clean.
2023-03-13 10:50:25 -07:00

25 lines
479 B
C++

#include <FEXHeaderUtils/Filesystem.h>
#include <fmt/format.h>
#include <cstddef>
#include <cstdint>
#include <linux/limits.h>
namespace FEXCore::CPUInfo {
uint32_t CalculateNumberOfCPUs() {
char Tmp[PATH_MAX];
size_t CPUs = 1;
for (;; ++CPUs) {
auto Size = fmt::format_to_n(Tmp, sizeof(Tmp), "/sys/devices/system/cpu/cpu{}", CPUs);
Tmp[Size.size] = 0;
if (!FHU::Filesystem::Exists(Tmp)) {
break;
}
}
return CPUs;
}
}