Mercurial > sdl-ios-xcode
diff src/cpuinfo/SDL_cpuinfo.c @ 3586:b6758aee0dd4
Added support for querying the number of CPUs available on Linux. This also happens to work on Mac OS X.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 17 Dec 2009 03:04:04 +0000 |
parents | 41d01d70659c |
children | 2080e8d75ac6 |
line wrap: on
line diff
--- a/src/cpuinfo/SDL_cpuinfo.c Wed Dec 16 19:50:51 2009 +0000 +++ b/src/cpuinfo/SDL_cpuinfo.c Thu Dec 17 03:04:04 2009 +0000 @@ -25,6 +25,9 @@ #include "SDL_cpuinfo.h" +#ifdef HAVE_SYSCONF +#include <unistd.h> +#endif #ifdef HAVE_SYSCTLBYNAME #include <sys/types.h> #include <sys/sysctl.h> @@ -297,21 +300,26 @@ SDL_GetCPUCount() { if (!SDL_CPUCount) { +#ifdef HAVE_SYSCONF + if (SDL_CPUCount <= 0) { + SDL_CPUCount = (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); } #endif #ifdef __WIN32__ - { + if (SDL_CPUCount <= 0) { SYSTEM_INFO info; GetSystemInfo(&info); SDL_CPUCount = info.dwNumberOfProcessors; } #endif /* There has to be at least 1, right? :) */ - if (!SDL_CPUCount) { + if (SDL_CPUCount <= 0) { SDL_CPUCount = 1; } }