File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -194,8 +194,22 @@ std::pair<int, int> System::CpuTotalCores()
194194
195195 return std::make_pair (logical, physical);
196196#elif defined(unix) || defined(__unix) || defined(__unix__)
197- long processors = sysconf (_SC_NPROCESSORS_ONLN);
198- return std::make_pair (processors, processors);
197+ static std::regex pattern (" core id(.*): (.*)" );
198+
199+ std::set<int > cores;
200+
201+ std::string line;
202+ std::ifstream stream (" /proc/cpuinfo" );
203+ while (getline (stream, line))
204+ {
205+ std::smatch matches;
206+ if (std::regex_match (line, matches, pattern))
207+ cores.insert (atoi (matches[2 ].str ().c_str ()));
208+ }
209+
210+ size_t logical = cores.size ();
211+ long physical = sysconf (_SC_N2PROCESSORS_ONLN);
212+ return std::make_pair (logical, physical);
199213#elif defined(_WIN32) || defined(_WIN64)
200214 BOOL allocated = FALSE ;
201215 PSYSTEM_LOGICAL_PROCESSOR_INFORMATION pBuffer = nullptr ;
You can’t perform that action at this time.
0 commit comments