| 102 | |
| 103 | uint hwthreads = 2, hwcores = 1; |
| 104 | void InitCPU() { |
| 105 | // This can fail and return 0, so default to 2 threads: |
| 106 | hwthreads = max(2U, thread::hardware_concurrency()); |
| 107 | // As a baseline, assume desktop CPUs are hyperthreaded, and mobile ones are not. |
| 108 | #ifdef PLATFORM_ES3 |
| 109 | hwcores = hwthreads; |
| 110 | #else |
| 111 | hwcores = max(1U, hwthreads / 2); |
| 112 | #endif |
| 113 | // On Windows, we can do better and actually count cores. |
| 114 | #ifdef _WIN32 |
| 115 | DWORD buflen = 0; |
| 116 | if (!GetLogicalProcessorInformation(nullptr, &buflen) && GetLastError() == ERROR_INSUFFICIENT_BUFFER) { |
| 117 | vector<SYSTEM_LOGICAL_PROCESSOR_INFORMATION> buf(buflen / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION)); |
| 118 | if (GetLogicalProcessorInformation(buf.data(), &buflen)) { |
| 119 | uint cores = 0; |
| 120 | for (auto &lpi : buf) { |
| 121 | if (lpi.Relationship == RelationProcessorCore) cores++; |
| 122 | } |
| 123 | // Only overwrite our baseline if we actually found any cores. |
| 124 | if (cores) hwcores = cores; |
| 125 | } |
| 126 | } |
| 127 | #endif |
| 128 | } |
| 129 | |
| 130 | uint NumHWThreads() { return hwthreads; } |
| 131 | uint NumHWCores() { return hwcores; } |
no test coverage detected