>From 3690bb13bf0879c9112d47fd2195b9f2683e1b07 Mon Sep 17 00:00:00 2001
From: Stephen Paul Weber <singpolyma@singpolyma.net>
Date: Tue, 11 Dec 2012 19:10:38 -0500
Subject: [PATCH] Move CLK_TCK check out to a C file
This removes the assumption that CLK_TCK is a constant (which is not
true on QNXNTO).
---
System/CPUTime.hsc | 21 +++------------------
base.cabal | 1 +
cbits/sysconf.c | 19 +++++++++++++++++++
3 files changed, 23 insertions(+), 18 deletions(-)
create mode 100644 cbits/sysconf.c
diff --git a/System/CPUTime.hsc b/System/CPUTime.hsc
index 8934a7e..4d988a7 100644
|
a
|
b
|
|
| 43 | 43 | import System.IO.Unsafe (unsafePerformIO) |
| 44 | 44 | #endif |
| 45 | 45 | |
| 46 | | -- For _SC_CLK_TCK |
| 47 | | #if HAVE_UNISTD_H |
| 48 | | #include <unistd.h> |
| 49 | | #endif |
| 50 | | |
| 51 | 46 | -- For struct rusage |
| 52 | 47 | #if !defined(mingw32_HOST_OS) && !defined(irix_HOST_OS) |
| 53 | 48 | # if HAVE_SYS_RESOURCE_H |
| … |
… |
|
| 60 | 55 | #include <windows.h> |
| 61 | 56 | #endif |
| 62 | 57 | |
| 63 | | -- for CLK_TCK |
| 64 | | #if HAVE_TIME_H |
| 65 | | #include <time.h> |
| 66 | | #endif |
| 67 | | |
| 68 | 58 | -- for struct tms |
| 69 | 59 | #if HAVE_SYS_TIMES_H |
| 70 | 60 | #include <sys/times.h> |
| … |
… |
|
| 185 | 175 | #endif |
| 186 | 176 | |
| 187 | 177 | #ifdef __GLASGOW_HASKELL__ |
| | 178 | foreign import ccall unsafe clk_tck :: CLong |
| | 179 | |
| 188 | 180 | clockTicks :: Int |
| 189 | | clockTicks = |
| 190 | | #if defined(CLK_TCK) |
| 191 | | (#const CLK_TCK) |
| 192 | | #else |
| 193 | | unsafePerformIO (sysconf (#const _SC_CLK_TCK) >>= return . fromIntegral) |
| 194 | | foreign import ccall unsafe sysconf :: CInt -> IO CLong |
| 195 | | #endif |
| | 181 | clockTicks = fromIntegral clk_tck |
| 196 | 182 | #endif /* __GLASGOW_HASKELL__ */ |
| 197 | | |
diff --git a/base.cabal b/base.cabal
index 28ccdd6..05ca157 100644
|
a
|
b
|
|
| 223 | 223 | cbits/inputReady.c |
| 224 | 224 | cbits/primFloat.c |
| 225 | 225 | cbits/md5.c |
| | 226 | cbits/sysconf.c |
| 226 | 227 | include-dirs: include |
| 227 | 228 | includes: HsBase.h |
| 228 | 229 | 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
|
a
|
b
|
|
| | 1 | #include "HsBaseConfig.h" |
| | 2 | |
| | 3 | /* For _SC_CLK_TCK */ |
| | 4 | #if HAVE_UNISTD_H |
| | 5 | #include <unistd.h> |
| | 6 | #endif |
| | 7 | |
| | 8 | /* for CLK_TCK */ |
| | 9 | #if HAVE_TIME_H |
| | 10 | #include <time.h> |
| | 11 | #endif |
| | 12 | |
| | 13 | long clk_tck(void) { |
| | 14 | #if defined(CLK_TCK) |
| | 15 | return (CLK_TCK); |
| | 16 | #else |
| | 17 | return sysconf(_SC_CLK_TCK); |
| | 18 | #endif |
| | 19 | } |