Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Added support for querying the number of CPUs available on Linux. Thi…

…s also happens to work on Mac OS X.
  • Loading branch information
slouken committed Dec 17, 2009
1 parent f0bc186 commit a6bfcec0be148c4b8979a7f7545d32df6134b35e
Showing with 15 additions and 4 deletions.
  1. +1 −1 configure.in
  2. +1 −0 include/SDL_config.h.in
  3. +1 −0 include/SDL_config_iphoneos.h
  4. +1 −0 include/SDL_config_macosx.h
  5. +11 −3 src/cpuinfo/SDL_cpuinfo.c
@@ -207,7 +207,7 @@ if test x$enable_libc = xyes; then
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)
@@ -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
@@ -108,6 +108,7 @@ typedef unsigned long uintptr_t;
#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 */
@@ -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 */
@@ -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 @@ int
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;
}
}

0 comments on commit a6bfcec

Please sign in to comment.