aboutsummaryrefslogtreecommitdiff
path: root/src/common/compat_libevent.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2014-03-04 11:00:02 -0500
committerNick Mathewson <nickm@torproject.org>2014-03-04 11:00:02 -0500
commitbb375442141b4a5b301212394ce3e106cb34daf2 (patch)
tree96a5baed08b8212b1b719e8ad72507d76e34bb99 /src/common/compat_libevent.c
parentc8d41da52d6ae1edd1c4999e328b1e7eadc0ab5b (diff)
parent46118d7d7542aa960a26a08d9d5fbac33698765c (diff)
downloadtor-bb375442141b4a5b301212394ce3e106cb34daf2.tar.gz
tor-bb375442141b4a5b301212394ce3e106cb34daf2.zip
Merge remote-tracking branch 'public/bug10169_024' into bug10169_025_v2
Conflicts: src/common/compat_libevent.h src/or/relay.c
Diffstat (limited to 'src/common/compat_libevent.c')
-rw-r--r--src/common/compat_libevent.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/common/compat_libevent.c b/src/common/compat_libevent.c
index b7987bc99a..61cbe91488 100644
--- a/src/common/compat_libevent.c
+++ b/src/common/compat_libevent.c
@@ -673,3 +673,33 @@ tor_gettimeofday_cache_set(const struct timeval *tv)
#endif
#endif
+/**
+ * As tor_gettimeofday_cached, but can never move backwards in time.
+ *
+ * The returned value may diverge from wall-clock time, since wall-clock time
+ * can trivially be adjusted backwards, and this can't. Don't mix wall-clock
+ * time with these values in the same calculation.
+ *
+ * Depending on implementation, this function may or may not "smooth out" huge
+ * jumps forward in wall-clock time. It may or may not keep its results
+ * advancing forward (as opposed to stalling) if the wall-clock time goes
+ * backwards. The current implementation does neither of of these.
+ *
+ * This function is not thread-safe; do not call it outside the main thread.
+ *
+ * In future versions of Tor, this may return a time does not have its
+ * origin at the Unix epoch.
+ */
+void
+tor_gettimeofday_cached_monotonic(struct timeval *tv)
+{
+ struct timeval last_tv = { 0, 0 };
+
+ tor_gettimeofday_cached(tv);
+ if (timercmp(tv, &last_tv, <)) {
+ memcpy(tv, &last_tv, sizeof(struct timeval));
+ } else {
+ memcpy(&last_tv, tv, sizeof(struct timeval));
+ }
+}
+