From 734dbfa590baf560741f0754bd81c07dfb829485 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Thu, 14 Sep 2017 14:47:59 -0400 Subject: 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 --- src/or/scheduler_vanilla.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'src/or/scheduler_vanilla.c') diff --git a/src/or/scheduler_vanilla.c b/src/or/scheduler_vanilla.c index 541ee80060..09653f445e 100644 --- a/src/or/scheduler_vanilla.c +++ b/src/or/scheduler_vanilla.c @@ -17,9 +17,6 @@ /* Maximum cells to flush in a single call to channel_flush_some_cells(); */ #define MAX_FLUSH_CELLS 1000 -/* Stores the vanilla scheduler function pointers. */ -static scheduler_t *vanilla_scheduler = NULL; - /***************************************************************************** * Externally called function implementations *****************************************************************************/ @@ -180,20 +177,20 @@ vanilla_scheduler_run(void) n_chans_before - n_chans_after, n_chans_before); } +/* Stores the vanilla scheduler function pointers. */ +static scheduler_t vanilla_scheduler = { + .free_all = NULL, + .on_channel_free = NULL, + .init = NULL, + .on_new_consensus = NULL, + .schedule = vanilla_scheduler_schedule, + .run = vanilla_scheduler_run, + .on_new_options = NULL, +}; + scheduler_t * get_vanilla_scheduler(void) { - if (!vanilla_scheduler) { - log_debug(LD_SCHED, "Initializing vanilla scheduler struct"); - vanilla_scheduler = tor_malloc_zero(sizeof(*vanilla_scheduler)); - vanilla_scheduler->free_all = NULL; - vanilla_scheduler->on_channel_free = NULL; - vanilla_scheduler->init = NULL; - vanilla_scheduler->on_new_consensus = NULL; - vanilla_scheduler->schedule = vanilla_scheduler_schedule; - vanilla_scheduler->run = vanilla_scheduler_run; - vanilla_scheduler->on_new_options = NULL; - } - return vanilla_scheduler; + return &vanilla_scheduler; } -- cgit v1.2.3-54-g00ecf