[tor-commits] [tor/maint-0.2.9] refactor out the tor_event_base_loopexit() call

nickm at torproject.org nickm at torproject.org
Thu Nov 3 19:45:23 UTC 2016


commit 28b755e66007c94521c45bdda07abdf3bcd59656
Author: Roger Dingledine <arma at torproject.org>
Date:   Mon Oct 31 00:20:22 2016 -0400

    refactor out the tor_event_base_loopexit() call
    
    no actual changes
---
 src/or/main.c | 25 +++++++++++++++++--------
 src/or/main.h |  2 ++
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/or/main.c b/src/or/main.c
index 6b5619c..cba19c3 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -726,6 +726,19 @@ connection_should_read_from_linked_conn(connection_t *conn)
   return 0;
 }
 
+/** If we called event_base_loop() and told it to never stop until it
+ * runs out of events, now we've changed our mind: tell it we want it to
+ * finish. */
+void
+tell_event_loop_to_finish(void)
+{
+  if (!called_loop_once) {
+    struct timeval tv = { 0, 0 };
+    tor_event_base_loopexit(tor_libevent_get_base(), &tv);
+    called_loop_once = 1; /* hack to avoid adding more exit events */
+  }
+}
+
 /** Helper: Tell the main loop to begin reading bytes into <b>conn</b> from
  * its linked connection, if it is not doing so already.  Called by
  * connection_start_reading and connection_start_writing as appropriate. */
@@ -738,14 +751,10 @@ connection_start_reading_from_linked_conn(connection_t *conn)
   if (!conn->active_on_link) {
     conn->active_on_link = 1;
     smartlist_add(active_linked_connection_lst, conn);
-    if (!called_loop_once) {
-      /* This is the first event on the list; we won't be in LOOP_ONCE mode,
-       * so we need to make sure that the event_base_loop() actually exits at
-       * the end of its run through the current connections and lets us
-       * activate read events for linked connections. */
-      struct timeval tv = { 0, 0 };
-      tor_event_base_loopexit(tor_libevent_get_base(), &tv);
-    }
+    /* make sure that the event_base_loop() function exits at
+     * the end of its run through the current connections, so we can
+     * activate read events for linked connections. */
+    tell_event_loop_to_finish();
   } else {
     tor_assert(smartlist_contains(active_linked_connection_lst, conn));
   }
diff --git a/src/or/main.h b/src/or/main.h
index ad865b8..6949376 100644
--- a/src/or/main.h
+++ b/src/or/main.h
@@ -45,6 +45,8 @@ int connection_is_writing(connection_t *conn);
 MOCK_DECL(void,connection_stop_writing,(connection_t *conn));
 MOCK_DECL(void,connection_start_writing,(connection_t *conn));
 
+void tell_event_loop_to_finish(void);
+
 void connection_stop_reading_from_linked_conn(connection_t *conn);
 
 void directory_all_unreachable(time_t now);





More information about the tor-commits mailing list