@cryptotaxi247 / netdata-1 / commits / 35ec0545d

Fix nanosleep on platforms other than Linux (#12991)

Vladimir Kobal committed May 24, 2022 at 16:34 UTC 35ec0545dd797534c42d033b31edff3600bd2c88
1 file changed +10
libnetdata/clocks/clocks.c
+10
@@ -179,6 +179,7 @@ inline usec_t dt_usec(struct timeval *now, struct timeval *old) {
179 return (ts1 > ts2) ? (ts1 - ts2) : (ts2 - ts1);
180 }
181
182 +#ifdef __linux__
183 void sleep_to_absolute_time(usec_t usec) {
184 static int einval_printed = 0, enotsup_printed = 0, eunknown_printed = 0;
185 clockid_t clock = CLOCK_REALTIME;
@@ -225,6 +226,7 @@ void sleep_to_absolute_time(usec_t usec) {
226 }
227 }
228 };
229 +#endif
230
231 #define HEARTBEAT_ALIGNMENT_STATISTICS_SIZE 10
232 netdata_mutex_t heartbeat_alignment_mutex = NETDATA_MUTEX_INITIALIZER;
@@ -344,12 +346,20 @@ void sleep_usec(usec_t usec) {
346 .tv_nsec = (suseconds_t) ((usec % USEC_PER_SEC) * NSEC_PER_USEC)
347 };
348
349 +#ifdef __linux__
350 while ((errno = clock_nanosleep(CLOCK_REALTIME, 0, &req, &rem)) != 0) {
351 +#else
352 + while ((errno = nanosleep(&req, &rem)) != 0) {
353 +#endif
354 if (likely(errno == EINTR)) {
355 req.tv_sec = rem.tv_sec;
356 req.tv_nsec = rem.tv_nsec;
357 } else {
358 +#ifdef __linux__
359 error("Cannot clock_nanosleep(CLOCK_REALTIME) for %llu microseconds.", usec);
360 +#else
361 + error("Cannot nanosleep() for %llu microseconds.", usec);
362 +#endif
363 break;
364 }
365 }