From: Alan T. DeKok Date: Tue, 20 Jun 2017 17:05:56 +0000 (-0400) Subject: add event_list_t to scheduler X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d47e2618fa41baea08c184dddc8ad0ef6397fb77;p=thirdparty%2Ffreeradius-server.git add event_list_t to scheduler in preparation for single-threaded mode --- diff --git a/src/lib/io/schedule.c b/src/lib/io/schedule.c index 448ef29ad97..5731dcfc635 100644 --- a/src/lib/io/schedule.c +++ b/src/lib/io/schedule.c @@ -110,6 +110,8 @@ typedef struct fr_schedule_network_t { struct fr_schedule_t { bool running; //!< is the scheduler running? + fr_event_list_t *el; //!< event list for single-threaded mode. + fr_log_t *log; //!< log destination int max_inputs; //!< number of network threads @@ -295,6 +297,7 @@ fail: /** Create a scheduler and spawn the child threads. * * @param[in] ctx the talloc context + * @param[in] el the event list, only for single-threaded mode. * @param[in] logger the destination for all logging messages * @param[in] max_inputs the number of network threads * @param[in] max_workers the number of worker threads @@ -304,7 +307,8 @@ fail: * - NULL on error * - fr_schedule_t new scheduler */ -fr_schedule_t *fr_schedule_create(TALLOC_CTX *ctx, fr_log_t *logger, int max_inputs, int max_workers, +fr_schedule_t *fr_schedule_create(TALLOC_CTX *ctx, fr_event_list_t *el, fr_log_t *logger, + int max_inputs, int max_workers, fr_schedule_thread_instantiate_t worker_thread_instantiate, void *worker_thread_ctx) { @@ -327,6 +331,7 @@ fr_schedule_t *fr_schedule_create(TALLOC_CTX *ctx, fr_log_t *logger, int max_inp return NULL; } + sc->el = el; sc->max_inputs = max_inputs; sc->max_workers = max_workers; sc->num_workers = 0; diff --git a/src/lib/io/schedule.h b/src/lib/io/schedule.h index e818936d368..62f353692ab 100644 --- a/src/lib/io/schedule.h +++ b/src/lib/io/schedule.h @@ -36,9 +36,9 @@ extern "C" { typedef struct fr_schedule_t fr_schedule_t; typedef int (*fr_schedule_thread_instantiate_t)(void *ctx, fr_event_list_t *el); -fr_schedule_t *fr_schedule_create(TALLOC_CTX *ctx, fr_log_t *log, int max_inputs, int max_workers, +fr_schedule_t *fr_schedule_create(TALLOC_CTX *ctx, fr_event_list_t *el, fr_log_t *log, int max_inputs, int max_workers, fr_schedule_thread_instantiate_t worker_thread_instantiate, - void *worker_thread_ctx); + void *worker_thread_ctx) CC_HINT(nonnull(3)); /* schedulers are async, so there's no fr_schedule_run() */ int fr_schedule_destroy(fr_schedule_t *sc); diff --git a/src/main/radiusd.c b/src/main/radiusd.c index b0b82292bd8..a46bcd2c08b 100644 --- a/src/main/radiusd.c +++ b/src/main/radiusd.c @@ -585,7 +585,21 @@ int main(int argc, char *argv[]) * async listeners, then we open the sockets. */ if (!check_config && main_config.namespace) { - sc = fr_schedule_create(NULL, &default_log, 1, 4, (fr_schedule_thread_instantiate_t) modules_thread_instantiate, + int networks = 1; + int workers = 4; + fr_event_list_t *el = NULL; + + if (!main_config.spawn_workers) { + networks = 0; + workers = 0; + el = process_global_event_list(EVENT_CORRAL_MAIN); + } + + /* + * @todo - fix this once the scheduler supports single-threaded mode + */ + sc = fr_schedule_create(NULL, NULL, &default_log, 1, 4, + (fr_schedule_thread_instantiate_t) modules_thread_instantiate, main_config.config); if (!sc) { exit(EXIT_FAILURE); diff --git a/src/tests/util/radius_schedule_test.c b/src/tests/util/radius_schedule_test.c index bf9625ac48e..c40455ee11e 100644 --- a/src/tests/util/radius_schedule_test.c +++ b/src/tests/util/radius_schedule_test.c @@ -269,7 +269,7 @@ int main(int argc, char *argv[]) app_io_inst->ipaddr = my_ipaddr; app_io_inst->port = my_port; - sched = fr_schedule_create(autofree, &default_log, num_networks, num_workers, NULL, NULL); + sched = fr_schedule_create(autofree, NULL, &default_log, num_networks, num_workers, NULL, NULL); if (!sched) { fprintf(stderr, "schedule_test: Failed to create scheduler\n"); exit(1); diff --git a/src/tests/util/schedule_test.c b/src/tests/util/schedule_test.c index 33590096242..5447ee7fbda 100644 --- a/src/tests/util/schedule_test.c +++ b/src/tests/util/schedule_test.c @@ -91,7 +91,7 @@ int main(int argc, char *argv[]) argv += (optind - 1); #endif - sched = fr_schedule_create(autofree, &default_log, num_networks, num_workers, NULL, NULL); + sched = fr_schedule_create(autofree, NULL, &default_log, num_networks, num_workers, NULL, NULL); if (!sched) { fprintf(stderr, "schedule_test: Failed to create scheduler\n"); exit(1);