summaryrefslogtreecommitdiff
path: root/rts
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2009-03-17 09:33:09 +0000
committerSimon Marlow <marlowsd@gmail.com>2009-03-17 09:33:09 +0000
commit0ee0be109fd00ec629f7a2ad6a597885a0c9d5b4 (patch)
treef34e7ebeb8ff40299745b169c4ca4b7bed4b2c54 /rts
parent8844513929ccd58854227ddb6275095a1f1742ad (diff)
downloadhaskell-0ee0be109fd00ec629f7a2ad6a597885a0c9d5b4.tar.gz
Add getNumberOfProcessors(), FIX MacOS X build problem (hopefully)
Somebody needs to implement getNumberOfProcessors() for MacOS X, currently it will return 1.
Diffstat (limited to 'rts')
-rw-r--r--rts/RtsFlags.c12
-rw-r--r--rts/posix/OSThreads.c18
-rw-r--r--rts/win32/OSThreads.c14
3 files changed, 33 insertions, 11 deletions
diff --git a/rts/RtsFlags.c b/rts/RtsFlags.c
index 2af67e7dc2..b3b95b32d9 100644
--- a/rts/RtsFlags.c
+++ b/rts/RtsFlags.c
@@ -1152,17 +1152,7 @@ error = rtsTrue;
#if defined(PROFILING)
RtsFlags.ParFlags.nNodes = 1;
#else
-#if defined(mingw32_HOST_OS)
- {
- SYSTEM_INFO si;
- GetSystemInfo(&si);
- RtsFlags.ParFlags.nNodes = si.dwNumberOfProcessors;
- }
-#elif defined(HAVE_SYSCONF)
- RtsFlags.ParFlags.nNodes = sysconf(_SC_NPROCESSORS_CONF);
-#else
- RtsFlags.ParFlags.nNodes = 1;
-#endif
+ RtsFlags.ParFlags.nNodes = getNumberOfProcessors();
#endif
} else {
RtsFlags.ParFlags.nNodes
diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c
index 6e01f82553..6eb2d2bc8e 100644
--- a/rts/posix/OSThreads.c
+++ b/rts/posix/OSThreads.c
@@ -179,6 +179,24 @@ forkOS_createThread ( HsStablePtr entry )
return result;
}
+nat
+getNumberOfProcessors (void)
+{
+ static nat nproc = 0;
+
+ 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);
+#else
+ nproc = 1;
+#endif
+ }
+
+ return nproc;
+}
+
#else /* !defined(THREADED_RTS) */
int
diff --git a/rts/win32/OSThreads.c b/rts/win32/OSThreads.c
index ed5c968cf1..929b8171e7 100644
--- a/rts/win32/OSThreads.c
+++ b/rts/win32/OSThreads.c
@@ -232,6 +232,20 @@ forkOS_createThread ( HsStablePtr entry )
(unsigned*)&pId) == 0);
}
+nat
+getNumberOfProcessors (void)
+{
+ static nat nproc = 0;
+
+ if (nproc == 0) {
+ SYSTEM_INFO si;
+ GetSystemInfo(&si);
+ nproc = si.dwNumberOfProcessors;
+ }
+
+ return nproc;
+}
+
#else /* !defined(THREADED_RTS) */
int