diff options
author | Ben Gamari <ben@smart-cactus.org> | 2020-05-31 13:23:20 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-06-04 04:38:36 -0400 |
commit | cab684f0857c71c40996201d6fb3ba93eb38a701 (patch) | |
tree | a826a9b6a86e4e87b8f9364b12d3d3d81460d77a | |
parent | c330331adc0a686f24b94844d0eb3a0711b928d7 (diff) | |
download | haskell-cab684f0857c71c40996201d6fb3ba93eb38a701.tar.gz |
rts: Add Windows-specific implementation of rtsSleep
Previously we would use the POSIX path, which uses `nanosleep`. However,
it turns out that `nanosleep` is provided by `libpthread` on Windows. In
general we don't want to incur such a dependency. Avoid this by simply
using `Sleep` on Windows.
Fixes #18272.
-rw-r--r-- | rts/RtsUtils.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/rts/RtsUtils.c b/rts/RtsUtils.c index 3b55a7d03f..e88babcd08 100644 --- a/rts/RtsUtils.c +++ b/rts/RtsUtils.c @@ -156,10 +156,16 @@ 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 */ +/* Returns -1 on failure but handles EINTR internally. On Windows this will + * only have millisecond precision. */ int rtsSleep(Time t) { +#if defined(_WIN32) + // N.B. we can't use nanosleep on Windows as it would incur a pthreads + // dependency. See #18272. + Sleep(TimeToMS(t)); + return 0; +#else struct timespec req; req.tv_sec = TimeToSeconds(t); req.tv_nsec = TimeToNS(t - req.tv_sec * TIME_RESOLUTION); @@ -168,6 +174,7 @@ int rtsSleep(Time t) ret = nanosleep(&req, &req); } while (ret == -1 && errno == EINTR); return ret; +#endif /* _WIN32 */ } /* ----------------------------------------------------------------------------- |