MCPcopy Create free account
hub / github.com/aardappel/treesheets / InitCPU

Function InitCPU

lobster/src/platform.cpp:104–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102
103uint hwthreads = 2, hwcores = 1;
104void 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
130uint NumHWThreads() { return hwthreads; }
131uint NumHWCores() { return hwcores; }

Callers 1

InitPlatformFunction · 0.85

Calls 2

maxFunction · 0.85
dataMethod · 0.45

Tested by

no test coverage detected