]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Remove the "cached gettimeofday" logic.
authorNick Mathewson <nickm@torproject.org>
Thu, 26 Apr 2018 14:24:33 +0000 (10:24 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 26 Apr 2018 16:01:48 +0000 (12:01 -0400)
Previously were using this value to have a cheap highish-resolution
timer.  But we were only using it in one place, and current dogma is
to use monotime_coarse_t for this kind of thing.

changes/ticket25927.2 [new file with mode: 0644]
src/common/compat_libevent.c
src/common/compat_libevent.h
src/or/connection.c

diff --git a/changes/ticket25927.2 b/changes/ticket25927.2
new file mode 100644 (file)
index 0000000..9acb4aa
--- /dev/null
@@ -0,0 +1,5 @@
+  o Code simplification and refactoring:
+    - Remove our previous logic for "cached gettimeofday()" -- our coarse
+      monotonic timers are fast enough for this purpose, and far less
+      error-prone. Implements part of ticket 25927.
+
index 9936c0aac41558b8ea2303431ccf35c651c265bc..707efe3892362f47d7510a27f66598a2e3b4d5c1 100644 (file)
@@ -494,51 +494,7 @@ tor_libevent_exit_loop_after_callback(struct event_base *base)
   event_base_loopbreak(base);
 }
 
-#if defined(LIBEVENT_VERSION_NUMBER) &&         \
-  LIBEVENT_VERSION_NUMBER >= V(2,1,1) &&        \
-  !defined(TOR_UNIT_TESTS)
-void
-tor_gettimeofday_cached(struct timeval *tv)
-{
-  event_base_gettimeofday_cached(the_event_base, tv);
-}
-void
-tor_gettimeofday_cache_clear(void)
-{
-  event_base_update_cache_time(the_event_base);
-}
-#else /* !(defined(LIBEVENT_VERSION_NUMBER) &&         ...) */
-/** Cache the current hi-res time; the cache gets reset when libevent
- * calls us. */
-static struct timeval cached_time_hires = {0, 0};
-
-/** Return a fairly recent view of the current time. */
-void
-tor_gettimeofday_cached(struct timeval *tv)
-{
-  if (cached_time_hires.tv_sec == 0) {
-    tor_gettimeofday(&cached_time_hires);
-  }
-  *tv = cached_time_hires;
-}
-
-/** Reset the cached view of the current time, so that the next time we try
- * to learn it, we will get an up-to-date value. */
-void
-tor_gettimeofday_cache_clear(void)
-{
-  cached_time_hires.tv_sec = 0;
-}
-
-#ifdef TOR_UNIT_TESTS
-/** For testing: force-update the cached time to a given value. */
-void
-tor_gettimeofday_cache_set(const struct timeval *tv)
-{
-  tor_assert(tv);
-  memcpy(&cached_time_hires, tv, sizeof(*tv));
-}
-
+#if defined(TOR_UNIT_TESTS)
 /** For testing: called post-fork to make libevent reinitialize
  * kernel structures. */
 void
@@ -548,5 +504,4 @@ tor_libevent_postfork(void)
   tor_assert(r == 0);
 }
 #endif /* defined(TOR_UNIT_TESTS) */
-#endif /* defined(LIBEVENT_VERSION_NUMBER) &&         ... */
 
index 29c6ad375a88961886f70a71383516ee5837ede2..e2747860a9bbc3c2e275fc423e44ed1bef0edc70 100644 (file)
@@ -68,10 +68,7 @@ void tor_libevent_free_all(void);
 
 int tor_init_libevent_rng(void);
 
-void tor_gettimeofday_cached(struct timeval *tv);
-void tor_gettimeofday_cache_clear(void);
 #ifdef TOR_UNIT_TESTS
-void tor_gettimeofday_cache_set(const struct timeval *tv);
 void tor_libevent_postfork(void);
 #endif
 
index de0f0485b0c8eefaf39083aae14906e8d9cf160b..c2673ade1647d75ba067bb19ca20bb7a49ecb0ec 100644 (file)
@@ -3440,7 +3440,6 @@ connection_handle_read(connection_t *conn)
 {
   int res;
 
-  tor_gettimeofday_cache_clear();
   res = connection_handle_read_impl(conn);
   return res;
 }
@@ -3983,7 +3982,6 @@ int
 connection_handle_write(connection_t *conn, int force)
 {
     int res;
-    tor_gettimeofday_cache_clear();
     conn->in_connection_handle_write = 1;
     res = connection_handle_write_impl(conn, force);
     conn->in_connection_handle_write = 0;