diff options
author | Austin Seipp <mad.one@gmail.com> | 2009-03-18 02:31:27 +0000 |
---|---|---|
committer | Austin Seipp <mad.one@gmail.com> | 2009-03-18 02:31:27 +0000 |
commit | 97c4b27494addf0231724ca8339e818511256dcf (patch) | |
tree | d1d59309828e5e307404de12256b588c0bb234cf /rts/posix | |
parent | a664d7385d97a2e4743d448aa3dddd911190f472 (diff) | |
download | haskell-97c4b27494addf0231724ca8339e818511256dcf.tar.gz |
FIX getNumberOfProcessors() on MacOS X
This checks if darwin_HOST_OS is defined and, if so, we call
sysctlbyname() on the "hw.ncpu" property to get the processor count.
Diffstat (limited to 'rts/posix')
-rw-r--r-- | rts/posix/OSThreads.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c index 84b111fcb7..d4d4382134 100644 --- a/rts/posix/OSThreads.c +++ b/rts/posix/OSThreads.c @@ -23,6 +23,11 @@ #include <string.h> #endif +#if defined(darwin_HOST_OS) +#include <sys/types.h> +#include <sys/sysctl.h> +#endif + #if !defined(HAVE_PTHREAD_H) #error pthreads.h is required for the threaded RTS on Posix platforms #endif @@ -196,12 +201,16 @@ nat getNumberOfProcessors (void) { static nat nproc = 0; + size_t size = sizeof(nat); if (nproc == 0) { #if defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN) nproc = sysconf(_SC_NPROCESSORS_ONLN); #elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_CONF) nproc = sysconf(_SC_NPROCESSORS_CONF); +#elif defined(darwin_HOST_OS) + if(0 != sysctlbyname("hw.ncpu",&nproc,&size,NULL,0)) + nproc = 1; #else nproc = 1; #endif |