[commit: base] master: Removes the assumption that CLK_TCK is a constant (#7519) (3b51b74)
Simon Marlow
marlowsd at gmail.com
Wed Jan 23 10:55:26 CET 2013
Repository : ssh://darcs.haskell.org//srv/darcs/packages/base
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/3b51b741f45d4d85e79b2128d00479ce230f72f2
>---------------------------------------------------------------
commit 3b51b741f45d4d85e79b2128d00479ce230f72f2
Author: Simon Marlow <marlowsd at gmail.com>
Date: Wed Jan 23 09:17:11 2013 +0000
Removes the assumption that CLK_TCK is a constant (#7519)
(which is not true on QNXNTO).
Submitted by: Stephen Paul Weber <singpolyma at singpolyma.net>
>---------------------------------------------------------------
System/CPUTime.hsc | 24 +++---------------------
base.cabal | 1 +
cbits/sysconf.c | 19 +++++++++++++++++++
3 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/System/CPUTime.hsc b/System/CPUTime.hsc
index 8934a7e..b74cc25 100644
--- a/System/CPUTime.hsc
+++ b/System/CPUTime.hsc
@@ -39,14 +39,6 @@ import CPUTime ( getCPUTime, cpuTimePrecision )
#ifdef __GLASGOW_HASKELL__
import Foreign.Safe
import Foreign.C
-#if !defined(CLK_TCK)
-import System.IO.Unsafe (unsafePerformIO)
-#endif
-
--- For _SC_CLK_TCK
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-- For struct rusage
#if !defined(mingw32_HOST_OS) && !defined(irix_HOST_OS)
@@ -60,11 +52,6 @@ import System.IO.Unsafe (unsafePerformIO)
#include <windows.h>
#endif
--- for CLK_TCK
-#if HAVE_TIME_H
-#include <time.h>
-#endif
-
-- for struct tms
#if HAVE_SYS_TIMES_H
#include <sys/times.h>
@@ -185,13 +172,8 @@ cpuTimePrecision = round ((1000000000000::Integer) % fromIntegral (clockTicks))
#endif
#ifdef __GLASGOW_HASKELL__
+foreign import ccall unsafe clk_tck :: CLong
+
clockTicks :: Int
-clockTicks =
-#if defined(CLK_TCK)
- (#const CLK_TCK)
-#else
- unsafePerformIO (sysconf (#const _SC_CLK_TCK) >>= return . fromIntegral)
-foreign import ccall unsafe sysconf :: CInt -> IO CLong
-#endif
+clockTicks = fromIntegral clk_tck
#endif /* __GLASGOW_HASKELL__ */
-
diff --git a/base.cabal b/base.cabal
index 05cbb76..c30be21 100644
--- a/base.cabal
+++ b/base.cabal
@@ -225,6 +225,7 @@ Library {
cbits/inputReady.c
cbits/primFloat.c
cbits/md5.c
+ cbits/sysconf.c
include-dirs: include
includes: HsBase.h
install-includes: HsBase.h HsBaseConfig.h EventConfig.h WCsubst.h consUtils.h Typeable.h
diff --git a/cbits/sysconf.c b/cbits/sysconf.c
new file mode 100644
index 0000000..bbf7853
--- /dev/null
+++ b/cbits/sysconf.c
@@ -0,0 +1,19 @@
+#include "HsBaseConfig.h"
+
+/* For _SC_CLK_TCK */
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+/* for CLK_TCK */
+#if HAVE_TIME_H
+#include <time.h>
+#endif
+
+long clk_tck(void) {
+#if defined(CLK_TCK)
+ return (CLK_TCK);
+#else
+ return sysconf(_SC_CLK_TCK);
+#endif
+}
More information about the ghc-commits
mailing list