]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
IO: Add current_time_now() function for immediate timestamp
authorToke Høiland-Jørgensen <toke@toke.dk>
Thu, 1 Jun 2023 22:26:41 +0000 (00:26 +0200)
committerOndrej Zajicek <santiago@crfreenet.org>
Thu, 1 Jun 2023 22:26:41 +0000 (00:26 +0200)
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.

lib/timer.h
sysdep/unix/io.c

index c5ea430cdb81fe858c819eab697ff753a3674d78..0f87852bd6d38cb0ff0ee24acfe0eef12828fc09 100644 (file)
@@ -46,6 +46,9 @@ extern struct timeloop main_timeloop;
 btime current_time(void);
 btime current_real_time(void);
 
+/* In sysdep code */
+btime current_time_now(void);
+
 //#define now (current_time() TO_S)
 //#define now_real (current_real_time() TO_S)
 extern btime boot_time;
index e131ca41ff460ae9e9d4b9fc94c831c7ea936adc..6aedcfb669191ae60c198d6b3620a9123afc8e9a 100644 (file)
@@ -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