summaryrefslogtreecommitdiff
path: root/rts/RtsUtils.c
diff options
context:
space:
mode:
Diffstat (limited to 'rts/RtsUtils.c')
-rw-r--r--rts/RtsUtils.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/rts/RtsUtils.c b/rts/RtsUtils.c
index b9ddb2a345..3b55a7d03f 100644
--- a/rts/RtsUtils.c
+++ b/rts/RtsUtils.c
@@ -153,6 +153,24 @@ reportHeapOverflow(void)
}
/* -----------------------------------------------------------------------------
+ Sleep for the given period of time.
+ -------------------------------------------------------------------------- */
+
+/* Returns -1 on failure but handles EINTR internally.
+ * N.B. usleep has been removed from POSIX 2008 */
+int rtsSleep(Time t)
+{
+ struct timespec req;
+ req.tv_sec = TimeToSeconds(t);
+ req.tv_nsec = TimeToNS(t - req.tv_sec * TIME_RESOLUTION);
+ int ret;
+ do {
+ ret = nanosleep(&req, &req);
+ } while (ret == -1 && errno == EINTR);
+ return ret;
+}
+
+/* -----------------------------------------------------------------------------
Get the current time as a string. Used in profiling reports.
-------------------------------------------------------------------------- */