Please the -Wall police by moving a variable declaration; really FIX getNumberOfProce...
[ghc-hetmet.git] / rts / posix / OSThreads.c
index 9bcd56f..324701d 100644 (file)
 #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
@@ -202,6 +207,10 @@ getNumberOfProcessors (void)
         nproc = sysconf(_SC_NPROCESSORS_ONLN);
 #elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_CONF)
         nproc = sysconf(_SC_NPROCESSORS_CONF);
+#elif defined(darwin_HOST_OS)
+        size_t size = sizeof(nat);
+        if(0 != sysctlbyname("hw.ncpu",&nproc,&size,NULL,0))
+            nproc = 1;
 #else
         nproc = 1;
 #endif
@@ -224,7 +233,7 @@ setThreadAffinity (nat n, nat m)
     nproc = getNumberOfProcessors();
     CPU_ZERO(&cs);
     for (i = n; i < nproc; i+=m) {
-        CPU_SET(n, &cs);
+        CPU_SET(i, &cs);
     }
     sched_setaffinity(0, sizeof(cpu_set_t), &cs);
 }