summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/Rts.h2
-rw-r--r--rts/posix/Select.c15
2 files changed, 14 insertions, 3 deletions
diff --git a/includes/Rts.h b/includes/Rts.h
index 501b9dcbfc..c52fe63d78 100644
--- a/includes/Rts.h
+++ b/includes/Rts.h
@@ -156,6 +156,8 @@ void _assertFail(const char *filename, unsigned int linenum)
#define TIME_RESOLUTION 1000000000
typedef StgInt64 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)
diff --git a/rts/posix/Select.c b/rts/posix/Select.c
index 5acb8174da..99a9508507 100644
--- a/rts/posix/Select.c
+++ b/rts/posix/Select.c
@@ -67,9 +67,18 @@ static LowResTime getLowResTimeOfDay(void)
*/
LowResTime getDelayTarget (HsInt us)
{
- // round up the target time, because we never want to sleep *less*
- // than the desired amount.
- return TimeToLowResTimeRoundUp(getProcessElapsedTime() + USToTime(us));
+ Time elapsed;
+ elapsed = getProcessElapsedTime();
+
+ // If the desired target would be larger than the maximum Time,
+ // default to the maximum Time. (#7087)
+ if (us > TimeToUS(TIME_MAX - elapsed)) {
+ return TimeToLowResTimeRoundDown(TIME_MAX);
+ } else {
+ // round up the target time, because we never want to sleep *less*
+ // than the desired amount.
+ return TimeToLowResTimeRoundUp(elapsed + USToTime(us));
+ }
}
/* There's a clever trick here to avoid problems when the time wraps