a1debedea06bec1d1ff073ef6efab96e70734464
[ghc.git] / includes / rts / Time.h
1 /* ----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 1998-2004
4 *
5 * Time values in the RTS
6 *
7 * To understand the structure of the RTS headers, see the wiki:
8 * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes
9 *
10 * --------------------------------------------------------------------------*/
11
12 #ifndef RTSTIME_H
13 #define RTSTIME_H
14
15 // For most time values in the RTS we use a fixed resolution of nanoseconds,
16 // normalising the time we get from platform-dependent APIs to this
17 // resolution.
18 #define TIME_RESOLUTION 1000000000
19 typedef int64_t Time;
20
21 #define TIME_MAX HS_INT64_MAX
22
23 #if TIME_RESOLUTION == 1000000000
24 // I'm being lazy, but it's awkward to define fully general versions of these
25 #define TimeToUS(t) ((t) / 1000)
26 #define TimeToNS(t) (t)
27 #define USToTime(t) ((Time)(t) * 1000)
28 #define NSToTime(t) ((Time)(t))
29 #else
30 #error Fix TimeToNS(), TimeToUS() etc.
31 #endif
32
33 #define SecondsToTime(t) ((Time)(t) * TIME_RESOLUTION)
34 #define TimeToSeconds(t) ((t) / TIME_RESOLUTION)
35
36 // Use instead of SecondsToTime() when we have a floating-point
37 // seconds value, to avoid truncating it.
38 INLINE_HEADER Time fsecondsToTime (double t)
39 {
40 return (Time)(t * TIME_RESOLUTION);
41 }
42
43 #endif // RTSTIME_H