diff options
author | Vladimir Kobal <vlad@prokk.net> | 2022-05-24 16:34:55 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-24 15:34:55 +0200 |
commit | 35ec0545dd797534c42d033b31edff3600bd2c88 (patch) | |
tree | 9ddfabbfe64541cd0c5ae6879e5ae89524b6426a /libnetdata | |
parent | 3766c410f83a593c54eedc8f726b0ab9daed4b1a (diff) |
Fix nanosleep on platforms other than Linux (#12991)
Diffstat (limited to 'libnetdata')
-rw-r--r-- | libnetdata/clocks/clocks.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/libnetdata/clocks/clocks.c b/libnetdata/clocks/clocks.c index 9e7264d33f..f0e17b232b 100644 --- a/libnetdata/clocks/clocks.c +++ b/libnetdata/clocks/clocks.c @@ -179,6 +179,7 @@ inline usec_t dt_usec(struct timeval *now, struct timeval *old) { return (ts1 > ts2) ? (ts1 - ts2) : (ts2 - ts1); } +#ifdef __linux__ void sleep_to_absolute_time(usec_t usec) { static int einval_printed = 0, enotsup_printed = 0, eunknown_printed = 0; clockid_t clock = CLOCK_REALTIME; @@ -225,6 +226,7 @@ void sleep_to_absolute_time(usec_t usec) { } } }; +#endif #define HEARTBEAT_ALIGNMENT_STATISTICS_SIZE 10 netdata_mutex_t heartbeat_alignment_mutex = NETDATA_MUTEX_INITIALIZER; @@ -344,12 +346,20 @@ void sleep_usec(usec_t usec) { .tv_nsec = (suseconds_t) ((usec % USEC_PER_SEC) * NSEC_PER_USEC) }; +#ifdef __linux__ while ((errno = clock_nanosleep(CLOCK_REALTIME, 0, &req, &rem)) != 0) { +#else + while ((errno = nanosleep(&req, &rem)) != 0) { +#endif if (likely(errno == EINTR)) { req.tv_sec = rem.tv_sec; req.tv_nsec = rem.tv_nsec; } else { +#ifdef __linux__ error("Cannot clock_nanosleep(CLOCK_REALTIME) for %llu microseconds.", usec); +#else + error("Cannot nanosleep() for %llu microseconds.", usec); +#endif break; } } |