]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
add isc_loop_now() to get consistent time
authorEvan Hunt <each@isc.org>
Sat, 27 May 2023 08:42:46 +0000 (01:42 -0700)
committerOndřej Surý <ondrej@isc.org>
Wed, 19 Jul 2023 13:32:21 +0000 (15:32 +0200)
isc_loop_now() is a front-end to uv_now(), returning the start
time of the current event loop tick.

lib/isc/include/isc/loop.h
lib/isc/loop.c

index de94e25a22e6ae04b969214352ad7f8c91023ee8..ba049ae1e348e07a20c3a048b4aed0af6dbff289 100644 (file)
@@ -205,4 +205,14 @@ isc_loop_getloopmgr(isc_loop_t *loop);
  * Requires:
  *\li  'loop' is a valid loop.
  */
+
+isc_time_t
+isc_loop_now(isc_loop_t *loop);
+/*%<
+ * Returns the start time of the current loop tick.
+ *
+ * Requires:
+ *
+ * \li 'loop' is a valid loop.
+ */
 ISC_LANG_ENDDECLS
index 67f74c4571d38f8693525832a53363edac74646f..5ee9daa8ebae2de972e7a08e670bc85dcbe2ee45 100644 (file)
@@ -32,6 +32,7 @@
 #include <isc/strerr.h>
 #include <isc/thread.h>
 #include <isc/tid.h>
+#include <isc/time.h>
 #include <isc/urcu.h>
 #include <isc/util.h>
 #include <isc/uv.h>
@@ -598,3 +599,16 @@ isc_loop_getloopmgr(isc_loop_t *loop) {
 
        return (loop->loopmgr);
 }
+
+isc_time_t
+isc_loop_now(isc_loop_t *loop) {
+       REQUIRE(VALID_LOOP(loop));
+
+       uint64_t msec = uv_now(&loop->loop);
+       isc_time_t t = {
+               .seconds = msec / MS_PER_SEC,
+               .nanoseconds = (msec % MS_PER_SEC) * NS_PER_MS,
+       };
+
+       return (t);
+}