diff options
author | Simon Marlow <marlowsd@gmail.com> | 2013-01-23 09:17:11 +0000 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2013-01-23 09:33:14 +0000 |
commit | 94e6d7db907c7f08d3c841c477678387f02c566d (patch) | |
tree | 564f8e2848decf2e3d99ea5f5b940782c12607ee | |
parent | c0d723ec700a4211fb9ab4e8585dbc08a816611d (diff) | |
download | haskell-94e6d7db907c7f08d3c841c477678387f02c566d.tar.gz |
Removes the assumption that CLK_TCK is a constant (#7519)
(which is not true on QNXNTO).
Submitted by: Stephen Paul Weber <singpolyma@singpolyma.net>
-rw-r--r-- | libraries/base/System/CPUTime.hsc | 24 | ||||
-rw-r--r-- | libraries/base/base.cabal | 1 | ||||
-rw-r--r-- | libraries/base/cbits/sysconf.c | 19 |
3 files changed, 23 insertions, 21 deletions
diff --git a/libraries/base/System/CPUTime.hsc b/libraries/base/System/CPUTime.hsc index 8934a7e6f6..b74cc25884 100644 --- a/libraries/base/System/CPUTime.hsc +++ b/libraries/base/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/libraries/base/base.cabal b/libraries/base/base.cabal index 05cbb7633d..c30be21b3b 100644 --- a/libraries/base/base.cabal +++ b/libraries/base/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/libraries/base/cbits/sysconf.c b/libraries/base/cbits/sysconf.c new file mode 100644 index 0000000000..bbf785326a --- /dev/null +++ b/libraries/base/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 +} |