+6085. [func] Add isc_time_monotonic() to simplify time measurements.
+ [GL !7468]
+
6084. [bug] When BIND was built without jemalloc, the allocator flag
ISC_MEM_ZERO could return non-zero memory. [GL #3845]
*\li 'i' is a valid pointer.
*/
+#define isc_interval_fromnanosecs(ns) isc_time_fromnanosecs(ns)
+#define isc_interval_tonanosecs(i) isc_time_tonanosecs(i)
+
/***
*** Absolute Times
***/
+/*%
+ * A linear count of nanoseconds.
+ *
+ * 64 bits of nanoseconds is more than 500 years.
+ */
+typedef uint64_t isc_nanosecs_t;
+
+/*%
+ * Convert linear nanoseconds to an isc_time_t
+ */
+#define isc_nanosecs_fromtime(time) \
+ (NS_PER_SEC * (isc_nanosecs_t)(time).seconds + (time).nanoseconds)
+
+/*%
+ * Construct an isc_time_t from linear nanoseconds
+ */
+#define isc_time_fromnanosecs(ns) \
+ ((isc_time_t){ \
+ .seconds = (ns) / NS_PER_SEC, \
+ .nanoseconds = (ns) % NS_PER_SEC, \
+ })
+
/*%
* The contents of this structure are private, and MUST NOT be accessed
* directly by callers.
*\li 't' is a valid pointer.
*/
+isc_nanosecs_t
+isc_time_monotonic(void);
+/*%<
+ * Returns the system's monotonic time in linear nanoseconds.
+ */
+
isc_result_t
isc_time_now(isc_time_t *t);
/*%<
return time_now(t, CLOCKSOURCE);
}
+isc_nanosecs_t
+isc_time_monotonic(void) {
+ struct timespec ts;
+
+ RUNTIME_CHECK(clock_gettime(CLOCK_MONOTONIC, &ts) != -1);
+
+ return (isc_nanosecs_fromtime(((isc_time_t){
+ .seconds = ts.tv_sec,
+ .nanoseconds = ts.tv_nsec,
+ })));
+}
+
isc_result_t
isc_time_nowplusinterval(isc_time_t *t, const isc_interval_t *i) {
struct timespec ts;