Add shutdown detection

The maxscale_is_shutting_down function is used to detect when MaxScale
should stop. This fixes a race condition in the code where the workers has
not yet been initialized but a termination signal has been received. It
also replaces the misuse of the service_should_stop variable with a proper
function.
This commit is contained in:
Markus Mäkelä
2018-08-23 23:22:27 +03:00
parent 8f3eabb868
commit 8b653133a7
8 changed files with 43 additions and 19 deletions

View File

@ -36,15 +36,19 @@ int maxscale_uptime()
return time(0) - started;
}
static sig_atomic_t n_shutdowns = 0;
bool maxscale_is_shutting_down()
{
return n_shutdowns != 0;
}
int maxscale_shutdown()
{
static int n_shutdowns = 0;
int n = atomic_add(&n_shutdowns, 1);
int n = n_shutdowns++;
if (n == 0)
{
service_shutdown();
mxs::RoutingWorker::shutdown_all();
}