Commit e319570e authored by Ben Gamari's avatar Ben Gamari 🐢 Committed by Marge Bot

rts: Use nanosleep instead of usleep

usleep was removed in POSIX.1-2008.
parent de32beff
Pipeline #15647 passed with stages
in 498 minutes and 49 seconds
......@@ -152,6 +152,24 @@ reportHeapOverflow(void)
(W_)RtsFlags.GcFlags.maxHeapSize * BLOCK_SIZE);
}
/* -----------------------------------------------------------------------------
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.
-------------------------------------------------------------------------- */
......
......@@ -33,6 +33,7 @@ void stgFree(void* p);
* Misc other utilities
* -------------------------------------------------------------------------- */
int rtsSleep(Time t);
char *time_str(void);
char *showStgWord64(StgWord64, char *, bool);
......
......@@ -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));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment