You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Warning(LOCATION, "Could not autodetect available number of threads! Disabling multithreading...");
52
+
return1;
53
+
}
54
+
}
55
+
56
+
//We don't want to rely on std::thread::hardware_concurrency() unless we have to, as it reports threads, not physical cores, and FSO doesn't gain much from hyperthreaded threads at the moment.
57
+
#ifdef WIN32
58
+
staticsize_tget_number_of_physical_cores() {
59
+
auto glpi = (BOOL (WINAPI *)(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD)) GetProcAddress(
if (info.Relationship == RelationProcessorCore && info.ProcessorMask != 0)
77
+
num_cores++;
78
+
}
79
+
80
+
if (num_cores < 1) {
81
+
//invalid results, try fallback
82
+
returnget_number_of_physical_cores_fallback();
83
+
}
84
+
else {
85
+
return num_cores;
86
+
}
87
+
}
88
+
#elif defined SCP_UNIX
89
+
staticsize_tget_number_of_physical_cores() {
90
+
try {
91
+
std::ifstream cpuinfo("/proc/cpuinfo");
92
+
SCP_string line;
93
+
while (std::getline(cpuinfo, line)) {
94
+
//Looking for a cpu cores property is fine assuming a user has only one physical CPU socket. If they have multiple CPU's, this'll underreport the core count, but that should be very rare in typical configurations
95
+
if (line.find("cpu cores") != SCP_string::npos){
96
+
size_t numberpos = line.find(": ");
97
+
if (numberpos == SCP_string::npos)
98
+
returnget_number_of_physical_cores_fallback();
99
+
100
+
int num_cores = std::stoi(line.substr(numberpos + 2));
0 commit comments