Added support for querying the number of CPUs available on Linux. This also happens to work on Mac OS X.
authorSam Lantinga <slouken@libsdl.org>
Thu, 17 Dec 2009 03:04:04 +0000
changeset 3586b6758aee0dd4
parent 3585 f8816ffa210b
child 3587 2080e8d75ac6
Added support for querying the number of CPUs available on Linux. This also happens to work on Mac OS X.
configure.in
include/SDL_config.h.in
include/SDL_config_iphoneos.h
include/SDL_config_macosx.h
src/cpuinfo/SDL_cpuinfo.c
     1.1 --- a/configure.in	Wed Dec 16 19:50:51 2009 +0000
     1.2 +++ b/configure.in	Thu Dec 17 03:04:04 2009 +0000
     1.3 @@ -207,7 +207,7 @@
     1.4          AC_DEFINE(HAVE_MPROTECT)
     1.5          ]),
     1.6      )
     1.7 -    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)
     1.8 +    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)
     1.9  
    1.10      AC_CHECK_LIB(m, pow, [LIBS="$LIBS -lm"; EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lm"])
    1.11      AC_CHECK_FUNCS(ceil copysign cos cosf fabs floor log pow scalbn sin sinf sqrt)
     2.1 --- a/include/SDL_config.h.in	Wed Dec 16 19:50:51 2009 +0000
     2.2 +++ b/include/SDL_config.h.in	Thu Dec 17 03:04:04 2009 +0000
     2.3 @@ -151,6 +151,7 @@
     2.4  #undef HAVE_SIGACTION
     2.5  #undef HAVE_SETJMP
     2.6  #undef HAVE_NANOSLEEP
     2.7 +#undef HAVE_SYSCONF
     2.8  #undef HAVE_SYSCTLBYNAME
     2.9  #undef HAVE_CLOCK_GETTIME
    2.10  #undef HAVE_GETPAGESIZE
     3.1 --- a/include/SDL_config_iphoneos.h	Wed Dec 16 19:50:51 2009 +0000
     3.2 +++ b/include/SDL_config_iphoneos.h	Thu Dec 17 03:04:04 2009 +0000
     3.3 @@ -108,6 +108,7 @@
     3.4  #define HAVE_SIGACTION	1
     3.5  #define HAVE_SETJMP	1
     3.6  #define HAVE_NANOSLEEP	1
     3.7 +#define HAVE_SYSCONF	1
     3.8  #define HAVE_SYSCTLBYNAME 1
     3.9  
    3.10  /* enable iPhone version of Core Audio driver */
     4.1 --- a/include/SDL_config_macosx.h	Wed Dec 16 19:50:51 2009 +0000
     4.2 +++ b/include/SDL_config_macosx.h	Thu Dec 17 03:04:04 2009 +0000
     4.3 @@ -106,6 +106,7 @@
     4.4  #define HAVE_SIGACTION	1
     4.5  #define HAVE_SETJMP	1
     4.6  #define HAVE_NANOSLEEP	1
     4.7 +#define HAVE_SYSCONF	1
     4.8  #define HAVE_SYSCTLBYNAME 1
     4.9  
    4.10  /* Enable various audio drivers */
     5.1 --- a/src/cpuinfo/SDL_cpuinfo.c	Wed Dec 16 19:50:51 2009 +0000
     5.2 +++ b/src/cpuinfo/SDL_cpuinfo.c	Thu Dec 17 03:04:04 2009 +0000
     5.3 @@ -25,6 +25,9 @@
     5.4  
     5.5  #include "SDL_cpuinfo.h"
     5.6  
     5.7 +#ifdef HAVE_SYSCONF
     5.8 +#include <unistd.h>
     5.9 +#endif
    5.10  #ifdef HAVE_SYSCTLBYNAME
    5.11  #include <sys/types.h>
    5.12  #include <sys/sysctl.h>
    5.13 @@ -297,21 +300,26 @@
    5.14  SDL_GetCPUCount()
    5.15  {
    5.16      if (!SDL_CPUCount) {
    5.17 +#ifdef HAVE_SYSCONF
    5.18 +        if (SDL_CPUCount <= 0) {
    5.19 +            SDL_CPUCount = (int)sysconf(_SC_NPROCESSORS_ONLN);
    5.20 +        }
    5.21 +#endif
    5.22  #ifdef HAVE_SYSCTLBYNAME
    5.23 -        {
    5.24 +        if (SDL_CPUCount <= 0) {
    5.25              size_t size = sizeof(SDL_CPUCount);
    5.26              sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
    5.27          }
    5.28  #endif
    5.29  #ifdef __WIN32__
    5.30 -        {
    5.31 +        if (SDL_CPUCount <= 0) {
    5.32              SYSTEM_INFO info;
    5.33              GetSystemInfo(&info);
    5.34              SDL_CPUCount = info.dwNumberOfProcessors;
    5.35          }
    5.36  #endif
    5.37          /* There has to be at least 1, right? :) */
    5.38 -        if (!SDL_CPUCount) {
    5.39 +        if (SDL_CPUCount <= 0) {
    5.40              SDL_CPUCount = 1;
    5.41          }
    5.42      }