summaryrefslogtreecommitdiff
path: root/src/or/scheduler_kist.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2017-09-14 14:47:59 -0400
committerDavid Goulet <dgoulet@torproject.org>2017-09-15 11:40:59 -0400
commit734dbfa590baf560741f0754bd81c07dfb829485 (patch)
tree4cf32837fd3823ac53b4244e6aab794a4a6eec46 /src/or/scheduler_kist.c
parentbd34a0d30f754f3dd75199d915febe918d058f30 (diff)
downloadtor-734dbfa590baf560741f0754bd81c07dfb829485.tar.gz
tor-734dbfa590baf560741f0754bd81c07dfb829485.zip
sched: Make the scheduler object static
Each type of scheduler implements its own static scheduler_t object and returns a reference to it. This commit also makes it a const pointer that is it can only change inside the scheduler type subsystem but not outside for extra protection. Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/or/scheduler_kist.c')
-rw-r--r--src/or/scheduler_kist.c26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/or/scheduler_kist.c b/src/or/scheduler_kist.c
index f35d0fae57..262d618160 100644
--- a/src/or/scheduler_kist.c
+++ b/src/or/scheduler_kist.c
@@ -103,8 +103,6 @@ static monotime_t scheduler_last_run;
static double sock_buf_size_factor = 1.0;
/* How often the scheduler runs. */
STATIC int32_t sched_run_interval = 10;
-/* Stores the kist scheduler function pointers. */
-static scheduler_t *kist_scheduler = NULL;
/*****************************************************************************
* Internally called function implementations
@@ -637,23 +635,23 @@ kist_scheduler_run(void)
* Externally called function implementations not called through scheduler_t
*****************************************************************************/
+/* Stores the kist scheduler function pointers. */
+static scheduler_t kist_scheduler = {
+ .free_all = kist_free_all,
+ .on_channel_free = kist_on_channel_free,
+ .init = kist_scheduler_init,
+ .on_new_consensus = kist_scheduler_on_new_consensus,
+ .schedule = kist_scheduler_schedule,
+ .run = kist_scheduler_run,
+ .on_new_options = kist_scheduler_on_new_options,
+};
+
/* Return the KIST scheduler object. If it didn't exists, return a newly
* allocated one but init() is not called. */
scheduler_t *
get_kist_scheduler(void)
{
- if (!kist_scheduler) {
- log_debug(LD_SCHED, "Allocating kist scheduler struct");
- kist_scheduler = tor_malloc_zero(sizeof(*kist_scheduler));
- kist_scheduler->free_all = kist_free_all;
- kist_scheduler->on_channel_free = kist_on_channel_free;
- kist_scheduler->init = kist_scheduler_init;
- kist_scheduler->on_new_consensus = kist_scheduler_on_new_consensus;
- kist_scheduler->schedule = kist_scheduler_schedule;
- kist_scheduler->run = kist_scheduler_run;
- kist_scheduler->on_new_options = kist_scheduler_on_new_options;
- }
- return kist_scheduler;
+ return &kist_scheduler;
}
/* Check the torrc for the configured KIST scheduler run interval.