]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Move tor_gettimeofday_cached() into compat_libevent
authorNick Mathewson <nickm@torproject.org>
Fri, 15 Jun 2012 14:31:34 +0000 (10:31 -0400)
committerNick Mathewson <nickm@torproject.org>
Fri, 15 Jun 2012 19:07:53 +0000 (15:07 -0400)
changes/move_cached_gtod [new file with mode: 0644]
src/common/compat_libevent.c
src/common/compat_libevent.h
src/or/relay.c
src/or/relay.h

diff --git a/changes/move_cached_gtod b/changes/move_cached_gtod
new file mode 100644 (file)
index 0000000..53d8092
--- /dev/null
@@ -0,0 +1,3 @@
+  o Code simplification and refactoring:
+    - Move tor_gettimeofday_cached() into compat_libevent.c, and use
+      Libevent's notion of cached time when possible.
index 9f7ac632397d515e002e423c3c42fdbabaaf07ad..544d16a215ac5da6d4b9c273dd0af96a33a53132 100644 (file)
@@ -689,3 +689,37 @@ tor_add_bufferevent_to_rate_limit_group(struct bufferevent *bev,
 }
 #endif
 
+#if defined(LIBEVENT_VERSION_NUMBER) && LIBEVENT_VERSION_NUMBER >= V(2,1,1)
+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
+/** 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;
+}
+#endif
index 224c76fda79ae639c57d856e91bd4a0e3ead4f20..56285ef80df9ea6bc824ff7148e147bdd5384bca 100644 (file)
@@ -88,5 +88,8 @@ int tor_add_bufferevent_to_rate_limit_group(struct bufferevent *bev,
                                    struct bufferevent_rate_limit_group *g);
 #endif
 
+void tor_gettimeofday_cached(struct timeval *tv);
+void tor_gettimeofday_cache_clear(void);
+
 #endif
 
index 8bbc9891e8e2fa82f07299aac0fb9ba2701a0f18..3f894bfe1f0393f956b2a4bd323e243f380acd03 100644 (file)
@@ -52,11 +52,6 @@ static int circuit_consider_stop_edge_reading(circuit_t *circ,
                                               crypt_path_t *layer_hint);
 static int circuit_queue_streams_are_blocked(circuit_t *circ);
 
-/* XXXX023 move this all to compat_libevent */
-/** Cache the current hi-res time; the cache gets reset when libevent
- * calls us. */
-static struct timeval cached_time_hires = {0, 0};
-
 /** Stop reading on edge connections when we have this many cells
  * waiting on the appropriate queue. */
 #define CELL_QUEUE_HIGHWATER_SIZE 256
@@ -64,24 +59,6 @@ static struct timeval cached_time_hires = {0, 0};
  * cells. */
 #define CELL_QUEUE_LOWWATER_SIZE 64
 
-/** Return a fairly recent view of the current time. */
-static 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;
-}
-
 /** Stats: how many relay cells have originated at this hop, or have
  * been relayed onward (not recognized at this hop)?
  */
index 6a54373654d603ca0ac1546a8544311a1e8c25ee..41675e21063df012f96dc27bb429c0b57ce2922e 100644 (file)
@@ -64,8 +64,6 @@ void cell_ewma_set_scale_factor(const or_options_t *options,
                                 const networkstatus_t *consensus);
 void circuit_clear_cell_queue(circuit_t *circ, or_connection_t *orconn);
 
-void tor_gettimeofday_cache_clear(void);
-
 #ifdef RELAY_PRIVATE
 int relay_crypt(circuit_t *circ, cell_t *cell, cell_direction_t cell_direction,
                 crypt_path_t **layer_hint, char *recognized);