|
@@ -4,6 +4,8 @@
|
|
|
#include "core/or/or.h"
|
|
|
#include "app/config/config.h"
|
|
|
|
|
|
+#include "core/or/scheduler_sys.h"
|
|
|
+
|
|
|
#include "lib/evloop/compat_libevent.h"
|
|
|
#define SCHEDULER_PRIVATE_
|
|
|
#define SCHEDULER_KIST_PRIVATE
|
|
@@ -155,7 +157,7 @@
|
|
|
*****************************************************************************/
|
|
|
|
|
|
/** DOCDOC */
|
|
|
-STATIC const scheduler_t *the_scheduler;
|
|
|
+STATIC const scheduler_t *the_scheduler = NULL;
|
|
|
|
|
|
/**
|
|
|
* We keep a list of channels that are pending - i.e, have cells to write
|
|
@@ -602,15 +604,26 @@ scheduler_ev_active(void)
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- * Initialize everything scheduling-related from config.c. Note this is only
|
|
|
- * called when Tor is starting up, while scheduler_t->init() is called both
|
|
|
- * when Tor is starting up and when we are switching schedulers.
|
|
|
+ * Initialize any global memory needed by the scheduler. In order to use the
|
|
|
+ * scheduler, you must still tell it when the configuration from config.c is
|
|
|
+ * ready with scheduler_conf_changed(), and attach the mainloop event with
|
|
|
+ * scheduler_attach_mainloop(). Note this is only called when Tor is starting
|
|
|
+ * up, while scheduler_t->init() is called when we are switching schedulers.
|
|
|
*/
|
|
|
void
|
|
|
scheduler_init(void)
|
|
|
{
|
|
|
- log_debug(LD_SCHED, "Initting scheduler");
|
|
|
+ log_debug(LD_SCHED, "Initting scheduler memory");
|
|
|
|
|
|
+ channels_pending = smartlist_new();
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * Create and attach a new mainloop event.
|
|
|
+ */
|
|
|
+void
|
|
|
+scheduler_attach_mainloop(void)
|
|
|
+{
|
|
|
// Two '!' because we really do want to check if the pointer is non-NULL
|
|
|
IF_BUG_ONCE(!!run_sched_ev) {
|
|
|
log_warn(LD_SCHED, "We should not already have a libevent scheduler event."
|
|
@@ -619,9 +632,6 @@ scheduler_init(void)
|
|
|
run_sched_ev = NULL;
|
|
|
}
|
|
|
run_sched_ev = mainloop_event_new(scheduler_evt_callback, NULL);
|
|
|
- channels_pending = smartlist_new();
|
|
|
-
|
|
|
- set_scheduler();
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -766,3 +776,24 @@ scheduler_touch_channel(channel_t *chan)
|
|
|
}
|
|
|
|
|
|
#endif /* defined(TOR_UNIT_TESTS) */
|
|
|
+
|
|
|
+static int
|
|
|
+subsys_scheduler_initialize(void)
|
|
|
+{
|
|
|
+ scheduler_init();
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+static void
|
|
|
+subsys_scheduler_shutdown(void)
|
|
|
+{
|
|
|
+ scheduler_free_all();
|
|
|
+}
|
|
|
+
|
|
|
+const struct subsys_fns_t sys_scheduler = {
|
|
|
+ .name = "scheduler",
|
|
|
+ .supported = true,
|
|
|
+ .level = 10,
|
|
|
+ .initialize = subsys_scheduler_initialize,
|
|
|
+ .shutdown = subsys_scheduler_shutdown,
|
|
|
+};
|