summaryrefslogtreecommitdiff
path: root/includes/rts/Time.h
diff options
context:
space:
mode:
Diffstat (limited to 'includes/rts/Time.h')
-rw-r--r--includes/rts/Time.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/includes/rts/Time.h b/includes/rts/Time.h
new file mode 100644
index 0000000000..a1debedea0
--- /dev/null
+++ b/includes/rts/Time.h
@@ -0,0 +1,43 @@
+/* ----------------------------------------------------------------------------
+ *
+ * (c) The GHC Team, 1998-2004
+ *
+ * Time values in the RTS
+ *
+ * To understand the structure of the RTS headers, see the wiki:
+ * http://ghc.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes
+ *
+ * --------------------------------------------------------------------------*/
+
+#ifndef RTSTIME_H
+#define RTSTIME_H
+
+// For most time values in the RTS we use a fixed resolution of nanoseconds,
+// normalising the time we get from platform-dependent APIs to this
+// resolution.
+#define TIME_RESOLUTION 1000000000
+typedef int64_t Time;
+
+#define TIME_MAX HS_INT64_MAX
+
+#if TIME_RESOLUTION == 1000000000
+// I'm being lazy, but it's awkward to define fully general versions of these
+#define TimeToUS(t) ((t) / 1000)
+#define TimeToNS(t) (t)
+#define USToTime(t) ((Time)(t) * 1000)
+#define NSToTime(t) ((Time)(t))
+#else
+#error Fix TimeToNS(), TimeToUS() etc.
+#endif
+
+#define SecondsToTime(t) ((Time)(t) * TIME_RESOLUTION)
+#define TimeToSeconds(t) ((t) / TIME_RESOLUTION)
+
+// Use instead of SecondsToTime() when we have a floating-point
+// seconds value, to avoid truncating it.
+INLINE_HEADER Time fsecondsToTime (double t)
+{
+ return (Time)(t * TIME_RESOLUTION);
+}
+
+#endif // RTSTIME_H