# HG changeset patch # User Sam Lantinga # Date 1261019044 0 # Node ID b6758aee0dd4d988805573808696f4dd33f1d666 # Parent f8816ffa210bbe01d156021010fda75447fbf7ca Added support for querying the number of CPUs available on Linux. This also happens to work on Mac OS X. diff -r f8816ffa210b -r b6758aee0dd4 configure.in --- a/configure.in Wed Dec 16 19:50:51 2009 +0000 +++ b/configure.in Thu Dec 17 03:04:04 2009 +0000 @@ -207,7 +207,7 @@ AC_DEFINE(HAVE_MPROTECT) ]), ) - AC_CHECK_FUNCS(malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp sscanf snprintf vsnprintf sigaction setjmp nanosleep sysctlbyname) + AC_CHECK_FUNCS(malloc calloc realloc free getenv setenv putenv unsetenv qsort abs bcopy memset memcpy memmove strlen strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp _strnicmp strncasecmp sscanf snprintf vsnprintf sigaction setjmp nanosleep sysconf sysctlbyname) AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"]) AC_CHECK_FUNCS(ceil copysign cos cosf fabs floor log pow scalbn sin sinf sqrt) diff -r f8816ffa210b -r b6758aee0dd4 include/SDL_config.h.in --- a/include/SDL_config.h.in Wed Dec 16 19:50:51 2009 +0000 +++ b/include/SDL_config.h.in Thu Dec 17 03:04:04 2009 +0000 @@ -151,6 +151,7 @@ #undef HAVE_SIGACTION #undef HAVE_SETJMP #undef HAVE_NANOSLEEP +#undef HAVE_SYSCONF #undef HAVE_SYSCTLBYNAME #undef HAVE_CLOCK_GETTIME #undef HAVE_GETPAGESIZE diff -r f8816ffa210b -r b6758aee0dd4 include/SDL_config_iphoneos.h --- a/include/SDL_config_iphoneos.h Wed Dec 16 19:50:51 2009 +0000 +++ b/include/SDL_config_iphoneos.h Thu Dec 17 03:04:04 2009 +0000 @@ -108,6 +108,7 @@ #define HAVE_SIGACTION 1 #define HAVE_SETJMP 1 #define HAVE_NANOSLEEP 1 +#define HAVE_SYSCONF 1 #define HAVE_SYSCTLBYNAME 1 /* enable iPhone version of Core Audio driver */ diff -r f8816ffa210b -r b6758aee0dd4 include/SDL_config_macosx.h --- a/include/SDL_config_macosx.h Wed Dec 16 19:50:51 2009 +0000 +++ b/include/SDL_config_macosx.h Thu Dec 17 03:04:04 2009 +0000 @@ -106,6 +106,7 @@ #define HAVE_SIGACTION 1 #define HAVE_SETJMP 1 #define HAVE_NANOSLEEP 1 +#define HAVE_SYSCONF 1 #define HAVE_SYSCTLBYNAME 1 /* Enable various audio drivers */ diff -r f8816ffa210b -r b6758aee0dd4 src/cpuinfo/SDL_cpuinfo.c --- 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 +#endif #ifdef HAVE_SYSCTLBYNAME #include #include @@ -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; } }