diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-26 08:15:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-08-26 08:15:20 +0000 |
commit | 87d772a7d708fec12f48cd8adc0dedff6e1025da (patch) | |
tree | 1fee344c64cc3f43074a01981e21126c8482a522 /src/libnetdata/clocks/clocks.c | |
parent | Adding upstream version 1.46.3. (diff) | |
download | netdata-87d772a7d708fec12f48cd8adc0dedff6e1025da.tar.xz netdata-87d772a7d708fec12f48cd8adc0dedff6e1025da.zip |
Adding upstream version 1.47.0.upstream/1.47.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/libnetdata/clocks/clocks.c')
-rw-r--r-- | src/libnetdata/clocks/clocks.c | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/libnetdata/clocks/clocks.c b/src/libnetdata/clocks/clocks.c index e1a3e64cb..5da450a2d 100644 --- a/src/libnetdata/clocks/clocks.c +++ b/src/libnetdata/clocks/clocks.c @@ -343,7 +343,7 @@ usec_t heartbeat_next(heartbeat_t *hb, usec_t tick) { } if(unlikely(now < next)) { - errno = 0; + errno_clear(); nd_log_limit_static_global_var(erl, 10, 0); nd_log_limit(&erl, NDLS_DAEMON, NDLP_NOTICE, "heartbeat clock: woke up %"PRIu64" microseconds earlier than expected " @@ -351,7 +351,7 @@ usec_t heartbeat_next(heartbeat_t *hb, usec_t tick) { next - now); } else if(unlikely(now - next > tick / 2)) { - errno = 0; + errno_clear(); nd_log_limit_static_global_var(erl, 10, 0); nd_log_limit(&erl, NDLS_DAEMON, NDLP_NOTICE, "heartbeat clock: woke up %"PRIu64" microseconds later than expected " @@ -368,6 +368,35 @@ usec_t heartbeat_next(heartbeat_t *hb, usec_t tick) { return dt; } +#ifdef OS_WINDOWS + +#include "windows.h" + +void sleep_usec_with_now(usec_t usec, usec_t started_ut) +{ + if (!started_ut) + started_ut = now_realtime_usec(); + + usec_t end_ut = started_ut + usec; + usec_t remaining_ut = usec; + + timeBeginPeriod(1); + + while (remaining_ut >= 1000) + { + DWORD sleep_ms = (DWORD) (remaining_ut / USEC_PER_MS); + Sleep(sleep_ms); + + usec_t now_ut = now_realtime_usec(); + if (now_ut >= end_ut) + break; + + remaining_ut = end_ut - now_ut; + } + + timeEndPeriod(1); +} +#else void sleep_usec_with_now(usec_t usec, usec_t started_ut) { // we expect microseconds (1.000.000 per second) // but timespec is nanoseconds (1.000.000.000 per second) @@ -411,6 +440,7 @@ void sleep_usec_with_now(usec_t usec, usec_t started_ut) { } } } +#endif static inline collected_number uptime_from_boottime(void) { #ifdef CLOCK_BOOTTIME_IS_AVAILABLE |