summaryrefslogtreecommitdiff
path: root/rts
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-01-22 19:09:49 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-02-11 05:08:47 -0500
commite319570ec141e0f63d82d23b88a40f96fc0b7105 (patch)
treef74ccb5c51ba9a1489d89e6ae6355c2033cbc6e1 /rts
parentde32beffde82eec954691703541a2d4081799453 (diff)
downloadhaskell-e319570ec141e0f63d82d23b88a40f96fc0b7105.tar.gz
rts: Use nanosleep instead of usleep
usleep was removed in POSIX.1-2008.
Diffstat (limited to 'rts')
-rw-r--r--rts/RtsUtils.c18
-rw-r--r--rts/RtsUtils.h1
-rw-r--r--rts/posix/itimer/Pthread.c5
3 files changed, 22 insertions, 2 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.
-------------------------------------------------------------------------- */
diff --git a/rts/RtsUtils.h b/rts/RtsUtils.h
index 5c986fe4a2..c87aedb3a7 100644
--- a/rts/RtsUtils.h
+++ b/rts/RtsUtils.h
@@ -33,6 +33,7 @@ void stgFree(void* p);
* Misc other utilities
* -------------------------------------------------------------------------- */
+int rtsSleep(Time t);
char *time_str(void);
char *showStgWord64(StgWord64, char *, bool);
diff --git a/rts/posix/itimer/Pthread.c b/rts/posix/itimer/Pthread.c
index 6f9cd8f4b3..083775bab2 100644
--- a/rts/posix/itimer/Pthread.c
+++ b/rts/posix/itimer/Pthread.c
@@ -39,6 +39,7 @@
#include "Rts.h"
#include "Ticker.h"
+#include "RtsUtils.h"
#include "Proftimer.h"
#include "Schedule.h"
#include "posix/Clock.h"
@@ -127,8 +128,8 @@ static void *itimer_thread_func(void *_handle_tick)
}
}
} else {
- if (usleep(TimeToUS(itimer_interval)) != 0 && errno != EINTR) {
- sysErrorBelch("usleep(TimeToUS(itimer_interval) failed");
+ if (rtsSleep(itimer_interval) != 0) {
+ sysErrorBelch("ITimer: sleep failed: %s", strerror(errno));
}
}