summaryrefslogtreecommitdiff
path: root/src/common/compat_time.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-12-13 08:28:04 -0500
committerNick Mathewson <nickm@torproject.org>2017-12-13 08:29:23 -0500
commit4c877ae87483d6e63c9e0309eb8abc009f9b9b87 (patch)
tree0ea831105d14594de5619d5416df145abcfc3314 /src/common/compat_time.c
parent426110dfa2e27f134e7bf44341e5df6f454e49a3 (diff)
downloadtor-4c877ae87483d6e63c9e0309eb8abc009f9b9b87.tar.gz
tor-4c877ae87483d6e63c9e0309eb8abc009f9b9b87.zip
Add monotime functions for clearing monotonic times
We need this to replace some of our "msec" users with monotime users.
Diffstat (limited to 'src/common/compat_time.c')
-rw-r--r--src/common/compat_time.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/common/compat_time.c b/src/common/compat_time.c
index c0cd73c74d..fa8dbdfac0 100644
--- a/src/common/compat_time.c
+++ b/src/common/compat_time.c
@@ -351,6 +351,12 @@ monotime_coarse_to_stamp(const monotime_coarse_t *t)
return (uint32_t)(t->abstime_ >> monotime_shift);
}
+int
+monotime_is_zero(const monotime_t *val)
+{
+ return val->abstime_ == 0;
+}
+
/* end of "__APPLE__" */
#elif defined(HAVE_CLOCK_GETTIME)
@@ -441,6 +447,12 @@ monotime_coarse_to_stamp(const monotime_coarse_t *t)
return (sec * STAMP_TICKS_PER_SECOND) + (nsec >> 20);
}
+int
+monotime_is_zero(const monotime_t *val)
+{
+ return val->ts_.tv_sec == 0 && val->ts_.tv_nsec == 0;
+}
+
/* end of "HAVE_CLOCK_GETTIME" */
#elif defined (_WIN32)
@@ -581,6 +593,18 @@ monotime_coarse_to_stamp(const monotime_coarse_t *t)
return (uint32_t) t->tick_count_;
}
+int
+monotime_is_zero(const monotime_t *val)
+{
+ return val->pcount_ == 0;
+}
+
+int
+monotime_coarse_is_zero(const monotime_coarse_t *val)
+{
+ return val->tick_count_ == 0;
+}
+
/* end of "_WIN32" */
#elif defined(MONOTIME_USING_GETTIMEOFDAY)
@@ -628,6 +652,12 @@ monotime_coarse_to_stamp(const monotime_coarse_t *t)
return (sec * STAMP_TICKS_PER_SECOND) | (nsec >> 10);
}
+int
+monotime_is_zero(const monotime_t *val)
+{
+ return val->tv_.tv_sec == 0 && val->tv_.tv_usec == 0;
+}
+
/* end of "MONOTIME_USING_GETTIMEOFDAY" */
#else
#error "No way to implement monotonic timers."
@@ -650,6 +680,19 @@ monotime_init(void)
}
}
+void
+monotime_zero(monotime_t *out)
+{
+ memset(out, 0, sizeof(*out));
+}
+#ifdef MONOTIME_COARSE_TYPE_IS_DIFFERENT
+void
+monotime_coarse_zero(monotime_coarse_t *out)
+{
+ memset(out, 0, sizeof(*out));
+}
+#endif
+
int64_t
monotime_diff_usec(const monotime_t *start,
const monotime_t *end)