clock 0.8 → 0.8.2
raw patch · 3 files changed
+43/−86 lines, 3 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- System/Clock.hsc +31/−47
- cbits/hs_clock_darwin.c +0/−29
- clock.cabal +12/−10
System/Clock.hsc view
@@ -23,6 +23,7 @@ import Data.Int import Data.Word import Data.Typeable (Typeable)+import Foreign.C import Foreign.Ptr import Foreign.Storable import Foreign.Marshal.Alloc@@ -30,12 +31,8 @@ #if defined(_WIN32) # include "hs_clock_win32.c"-#elif defined(__MACH__) && defined(__APPLE__)-# include "hs_clock_darwin.c" #else # include <time.h>--- Due to missing define in FreeBSD 9.0 and 9.1--- (http://lists.freebsd.org/pipermail/freebsd-stable/2013-September/075095.html). # ifndef CLOCK_PROCESS_CPUTIME_ID # define CLOCK_PROCESS_CPUTIME_ID 15 # endif@@ -47,8 +44,7 @@ -- | Clock types. A clock may be system-wide (that is, visible to all processes) -- or per-process (measuring time that is meaningful only within a process).--- All implementations shall support CLOCK_REALTIME. (The only suspend-aware--- monotonic is CLOCK_BOOTTIME on Linux.)+-- All implementations shall support 'Realtime'. data Clock -- | The identifier for the system-wide monotonic clock, which is defined as@@ -62,11 +58,14 @@ -- monotonic clock is meaningless (because its origin is arbitrary), and -- thus there is no need to set it. Furthermore, realtime applications can -- rely on the fact that the value of this clock is never set.+ -- (Identical to 'Boottime' since Linux 4.17, see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d6ed449afdb38f89a7b38ec50e367559e1b8f71f)+ -- @CLOCK_MONOTONIC@ (macOS - @SYSTEM_CLOCK@) = Monotonic -- | The identifier of the system-wide clock measuring real time. For this -- clock, the value returned by 'getTime' represents the amount of time (in -- seconds and nanoseconds) since the Epoch.+ -- @CLOCK_REALTIME@ (macOS - @CALENDAR_CLOCK@, Windows - @GetSystemTimeAsFileTime@) | Realtime -- | The identifier of the CPU-time clock associated with the calling@@ -80,72 +79,66 @@ | ThreadCPUTime #if defined (CLOCK_MONOTONIC_RAW)- -- | (since Linux 2.6.28; Linux-specific)- -- Similar to CLOCK_MONOTONIC, but provides access to a+ -- | (since Linux 2.6.28, macOS 10.12)+ -- Similar to 'Monotonic', but provides access to a -- raw hardware-based time that is not subject to NTP -- adjustments or the incremental adjustments performed by -- adjtime(3).+ -- @CLOCK_MONOTONIC_RAW@ (Windows - @QueryPerformanceCounter@, @QueryPerformanceFrequency@) | MonotonicRaw #endif #if defined (CLOCK_BOOTTIME) -- | (since Linux 2.6.39; Linux-specific)- -- Identical to CLOCK_MONOTONIC, except it also includes- -- any time that the system is suspended. This allows+ -- Identical to `Monotonic`, except it also includes+ -- any time that the system is suspended. This allows -- applications to get a suspend-aware monotonic clock- -- without having to deal with the complications of- -- CLOCK_REALTIME, which may have discontinuities if the- -- time is changed using settimeofday(2).+ -- without having to deal with the complications of 'Realtime',+ -- which may have discontinuities if the time is changed+ -- using settimeofday(2).+ -- (since Linux 4.17; identical to 'Monotonic')+ -- @CLOCK_BOOTTIME@ | Boottime #endif #if defined (CLOCK_MONOTONIC_COARSE) -- | (since Linux 2.6.32; Linux-specific)- -- A faster but less precise version of CLOCK_MONOTONIC.+ -- A faster but less precise version of 'Monotonic'. -- Use when you need very fast, but not fine-grained timestamps.+ -- @CLOCK_MONOTONIC_COARSE@ | MonotonicCoarse #endif #if defined (CLOCK_REALTIME_COARSE) -- | (since Linux 2.6.32; Linux-specific)- -- A faster but less precise version of CLOCK_REALTIME.+ -- A faster but less precise version of 'Realtime'. -- Use when you need very fast, but not fine-grained timestamps.+ -- @CLOCK_REALTIME_COARSE@ | RealtimeCoarse #endif deriving (Eq, Enum, Generic, Read, Show, Typeable) #if defined(_WIN32)-foreign import ccall hs_clock_win32_gettime_monotonic :: Ptr TimeSpec -> IO ()-foreign import ccall hs_clock_win32_gettime_realtime :: Ptr TimeSpec -> IO ()-foreign import ccall hs_clock_win32_gettime_processtime :: Ptr TimeSpec -> IO ()-foreign import ccall hs_clock_win32_gettime_threadtime :: Ptr TimeSpec -> IO ()-foreign import ccall hs_clock_win32_getres_monotonic :: Ptr TimeSpec -> IO ()-foreign import ccall hs_clock_win32_getres_realtime :: Ptr TimeSpec -> IO ()-foreign import ccall hs_clock_win32_getres_processtime :: Ptr TimeSpec -> IO ()-foreign import ccall hs_clock_win32_getres_threadtime :: Ptr TimeSpec -> IO ()-#elif defined(__MACH__) && defined(__APPLE__)-foreign import ccall hs_clock_darwin_gettime :: #{type clock_id_t} -> Ptr TimeSpec -> IO ()-foreign import ccall hs_clock_darwin_getres :: #{type clock_id_t} -> Ptr TimeSpec -> IO ()+foreign import ccall unsafe hs_clock_win32_gettime_monotonic :: Ptr TimeSpec -> IO ()+foreign import ccall unsafe hs_clock_win32_gettime_realtime :: Ptr TimeSpec -> IO ()+foreign import ccall unsafe hs_clock_win32_gettime_processtime :: Ptr TimeSpec -> IO ()+foreign import ccall unsafe hs_clock_win32_gettime_threadtime :: Ptr TimeSpec -> IO ()+foreign import ccall unsafe hs_clock_win32_getres_monotonic :: Ptr TimeSpec -> IO ()+foreign import ccall unsafe hs_clock_win32_getres_realtime :: Ptr TimeSpec -> IO ()+foreign import ccall unsafe hs_clock_win32_getres_processtime :: Ptr TimeSpec -> IO ()+foreign import ccall unsafe hs_clock_win32_getres_threadtime :: Ptr TimeSpec -> IO () #else-foreign import ccall unsafe clock_gettime :: #{type clockid_t} -> Ptr TimeSpec -> IO ()-foreign import ccall unsafe clock_getres :: #{type clockid_t} -> Ptr TimeSpec -> IO ()+foreign import ccall unsafe clock_gettime :: #{type clockid_t} -> Ptr TimeSpec -> IO CInt+foreign import ccall unsafe clock_getres :: #{type clockid_t} -> Ptr TimeSpec -> IO CInt #endif #if !defined(_WIN32)-#if defined(__MACH__) && defined(__APPLE__)-clockToConst :: Clock -> #{type clock_id_t}-clockToConst Monotonic = #const SYSTEM_CLOCK-clockToConst Realtime = #const CALENDAR_CLOCK-clockToConst ProcessCPUTime = #const SYSTEM_CLOCK-clockToConst ThreadCPUTime = #const SYSTEM_CLOCK-#else clockToConst :: Clock -> #{type clockid_t} clockToConst Monotonic = #const CLOCK_MONOTONIC clockToConst Realtime = #const CLOCK_REALTIME clockToConst ProcessCPUTime = #const CLOCK_PROCESS_CPUTIME_ID clockToConst ThreadCPUTime = #const CLOCK_THREAD_CPUTIME_ID-#endif #if defined (CLOCK_MONOTONIC_RAW) clockToConst MonotonicRaw = #const CLOCK_MONOTONIC_RAW@@ -178,10 +171,8 @@ getTime Realtime = allocaAndPeek hs_clock_win32_gettime_realtime getTime ProcessCPUTime = allocaAndPeek hs_clock_win32_gettime_processtime getTime ThreadCPUTime = allocaAndPeek hs_clock_win32_gettime_threadtime-#elif defined(__MACH__) && defined(__APPLE__)-getTime clk = allocaAndPeek $! hs_clock_darwin_gettime $! clockToConst clk #else-getTime clk = allocaAndPeek $! clock_gettime $! clockToConst clk+getTime clk = allocaAndPeek $! throwErrnoIfMinus1_ "clock_gettime" . clock_gettime (clockToConst clk) #endif #if defined(_WIN32)@@ -189,10 +180,8 @@ getRes Realtime = allocaAndPeek hs_clock_win32_getres_realtime getRes ProcessCPUTime = allocaAndPeek hs_clock_win32_getres_processtime getRes ThreadCPUTime = allocaAndPeek hs_clock_win32_getres_threadtime-#elif defined(__MACH__) && defined(__APPLE__)-getRes clk = allocaAndPeek $! hs_clock_darwin_getres $! clockToConst clk #else-getRes clk = allocaAndPeek $! clock_getres $! clockToConst clk+getRes clk = allocaAndPeek $! throwErrnoIfMinus1_ "clock_getres" . clock_getres (clockToConst clk) #endif -- | TimeSpec structure@@ -245,11 +234,6 @@ ysi = toInteger ys xni = toInteger xn yni = toInteger yn--- let xsi = toInteger xs -- convert to arbitraty Integer type to avoid int overflow--- xni = toInteger xn--- ysi = toInteger ys--- yni = toInteger yn -- seconds -- nanoseconds--- in normalize $! TimeSpec (fromInteger $! xsi * ysi) (fromInteger $! (xni * yni + (xni * ysi + xsi * yni) * s2ns) `div` s2ns) negate (TimeSpec xs xn) = normalize $! TimeSpec (negate xs) (negate xn) abs (normalize -> TimeSpec xs xn) | xs == 0 = normalize $! TimeSpec 0 xn
− cbits/hs_clock_darwin.c
@@ -1,29 +0,0 @@-#ifdef __MACH__-#include <time.h>-#include <mach/clock.h>-#include <mach/mach.h>--void hs_clock_darwin_gettime(clock_id_t clock, struct timespec *ts)-{- // OS X does not have clock_gettime, use clock_get_time- // see http://stackoverflow.com/questions/11680461/monotonic-clock-on-osx- clock_serv_t cclock;- mach_timespec_t mts;- host_get_clock_service(mach_host_self(), clock, &cclock);- clock_get_time(cclock, &mts);- mach_port_deallocate(mach_task_self(), cclock);- ts->tv_sec = mts.tv_sec;- ts->tv_nsec = mts.tv_nsec;-}--void hs_clock_darwin_getres(clock_id_t clock, struct timespec *ts)-{- clock_serv_t cclock;- int nsecs;- mach_msg_type_number_t count;- host_get_clock_service(mach_host_self(), clock, &cclock);- clock_get_attributes(cclock, CLOCK_GET_TIME_RES, (clock_attr_t)&nsecs, &count);- mach_port_deallocate(mach_task_self(), cclock);-}--#endif /* __MACH__ */
clock.cabal view
@@ -1,5 +1,6 @@+cabal-version: >= 1.10 name: clock-version: 0.8+version: 0.8.2 stability: stable synopsis: High-resolution clock functions: monotonic, realtime, cputime. description: A package for convenient access to high-resolution clock and@@ -35,21 +36,23 @@ . Refreshment release in 2019-04 after numerous contributions. .+ Refactoring for Windows, Mac implementation consistence by Alexander Vershilov on 2021-01-16.+ . [Version Scheme] Major-@/R/@-ewrite . New-@/F/@-unctionality . @/I/@-mprovementAndBugFixes . @/P/@-ackagingOnly . * @PackagingOnly@ changes are made for quality assurance reasons. -copyright: Copyright © Cetin Sert 2009-2016, Eugene Kirpichov 2010, Finn Espen Gundersen 2013, Gerolf Seitz 2013, Mathieu Boespflug 2014 2015, Chris Done 2015, Dimitri Sabadie 2015, Christian Burger 2015, Mario Longobardi 2016+copyright: Copyright © Cetin Sert 2009-2016, Eugene Kirpichov 2010, Finn Espen Gundersen 2013, Gerolf Seitz 2013, Mathieu Boespflug 2014 2015, Chris Done 2015, Dimitri Sabadie 2015, Christian Burger 2015, Mario Longobardi 2016, Alexander Vershilov 2021. license: BSD3 license-file: LICENSE-author: Cetin Sert <cetin@corsis.tech>, Corsis Research-maintainer: Cetin Sert <cetin@corsis.tech>, Corsis Research+author: Cetin Sert <cetin@sert.works>, Corsis Research+maintainer: Cetin Sert <cetin@sert.works>, Corsis Research homepage: https://github.com/corsis/clock bug-reports: https://github.com/corsis/clock/issues category: System build-type: Simple-cabal-version: >= 1.8+tested-with: GHC==8.10.3, GHC==8.8.4, GHC==8.6.5 source-repository head@@ -63,17 +66,16 @@ library+ default-language: Haskell2010 if impl (ghc < 7.6) build-depends: base >= 4.4 && <= 5, ghc-prim build-depends: base >= 2 && <= 5 exposed-modules: System.Clock- extensions: DeriveGeneric+ default-extensions: DeriveGeneric DeriveDataTypeable ForeignFunctionInterface ScopedTypeVariables ViewPatterns- if os(darwin)- c-sources: cbits/hs_clock_darwin.c if os(windows) c-sources: cbits/hs_clock_win32.c include-dirs: cbits@@ -84,8 +86,7 @@ test-suite test--- default-language:--- Haskell2010+ default-language: Haskell2010 type: exitcode-stdio-1.0 hs-source-dirs:@@ -99,6 +100,7 @@ , clock benchmark benchmarks+ default-language: Haskell2010 type: exitcode-stdio-1.0 hs-source-dirs: