mirror of https://github.com/libsdl-org/SDL
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:
parent
93bf534268
commit
1f3fd65c4c
|
@ -3667,3 +3667,8 @@ identifier func =~ "^(SDL_AddEventWatch|SDL_AddHintCallback|SDL_AddSurfaceAltern
|
||||||
@@
|
@@
|
||||||
- SDL_NUM_SCANCODES
|
- SDL_NUM_SCANCODES
|
||||||
+ SDL_SCANCODE_COUNT
|
+ SDL_SCANCODE_COUNT
|
||||||
|
@@
|
||||||
|
@@
|
||||||
|
- SDL_GetCPUCount
|
||||||
|
+ SDL_GetNumLogicalCPUCores
|
||||||
|
(...)
|
||||||
|
|
|
@ -341,6 +341,7 @@ SDL_HasRDTSC() has been removed; there is no replacement. Don't use the RDTSC op
|
||||||
SDL_SIMDAlloc(), SDL_SIMDRealloc(), and SDL_SIMDFree() have been removed. You can use SDL_aligned_alloc() and SDL_aligned_free() with SDL_GetSIMDAlignment() to get the same functionality.
|
SDL_SIMDAlloc(), SDL_SIMDRealloc(), and SDL_SIMDFree() have been removed. You can use SDL_aligned_alloc() and SDL_aligned_free() with SDL_GetSIMDAlignment() to get the same functionality.
|
||||||
|
|
||||||
The following functions have been renamed:
|
The following functions have been renamed:
|
||||||
|
* SDL_GetCPUCount() => SDL_GetNumLogicalCPUCores()
|
||||||
* SDL_SIMDGetAlignment() => SDL_GetSIMDAlignment()
|
* SDL_SIMDGetAlignment() => SDL_GetSIMDAlignment()
|
||||||
|
|
||||||
## SDL_endian.h
|
## SDL_endian.h
|
||||||
|
|
|
@ -54,7 +54,7 @@ extern "C" {
|
||||||
#define SDL_CACHELINE_SIZE 128
|
#define SDL_CACHELINE_SIZE 128
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of CPU cores available.
|
* Get the number of logical CPU cores available.
|
||||||
*
|
*
|
||||||
* \returns the total number of logical CPU cores. On CPUs that include
|
* \returns the total number of logical CPU cores. On CPUs that include
|
||||||
* technologies such as hyperthreading, the number of logical cores
|
* technologies such as hyperthreading, the number of logical cores
|
||||||
|
@ -62,7 +62,7 @@ extern "C" {
|
||||||
*
|
*
|
||||||
* \since This function is available since SDL 3.0.0.
|
* \since This function is available since SDL 3.0.0.
|
||||||
*/
|
*/
|
||||||
extern SDL_DECLSPEC int SDLCALL SDL_GetCPUCount(void);
|
extern SDL_DECLSPEC int SDLCALL SDL_GetNumLogicalCPUCores(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine the L1 cache line size of the CPU.
|
* Determine the L1 cache line size of the CPU.
|
||||||
|
|
|
@ -74,6 +74,7 @@
|
||||||
#define SDL_NewAudioStream SDL_CreateAudioStream
|
#define SDL_NewAudioStream SDL_CreateAudioStream
|
||||||
|
|
||||||
/* ##SDL_cpuinfo.h */
|
/* ##SDL_cpuinfo.h */
|
||||||
|
#define SDL_GetCPUCount SDL_GetNumLogicalCPUCores
|
||||||
#define SDL_SIMDGetAlignment SDL_GetSIMDAlignment
|
#define SDL_SIMDGetAlignment SDL_GetSIMDAlignment
|
||||||
|
|
||||||
/* ##SDL_endian.h */
|
/* ##SDL_endian.h */
|
||||||
|
@ -703,6 +704,7 @@
|
||||||
#define SDL_NewAudioStream SDL_NewAudioStream_renamed_SDL_CreateAudioStream
|
#define SDL_NewAudioStream SDL_NewAudioStream_renamed_SDL_CreateAudioStream
|
||||||
|
|
||||||
/* ##SDL_cpuinfo.h */
|
/* ##SDL_cpuinfo.h */
|
||||||
|
#define SDL_GetCPUCount SDL_GetCPUCount_renamed_SDL_GetNumLogicalCPUCores
|
||||||
#define SDL_SIMDGetAlignment SDL_SIMDGetAlignment_renamed_SDL_GetSIMDAlignment
|
#define SDL_SIMDGetAlignment SDL_SIMDGetAlignment_renamed_SDL_GetSIMDAlignment
|
||||||
|
|
||||||
/* ##SDL_endian.h */
|
/* ##SDL_endian.h */
|
||||||
|
|
|
@ -620,35 +620,35 @@ static int CPU_haveAVX512F(void)
|
||||||
}
|
}
|
||||||
#endif
|
#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 defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
|
||||||
if (SDL_CPUCount <= 0) {
|
if (SDL_NumLogicalCPUCores <= 0) {
|
||||||
SDL_CPUCount = (int)sysconf(_SC_NPROCESSORS_ONLN);
|
SDL_NumLogicalCPUCores = (int)sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_SYSCTLBYNAME
|
#ifdef HAVE_SYSCTLBYNAME
|
||||||
if (SDL_CPUCount <= 0) {
|
if (SDL_NumLogicalCPUCores <= 0) {
|
||||||
size_t size = sizeof(SDL_CPUCount);
|
size_t size = sizeof(SDL_NumLogicalCPUCores);
|
||||||
sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
|
sysctlbyname("hw.ncpu", &SDL_NumLogicalCPUCores, &size, NULL, 0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(SDL_PLATFORM_WINDOWS)
|
#if defined(SDL_PLATFORM_WINDOWS)
|
||||||
if (SDL_CPUCount <= 0) {
|
if (SDL_NumLogicalCPUCores <= 0) {
|
||||||
SYSTEM_INFO info;
|
SYSTEM_INFO info;
|
||||||
GetSystemInfo(&info);
|
GetSystemInfo(&info);
|
||||||
SDL_CPUCount = info.dwNumberOfProcessors;
|
SDL_NumLogicalCPUCores = info.dwNumberOfProcessors;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// There has to be at least 1, right? :)
|
// There has to be at least 1, right? :)
|
||||||
if (SDL_CPUCount <= 0) {
|
if (SDL_NumLogicalCPUCores <= 0) {
|
||||||
SDL_CPUCount = 1;
|
SDL_NumLogicalCPUCores = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return SDL_CPUCount;
|
return SDL_NumLogicalCPUCores;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __e2k__
|
#ifdef __e2k__
|
||||||
|
|
|
@ -239,7 +239,7 @@ SDL3_0.0.0 {
|
||||||
SDL_GetBasePath;
|
SDL_GetBasePath;
|
||||||
SDL_GetBooleanProperty;
|
SDL_GetBooleanProperty;
|
||||||
SDL_GetCPUCacheLineSize;
|
SDL_GetCPUCacheLineSize;
|
||||||
SDL_GetCPUCount;
|
SDL_GetNumLogicalCPUCores;
|
||||||
SDL_GetCameraDriver;
|
SDL_GetCameraDriver;
|
||||||
SDL_GetCameraFormat;
|
SDL_GetCameraFormat;
|
||||||
SDL_GetCameraID;
|
SDL_GetCameraID;
|
||||||
|
|
|
@ -264,7 +264,7 @@
|
||||||
#define SDL_GetBasePath SDL_GetBasePath_REAL
|
#define SDL_GetBasePath SDL_GetBasePath_REAL
|
||||||
#define SDL_GetBooleanProperty SDL_GetBooleanProperty_REAL
|
#define SDL_GetBooleanProperty SDL_GetBooleanProperty_REAL
|
||||||
#define SDL_GetCPUCacheLineSize SDL_GetCPUCacheLineSize_REAL
|
#define SDL_GetCPUCacheLineSize SDL_GetCPUCacheLineSize_REAL
|
||||||
#define SDL_GetCPUCount SDL_GetCPUCount_REAL
|
#define SDL_GetNumLogicalCPUCores SDL_GetNumLogicalCPUCores_REAL
|
||||||
#define SDL_GetCameraDriver SDL_GetCameraDriver_REAL
|
#define SDL_GetCameraDriver SDL_GetCameraDriver_REAL
|
||||||
#define SDL_GetCameraFormat SDL_GetCameraFormat_REAL
|
#define SDL_GetCameraFormat SDL_GetCameraFormat_REAL
|
||||||
#define SDL_GetCameraID SDL_GetCameraID_REAL
|
#define SDL_GetCameraID SDL_GetCameraID_REAL
|
||||||
|
|
|
@ -284,7 +284,7 @@ SDL_DYNAPI_PROC(int,SDL_GetAudioStreamQueued,(SDL_AudioStream *a),(a),return)
|
||||||
SDL_DYNAPI_PROC(const char*,SDL_GetBasePath,(void),(),return)
|
SDL_DYNAPI_PROC(const char*,SDL_GetBasePath,(void),(),return)
|
||||||
SDL_DYNAPI_PROC(SDL_bool,SDL_GetBooleanProperty,(SDL_PropertiesID a, const char *b, SDL_bool c),(a,b,c),return)
|
SDL_DYNAPI_PROC(SDL_bool,SDL_GetBooleanProperty,(SDL_PropertiesID a, const char *b, SDL_bool c),(a,b,c),return)
|
||||||
SDL_DYNAPI_PROC(int,SDL_GetCPUCacheLineSize,(void),(),return)
|
SDL_DYNAPI_PROC(int,SDL_GetCPUCacheLineSize,(void),(),return)
|
||||||
SDL_DYNAPI_PROC(int,SDL_GetCPUCount,(void),(),return)
|
SDL_DYNAPI_PROC(int,SDL_GetNumLogicalCPUCores,(void),(),return)
|
||||||
SDL_DYNAPI_PROC(const char*,SDL_GetCameraDriver,(int a),(a),return)
|
SDL_DYNAPI_PROC(const char*,SDL_GetCameraDriver,(int a),(a),return)
|
||||||
SDL_DYNAPI_PROC(SDL_bool,SDL_GetCameraFormat,(SDL_Camera *a, SDL_CameraSpec *b),(a,b),return)
|
SDL_DYNAPI_PROC(SDL_bool,SDL_GetCameraFormat,(SDL_Camera *a, SDL_CameraSpec *b),(a,b),return)
|
||||||
SDL_DYNAPI_PROC(SDL_CameraID,SDL_GetCameraID,(SDL_Camera *a),(a),return)
|
SDL_DYNAPI_PROC(SDL_CameraID,SDL_GetCameraID,(SDL_Camera *a),(a),return)
|
||||||
|
|
|
@ -120,7 +120,7 @@ static int SDLCALL platform_testEndianessAndSwap(void *arg)
|
||||||
/**
|
/**
|
||||||
* Tests SDL_GetXYZ() functions
|
* Tests SDL_GetXYZ() functions
|
||||||
* \sa SDL_GetPlatform
|
* \sa SDL_GetPlatform
|
||||||
* \sa SDL_GetCPUCount
|
* \sa SDL_GetNumLogicalCPUCores
|
||||||
* \sa SDL_GetRevision
|
* \sa SDL_GetRevision
|
||||||
* \sa SDL_GetCPUCacheLineSize
|
* \sa SDL_GetCPUCacheLineSize
|
||||||
*/
|
*/
|
||||||
|
@ -142,10 +142,10 @@ static int SDLCALL platform_testGetFunctions(void *arg)
|
||||||
(int)len);
|
(int)len);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = SDL_GetCPUCount();
|
ret = SDL_GetNumLogicalCPUCores();
|
||||||
SDLTest_AssertPass("SDL_GetCPUCount()");
|
SDLTest_AssertPass("SDL_GetNumLogicalCPUCores()");
|
||||||
SDLTest_AssertCheck(ret > 0,
|
SDLTest_AssertCheck(ret > 0,
|
||||||
"SDL_GetCPUCount(): expected count > 0, was: %i",
|
"SDL_GetNumLogicalCPUCores(): expected count > 0, was: %i",
|
||||||
ret);
|
ret);
|
||||||
|
|
||||||
ret = SDL_GetCPUCacheLineSize();
|
ret = SDL_GetCPUCacheLineSize();
|
||||||
|
|
|
@ -476,7 +476,7 @@ static AVCodecContext *OpenVideoStream(AVFormatContext *ic, int stream, const AV
|
||||||
context->strict_std_compliance = -2;
|
context->strict_std_compliance = -2;
|
||||||
|
|
||||||
/* Enable threaded decoding, VVC decode is slow */
|
/* Enable threaded decoding, VVC decode is slow */
|
||||||
context->thread_count = SDL_GetCPUCount();
|
context->thread_count = SDL_GetNumLogicalCPUCores();
|
||||||
context->thread_type = (FF_THREAD_FRAME | FF_THREAD_SLICE);
|
context->thread_type = (FF_THREAD_FRAME | FF_THREAD_SLICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -389,7 +389,7 @@ static int Test64Bit(SDL_bool verbose)
|
||||||
static int TestCPUInfo(SDL_bool verbose)
|
static int TestCPUInfo(SDL_bool verbose)
|
||||||
{
|
{
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
SDL_Log("CPU count: %d\n", SDL_GetCPUCount());
|
SDL_Log("Number of logical CPU cores: %d\n", SDL_GetNumLogicalCPUCores());
|
||||||
SDL_Log("CPU cache line size: %d\n", SDL_GetCPUCacheLineSize());
|
SDL_Log("CPU cache line size: %d\n", SDL_GetCPUCacheLineSize());
|
||||||
SDL_Log("AltiVec %s\n", SDL_HasAltiVec() ? "detected" : "not detected");
|
SDL_Log("AltiVec %s\n", SDL_HasAltiVec() ? "detected" : "not detected");
|
||||||
SDL_Log("MMX %s\n", SDL_HasMMX() ? "detected" : "not detected");
|
SDL_Log("MMX %s\n", SDL_HasMMX() ? "detected" : "not detected");
|
||||||
|
|
Loading…
Reference in New Issue