cpuinfo: Rename SDL_GetCPUCount to SDL_GetNumLogicalCPUCores

This was the only API that broke the "GetNumThings" convention
used elsewhere, so renaming it helps with consistency.
Adding "logical cores" to the name also makes it a bit
more immediately obvious what the count actually represents.
This commit is contained in:
Carl Åstholm
2024-09-14 00:06:38 +02:00
committed by Sam Lantinga
parent 93bf534268
commit 1f3fd65c4c
11 changed files with 32 additions and 24 deletions

View File

@@ -620,35 +620,35 @@ static int CPU_haveAVX512F(void)
}
#endif
static int SDL_CPUCount = 0;
static int SDL_NumLogicalCPUCores = 0;
int SDL_GetCPUCount(void)
int SDL_GetNumLogicalCPUCores(void)
{
if (!SDL_CPUCount) {
if (!SDL_NumLogicalCPUCores) {
#if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
if (SDL_CPUCount <= 0) {
SDL_CPUCount = (int)sysconf(_SC_NPROCESSORS_ONLN);
if (SDL_NumLogicalCPUCores <= 0) {
SDL_NumLogicalCPUCores = (int)sysconf(_SC_NPROCESSORS_ONLN);
}
#endif
#ifdef HAVE_SYSCTLBYNAME
if (SDL_CPUCount <= 0) {
size_t size = sizeof(SDL_CPUCount);
sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
if (SDL_NumLogicalCPUCores <= 0) {
size_t size = sizeof(SDL_NumLogicalCPUCores);
sysctlbyname("hw.ncpu", &SDL_NumLogicalCPUCores, &size, NULL, 0);
}
#endif
#if defined(SDL_PLATFORM_WINDOWS)
if (SDL_CPUCount <= 0) {
if (SDL_NumLogicalCPUCores <= 0) {
SYSTEM_INFO info;
GetSystemInfo(&info);
SDL_CPUCount = info.dwNumberOfProcessors;
SDL_NumLogicalCPUCores = info.dwNumberOfProcessors;
}
#endif
// There has to be at least 1, right? :)
if (SDL_CPUCount <= 0) {
SDL_CPUCount = 1;
if (SDL_NumLogicalCPUCores <= 0) {
SDL_NumLogicalCPUCores = 1;
}
}
return SDL_CPUCount;
return SDL_NumLogicalCPUCores;
}
#ifdef __e2k__