packages feed

clock 0.1 → 0.1.1

raw patch · 7 files changed

+75/−37 lines, 7 filesdep ~basePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base

API changes (from Hackage documentation)

Files

+ CHANGES view
@@ -0,0 +1,3 @@+CHANGES++  0.1.1: added rudimentary documentation
README view
@@ -1,5 +1,26 @@-dedicated to An Le Thi Thanh+Dedicated to An Le Thi Thanh  ---------------- -bindings to time.h: clock_gettime and clock_getres+DESCRIPTION++  low-level bindings to time.h: clock_gettime and clock_getres++----------------++CONSIDERATIONS++  → Move from System.CPUTime.Clock to either System.Posix.Clock+    or ask for suggestions from other people.++  → clock_getres has type 'Clock → IO TimeSpec' discuss changing+    to 'Clock → TimeSpec' with other haskell developers.+++----------------++KNOWN ISSUES++  → clock_settime not implemented.++  → namespace have not been confirmed final.
System/CPUTime/Clock.hs view
@@ -1,3 +1,4 @@+-- | From time.h, provides clockid_t, timespec, clock_gettime, clock_getres. module System.CPUTime.Clock (    Clock (Monotonic, Realtime, ProcessTime, ThreadTime),@@ -17,25 +18,36 @@ import Foreign.Marshal.Alloc (free) import Foreign.Marshal.Array --- Reader function-type ReaderFunc = Ptr Int → IO ()+-- | Clock types+data Clock = Monotonic   -- ^ Clock that cannot be set and represents monotonic time since some unspecified starting point. +           | Realtime    -- ^ System-wide realtime clock+           | ProcessTime -- ^ High-resolution per-process timer from the CPU. +           | ThreadTime  -- ^ Thread-specific CPU-time clock.  --- Readers--- | -foreign import ccall clock_readtime_monotonic :: ReaderFunc-foreign import ccall clock_readtime_realtime :: ReaderFunc-foreign import ccall clock_readtime_processtime :: ReaderFunc-foreign import ccall clock_readtime_threadtime :: ReaderFunc+-- | TimeSpec structure+data TimeSpec = Time Int Int deriving (Show, Read) -foreign import ccall clock_readres_monotonic :: ReaderFunc-foreign import ccall clock_readres_realtime :: ReaderFunc-foreign import ccall clock_readres_processtime :: ReaderFunc-foreign import ccall clock_readres_threadtime :: ReaderFunc+-- | Seconds of a TimeSpec+sec  :: TimeSpec → Int+sec  (Time s _) = s +-- | Nanoseconds of a TimeSpec+nsec :: TimeSpec → Int+nsec (Time _ n) = n --- Clock types-data Clock = Monotonic | Realtime | ProcessTime | ThreadTime+-- | Retrieves the time of the specified clock.+clock_gettime :: Clock → IO TimeSpec+clock_gettime = call . time +-- | Finds the resolution (precision) of the specified clock.+clock_getres :: Clock → IO TimeSpec+clock_getres = call . res++---------------------------------------------++-- Reader function+type ReaderFunc = Ptr Int → IO ()+ -- Clock-to-time reading time :: Clock → ReaderFunc time Monotonic = clock_readtime_monotonic@@ -50,22 +62,18 @@ res ProcessTime = clock_readres_processtime res ThreadTime = clock_readres_threadtime --- TimeSpec structure-data TimeSpec = Time Int Int deriving (Show, Read)-sec  :: TimeSpec → Int-nsec :: TimeSpec → Int-sec  (Time s _) = s-nsec (Time _ n) = n---- clock_gettime-clock_gettime :: Clock → IO TimeSpec-clock_gettime = call . time+-- Readers+foreign import ccall clock_readtime_monotonic :: ReaderFunc+foreign import ccall clock_readtime_realtime :: ReaderFunc+foreign import ccall clock_readtime_processtime :: ReaderFunc+foreign import ccall clock_readtime_threadtime :: ReaderFunc --- clock_getres-clock_getres :: Clock → IO TimeSpec-clock_getres = call . res+foreign import ccall clock_readres_monotonic :: ReaderFunc+foreign import ccall clock_readres_realtime :: ReaderFunc+foreign import ccall clock_readres_processtime :: ReaderFunc+foreign import ccall clock_readres_threadtime :: ReaderFunc --- core function+-- Marshalling call :: ReaderFunc → IO TimeSpec call read_ = do   t ← (2 ↑≣)@@ -75,7 +83,7 @@   (t ≣⊠)   return $ Time s n ----------------------------------------------+-- Arrays  (↑≣) :: Storable a ⇒ Int → IO (Ptr a) (↑≣) = mallocArray
clock.cabal view
@@ -1,5 +1,5 @@ Name:               clock-Version:            0.1+Version:            0.1.1 License:            BSD3 License-file:       COPYING Copyright:          (c) 2009 Cetin Sert@@ -7,11 +7,12 @@ Maintainer:         Cetin Sert <cetin@sertcom.de> Homepage:           http://sert.homedns.org/hs/clock/ Category:           System-Synopsis:           bindings to time.h: clock_gettime and clock_getres-Description:        bindings to time.h: clock_gettime and clock_getres+Synopsis:           low-level binding to time.h: clock_gettime and clock_getres+Description:        low-level binding to time.h: clock_gettime and clock_getres. +                    clock_settime will be added in later versions. Stability:          Experimental Build-type:         Simple-Build-depends:      base >= 2 && < 4.2+Build-depends:      base >= 2 && < 5 Exposed-Modules:    System.CPUTime.Clock Extensions:         ForeignFunctionInterface C-sources:	        csec/clock.c
csec/clock.c view
@@ -1,6 +1,7 @@ #include "clock.h" #include <time.h> + void time_(clockid_t clock, long* t) { 
csec/clock.h view
@@ -2,4 +2,8 @@ void clock_readtime_realtime(long* t); void clock_readtime_processtime(long* t); void clock_readtime_threadtime(long* t);-void clock_readres(long* t);++void clock_readres_monotonic(long* t);+void clock_readres_realtime(long* t);+void clock_readres_processtime(long* t);+void clock_readres_threadtime(long* t);
edit view
@@ -1,1 +1,1 @@-gedit COPYING clock.cabal csec/*.c csec/*.h System/CPUTime/*.hs &+gedit AUTHORS COPYING README CHANGES clock.cabal csec/*.c csec/*.h System/CPUTime/*.hs &