[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] sched: Don't expose the global scheduler libevent object



commit 14cd8bdd4ba6f4c5946ecd9877c77c9ba305bbe8
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date:   Thu Sep 14 14:22:22 2017 -0400

    sched: Don't expose the global scheduler libevent object
    
    Instead, add wrappers to do the needed action the different scheduler needs
    with the libevent object.
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
 src/or/scheduler.c         | 25 ++++++++++++++++++-------
 src/or/scheduler.h         |  3 ++-
 src/or/scheduler_kist.c    | 13 +++----------
 src/or/scheduler_vanilla.c | 12 +++---------
 4 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/src/or/scheduler.c b/src/or/scheduler.c
index 39427b782..8d2dfac08 100644
--- a/src/or/scheduler.c
+++ b/src/or/scheduler.c
@@ -214,13 +214,6 @@ get_channels_pending(void)
   return channels_pending;
 }
 
-/* Return our libevent scheduler event. */
-struct event *
-get_run_sched_ev(void)
-{
-  return run_sched_ev;
-}
-
 /* Comparison function to use when sorting pending channels */
 MOCK_IMPL(int,
 scheduler_compare_channels, (const void *c1_v, const void *c2_v))
@@ -496,6 +489,24 @@ scheduler_channel_has_waiting_cells,(channel_t *chan))
   }
 }
 
+/* Add the scheduler event to the set of pending events with next_run being
+ * the time up to libevent should wait before triggering the event. */
+void
+scheduler_ev_add(const struct timeval *next_run)
+{
+  tor_assert(run_sched_ev);
+  tor_assert(next_run);
+  event_add(run_sched_ev, next_run);
+}
+
+/* Make the scheduler event active with the given flags. */
+void
+scheduler_ev_active(int flags)
+{
+  tor_assert(run_sched_ev);
+  event_active(run_sched_ev, flags, 1);
+}
+
 /*
  * Initialize everything scheduling-related from config.c. Note this is only
  * called when Tor is starting up, while scheduler_t->init() is called both
diff --git a/src/or/scheduler.h b/src/or/scheduler.h
index b1863b119..c69f763ff 100644
--- a/src/or/scheduler.h
+++ b/src/or/scheduler.h
@@ -139,9 +139,10 @@ MOCK_DECL(void, scheduler_channel_has_waiting_cells, (channel_t *chan));
  * Defined in scheduler.c
  *********************************/
 smartlist_t *get_channels_pending(void);
-struct event *get_run_sched_ev(void);
 MOCK_DECL(int, scheduler_compare_channels,
           (const void *c1_v, const void *c2_v));
+void scheduler_ev_active(int flags);
+void scheduler_ev_add(const struct timeval *next_run);
 
 #ifdef TOR_UNIT_TESTS
 extern smartlist_t *channels_pending;
diff --git a/src/or/scheduler_kist.c b/src/or/scheduler_kist.c
index 8646169ee..b4234a053 100644
--- a/src/or/scheduler_kist.c
+++ b/src/or/scheduler_kist.c
@@ -471,14 +471,7 @@ kist_scheduler_schedule(void)
   struct monotime_t now;
   struct timeval next_run;
   int32_t diff;
-  struct event *ev = get_run_sched_ev();
-  IF_BUG_ONCE(!ev) {
-    log_warn(LD_SCHED, "Wow we don't have a scheduler event. That's really "
-             "weird! We can't really schedule a scheduling run with libevent "
-             "without it. So we're going to stop trying now and hope we have "
-             "one next time. If we never get one, we're broken.");
-    return;
-  }
+
   if (!have_work()) {
     return;
   }
@@ -489,9 +482,9 @@ kist_scheduler_schedule(void)
     /* 1000 for ms -> us */
     next_run.tv_usec = (sched_run_interval - diff) * 1000;
     /* Readding an event reschedules it. It does not duplicate it. */
-    event_add(ev, &next_run);
+    scheduler_ev_add(&next_run);
   } else {
-    event_active(ev, EV_TIMEOUT, 1);
+    scheduler_ev_active(EV_TIMEOUT);
   }
 }
 
diff --git a/src/or/scheduler_vanilla.c b/src/or/scheduler_vanilla.c
index efc0e98de..541ee8006 100644
--- a/src/or/scheduler_vanilla.c
+++ b/src/or/scheduler_vanilla.c
@@ -43,15 +43,9 @@ vanilla_scheduler_schedule(void)
   if (!have_work()) {
     return;
   }
-  struct event *ev = get_run_sched_ev();
-  IF_BUG_ONCE(!ev) {
-    log_warn(LD_SCHED, "Wow we don't have a scheduler event. That's really "
-             "weird! We can't really schedule a scheduling run with libevent "
-             "without it. So we're going to stop trying now and hope we have "
-             "one next time. If we never get one, we're broken.");
-    return;
-  }
-  event_active(ev, EV_TIMEOUT, 1);
+
+  /* Activate our event so it can process channels. */
+  scheduler_ev_active(EV_TIMEOUT);
 }
 
 static void



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits