diff options
author | Toke Høiland-Jørgensen <toke@toke.dk> | 2023-06-02 00:26:41 +0200 |
---|---|---|
committer | Ondrej Zajicek <santiago@crfreenet.org> | 2023-06-02 00:26:41 +0200 |
commit | d8cf3cad5104ab7a9887397b2a34d94c8a5f2aef (patch) | |
tree | 5e2d4be853f84197031092febf20a66a7a7acdf7 /sysdep | |
parent | f8ba82804faba5cc1520d4545330502e29b9e920 (diff) |
IO: Add current_time_now() function for immediate timestamp
Add a current_time_now() function which gets an immediate monotonic
timestamp instead of using the cached value from the event loop. This is
useful for callers that need precise times, such as the Babel RTT
measurement code.
Minor changes by committer.
Diffstat (limited to 'sysdep')
-rw-r--r-- | sysdep/unix/io.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/sysdep/unix/io.c b/sysdep/unix/io.c index e131ca41..6aedcfb6 100644 --- a/sysdep/unix/io.c +++ b/sysdep/unix/io.c @@ -171,6 +171,19 @@ times_update_real_time(struct timeloop *loop) loop->real_time = ts.tv_sec S + ts.tv_nsec NS; } +btime +current_time_now(void) +{ + struct timespec ts; + int rv; + + rv = clock_gettime(CLOCK_MONOTONIC, &ts); + if (rv < 0) + die("clock_gettime: %m"); + + return ts.tv_sec S + ts.tv_nsec NS; +} + /** * DOC: Sockets |