* Time
*/
#define TIME_NOW(tp) RUNTIME_CHECK(isc_time_now((tp)) == ISC_R_SUCCESS)
+#define TIME_NOW_HIRES(tp) \
+ RUNTIME_CHECK(isc_time_now_hires((tp)) == ISC_R_SUCCESS)
/*%
* Alignment
UNUSED(state);
setenv("TZ", "America/Los_Angeles", 1);
- result = isc_time_now(&t);
+ result = isc_time_now_hires(&t);
assert_int_equal(result, ISC_R_SUCCESS);
/* check formatting: yyyy-mm-ddThh:mm:ss.ssssssZ */
UNUSED(state);
setenv("TZ", "America/Los_Angeles", 1);
- result = isc_time_now(&t);
+ result = isc_time_now_hires(&t);
assert_int_equal(result, ISC_R_SUCCESS);
/* check formatting: yyyy-mm-ddThh:mm:ss.ssssss */
* in the current definition of isc_time_t.
*/
+isc_result_t
+isc_time_now_hires(isc_time_t *t);
+/*%<
+ * Set 't' to the current absolute time. Uses higher resolution clocks
+ * recommended when microsecond accuracy is required.
+ *
+ * Requires:
+ *
+ *\li 't' is a valid pointer.
+ *
+ * Returns:
+ *
+ *\li Success
+ *\li Unexpected error
+ * Getting the time from the system failed.
+ *\li Out of range
+ * The time from the system is too large to be represented
+ * in the current definition of isc_time_t.
+ */
+
isc_result_t
isc_time_nowplusinterval(isc_time_t *t, const isc_interval_t *i);
/*%<
#define NS_PER_US 1000 /*%< Nanoseconds per microsecond. */
#define NS_PER_MS 1000000 /*%< Nanoseconds per millisecond. */
+#if defined(CLOCK_REALTIME)
+#define CLOCKSOURCE_HIRES CLOCK_REALTIME
+#endif /* #if defined(CLOCK_REALTIME) */
+
#if defined(CLOCK_REALTIME_COARSE)
#define CLOCKSOURCE CLOCK_REALTIME_COARSE
#elif defined(CLOCK_REALTIME_FAST)
#define CLOCKSOURCE CLOCK_REALTIME
#endif /* if defined(CLOCK_REALTIME_COARSE) */
+#if !defined(CLOCKSOURCE_HIRES)
+#define CLOCKSOURCE_HIRES CLOCKSOURCE
+#endif /* #ifndef CLOCKSOURCE_HIRES */
+
/*%
*** Intervals
***/
return (false);
}
-isc_result_t
-isc_time_now(isc_time_t *t) {
+static inline isc_result_t
+time_now(isc_time_t *t, clockid_t clock) {
struct timespec ts;
char strbuf[ISC_STRERRORSIZE];
REQUIRE(t != NULL);
- if (clock_gettime(CLOCKSOURCE, &ts) == -1) {
+ if (clock_gettime(clock, &ts) == -1) {
strerror_r(errno, strbuf, sizeof(strbuf));
UNEXPECTED_ERROR(__FILE__, __LINE__, "%s", strbuf);
return (ISC_R_UNEXPECTED);
return (ISC_R_SUCCESS);
}
+isc_result_t
+isc_time_now_hires(isc_time_t *t) {
+ return time_now(t, CLOCKSOURCE_HIRES);
+}
+
+isc_result_t
+isc_time_now(isc_time_t *t) {
+ return time_now(t, CLOCKSOURCE);
+}
+
isc_result_t
isc_time_nowplusinterval(isc_time_t *t, const isc_interval_t *i) {
struct timespec ts;
* in the current definition of isc_time_t.
*/
+isc_result_t
+isc_time_now_hires(isc_time_t *t);
+/*%<
+ * Set 't' to the current absolute time. Uses higher resolution clocks
+ * recommended when microsecond accuracy is required.
+ *
+ * Requires:
+ *
+ *\li 't' is a valid pointer.
+ *
+ * Returns:
+ *
+ *\li Success
+ *\li Unexpected error
+ * Getting the time from the system failed.
+ *\li Out of range
+ * The time from the system is too large to be represented
+ * in the current definition of isc_time_t.
+ */
+
isc_result_t
isc_time_nowplusinterval(isc_time_t *t, const isc_interval_t *i);
/*
isc_time_microdiff
isc_time_nanoseconds
isc_time_now
+isc_time_now_hires
isc_time_nowplusinterval
isc_time_parsehttptimestamp
isc_time_secondsastimet
return (ISC_R_SUCCESS);
}
+isc_result_t
+isc_time_now_hires(isc_time_t *t) {
+ REQUIRE(t != NULL);
+
+ GetSystemTimePreciseAsFileTime(&t->absolute);
+
+ return (ISC_R_SUCCESS);
+}
+
isc_result_t
isc_time_nowplusinterval(isc_time_t *t, const isc_interval_t *i) {
ULARGE_INTEGER i1;