cpp: Use #pragma once instead of #ifndef guards
[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 #pragma once
13
14 // For most time values in the RTS we use a fixed resolution of nanoseconds,
15 // normalising the time we get from platform-dependent APIs to this
16 // resolution.
17 #define TIME_RESOLUTION 1000000000
18 typedef int64_t Time;
19
20 #define TIME_MAX HS_INT64_MAX
21
22 #if TIME_RESOLUTION == 1000000000
23 // I'm being lazy, but it's awkward to define fully general versions of these
24 #define TimeToUS(t) ((t) / 1000)
25 #define TimeToNS(t) (t)
26 #define USToTime(t) ((Time)(t) * 1000)
27 #define NSToTime(t) ((Time)(t))
28 #else
29 #error Fix TimeToNS(), TimeToUS() etc.
30 #endif
31
32 #define SecondsToTime(t) ((Time)(t) * TIME_RESOLUTION)
33 #define TimeToSeconds(t) ((t) / TIME_RESOLUTION)
34
35 // Use instead of SecondsToTime() when we have a floating-point
36 // seconds value, to avoid truncating it.
37 INLINE_HEADER Time fsecondsToTime (double t)
38 {
39 return (Time)(t * TIME_RESOLUTION);
40 }