src/cpuinfo/SDL_cpuinfo.c
changeset 3586 b6758aee0dd4
parent 3584 41d01d70659c
child 3587 2080e8d75ac6
     1.1 --- a/src/cpuinfo/SDL_cpuinfo.c	Wed Dec 16 19:50:51 2009 +0000
     1.2 +++ b/src/cpuinfo/SDL_cpuinfo.c	Thu Dec 17 03:04:04 2009 +0000
     1.3 @@ -25,6 +25,9 @@
     1.4  
     1.5  #include "SDL_cpuinfo.h"
     1.6  
     1.7 +#ifdef HAVE_SYSCONF
     1.8 +#include <unistd.h>
     1.9 +#endif
    1.10  #ifdef HAVE_SYSCTLBYNAME
    1.11  #include <sys/types.h>
    1.12  #include <sys/sysctl.h>
    1.13 @@ -297,21 +300,26 @@
    1.14  SDL_GetCPUCount()
    1.15  {
    1.16      if (!SDL_CPUCount) {
    1.17 +#ifdef HAVE_SYSCONF
    1.18 +        if (SDL_CPUCount <= 0) {
    1.19 +            SDL_CPUCount = (int)sysconf(_SC_NPROCESSORS_ONLN);
    1.20 +        }
    1.21 +#endif
    1.22  #ifdef HAVE_SYSCTLBYNAME
    1.23 -        {
    1.24 +        if (SDL_CPUCount <= 0) {
    1.25              size_t size = sizeof(SDL_CPUCount);
    1.26              sysctlbyname("hw.ncpu", &SDL_CPUCount, &size, NULL, 0);
    1.27          }
    1.28  #endif
    1.29  #ifdef __WIN32__
    1.30 -        {
    1.31 +        if (SDL_CPUCount <= 0) {
    1.32              SYSTEM_INFO info;
    1.33              GetSystemInfo(&info);
    1.34              SDL_CPUCount = info.dwNumberOfProcessors;
    1.35          }
    1.36  #endif
    1.37          /* There has to be at least 1, right? :) */
    1.38 -        if (!SDL_CPUCount) {
    1.39 +        if (SDL_CPUCount <= 0) {
    1.40              SDL_CPUCount = 1;
    1.41          }
    1.42      }