MXS-2218 Run MainWorker in main thread

The previous main routing worker is now run in a separate thread.
Next step is to treat all routing workers in an identical fashion.
MainWorker is not yet used for anything, but in a subsequent change
the old housekeeper functionality will be moved in top of MainWorker.
This commit is contained in:
Johan Wikman
2019-01-07 16:12:49 +02:00
parent 92306c565b
commit 35dfa05767

View File

@ -51,6 +51,7 @@
#include <maxscale/adminusers.h> #include <maxscale/adminusers.h>
#include <maxscale/dcb.hh> #include <maxscale/dcb.hh>
#include <maxscale/housekeeper.h> #include <maxscale/housekeeper.h>
#include <maxscale/mainworker.hh>
#include <maxscale/maxscale.h> #include <maxscale/maxscale.h>
#include <maxscale/mysql_utils.hh> #include <maxscale/mysql_utils.hh>
#include <maxscale/paths.h> #include <maxscale/paths.h>
@ -150,6 +151,7 @@ static bool log_to_shm_configured = false;
static volatile sig_atomic_t last_signal = 0; static volatile sig_atomic_t last_signal = 0;
static bool unload_modules_at_exit = true; static bool unload_modules_at_exit = true;
static std::string redirect_output_to; static std::string redirect_output_to;
static maxscale::MainWorker* main_worker = nullptr;
static int cnf_preparser(void* data, const char* section, const char* name, const char* value); static int cnf_preparser(void* data, const char* section, const char* name, const char* value);
static int write_pid_file(); /* write MaxScale pidfile */ static int write_pid_file(); /* write MaxScale pidfile */
@ -351,6 +353,11 @@ static void sigterm_handler(int i)
if (n_shutdowns == 1) if (n_shutdowns == 1)
{ {
if (main_worker)
{
main_worker->shutdown();
}
if (!daemon_mode) if (!daemon_mode)
{ {
if (write(STDERR_FILENO, shutdown_msg, sizeof(shutdown_msg) - 1) == -1) if (write(STDERR_FILENO, shutdown_msg, sizeof(shutdown_msg) - 1) == -1)
@ -372,6 +379,11 @@ static void sigint_handler(int i)
if (n_shutdowns == 1) if (n_shutdowns == 1)
{ {
if (main_worker)
{
main_worker->shutdown();
}
if (!daemon_mode) if (!daemon_mode)
{ {
if (write(STDERR_FILENO, shutdown_msg, sizeof(shutdown_msg) - 1) == -1) if (write(STDERR_FILENO, shutdown_msg, sizeof(shutdown_msg) - 1) == -1)
@ -2059,6 +2071,7 @@ int main(int argc, char** argv)
} }
// Initialize the housekeeper // Initialize the housekeeper
main_worker = new maxscale::MainWorker;
if (!hkinit()) if (!hkinit())
{ {
const char* logerr = "Failed to initialize housekeeper"; const char* logerr = "Failed to initialize housekeeper";
@ -2266,10 +2279,9 @@ int main(int argc, char** argv)
goto return_main; goto return_main;
} }
/*< worker->start();
* Run worker 0 in the main thread.
*/ main_worker->run();
worker->run();
/** Stop administrative interface */ /** Stop administrative interface */
mxs_admin_shutdown(); mxs_admin_shutdown();
@ -2285,6 +2297,7 @@ int main(int argc, char** argv)
*/ */
hkfinish(); hkfinish();
worker->join();
/*< /*<
* Wait for worker threads to exit. * Wait for worker threads to exit.
*/ */
@ -2347,6 +2360,9 @@ return_main:
config_finish(); config_finish();
delete main_worker;
main_worker = nullptr;
return rc; return rc;
} /*< End of main */ } /*< End of main */