mirror of
https://github.com/matrix-construct/construct
synced 2024-09-26 02:18:53 +02:00
construct: Fix exception propagation; interrupt masking during runlevel change.
This commit is contained in:
parent
676e657368
commit
6da204b063
2 changed files with 17 additions and 16 deletions
|
@ -210,13 +210,12 @@ noexcept try
|
|||
// different contexts.
|
||||
ircd::ctx::latch start(2), quit(2);
|
||||
std::exception_ptr eptr;
|
||||
bool rethrow {false};
|
||||
|
||||
// Setup the matrix homeserver application. This will be executed on an
|
||||
// ircd::context (dedicated stack). We construct several objects on the
|
||||
// stack which are the basis for our matrix homeserver. When the stack
|
||||
// unwinds, the homeserver will go out of service.
|
||||
const auto homeserver{[&origin, &server_name, &start, &quit, &eptr, &rethrow]
|
||||
const auto homeserver{[&origin, &server_name, &start, &quit, &eptr]
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -240,8 +239,6 @@ noexcept try
|
|||
}
|
||||
};
|
||||
|
||||
rethrow = true;
|
||||
|
||||
// 7 Notify the loader the homeserver is ready for service.
|
||||
start.count_down_and_wait();
|
||||
|
||||
|
@ -276,7 +273,7 @@ noexcept try
|
|||
// to start and stop the homeserver.
|
||||
const ircd::run::changed loader
|
||||
{
|
||||
[&homeserver, &start, &quit, &eptr, &rethrow](const auto &level)
|
||||
[&homeserver, &start, &quit, &eptr](const auto &level)
|
||||
{
|
||||
static ircd::context context;
|
||||
|
||||
|
@ -295,10 +292,8 @@ noexcept try
|
|||
|
||||
// 8 Check if error on start; rethrowing that here propagates
|
||||
// to ircd::main() and triggers a runlevel QUIT sequence.
|
||||
if(!!eptr && rethrow)
|
||||
if(!!eptr)
|
||||
std::rethrow_exception(eptr);
|
||||
else if(!!eptr)
|
||||
ircd::quit();
|
||||
|
||||
// 8.1
|
||||
return;
|
||||
|
|
22
ircd/ircd.cc
22
ircd/ircd.cc
|
@ -264,8 +264,8 @@ noexcept
|
|||
return true;
|
||||
}
|
||||
|
||||
case run::level::LOAD:
|
||||
case run::level::START:
|
||||
case run::level::LOAD:
|
||||
{
|
||||
ctx::terminate(*main_context);
|
||||
main_context = nullptr;
|
||||
|
@ -349,8 +349,10 @@ noexcept try
|
|||
|
||||
// When this function is entered IRCd will transition to START indicating
|
||||
// that subsystems are initializing.
|
||||
run::set(run::level::START);
|
||||
ctx::interruption_point();
|
||||
{
|
||||
const ctx::uninterruptible ui;
|
||||
run::set(run::level::START);
|
||||
}
|
||||
|
||||
// These objects are the init()'s and fini()'s for each subsystem.
|
||||
// Appearing here ties their life to the main context. Initialization can
|
||||
|
@ -371,19 +373,23 @@ noexcept try
|
|||
// Transition to the QUIT and UNLOAD states on unwind.
|
||||
const unwind quit{[]
|
||||
{
|
||||
const ctx::uninterruptible::nothrow ui;
|
||||
ircd::run::set(run::level::QUIT);
|
||||
ircd::run::set(run::level::UNLOAD);
|
||||
}};
|
||||
ctx::interruption_point();
|
||||
|
||||
// IRCd will now transition to the LOAD state allowing library user's to
|
||||
// load their applications using the run::changed callback.
|
||||
run::set(run::level::LOAD);
|
||||
ctx::interruption_point();
|
||||
{
|
||||
const ctx::uninterruptible ui;
|
||||
run::set(run::level::LOAD);
|
||||
}
|
||||
|
||||
// IRCd will now transition to the RUN state indicating full functionality.
|
||||
run::set(run::level::RUN);
|
||||
ctx::interruption_point();
|
||||
{
|
||||
const ctx::uninterruptible ui;
|
||||
run::set(run::level::RUN);
|
||||
}
|
||||
|
||||
// This call blocks until the main context is notified or interrupted etc.
|
||||
// Waiting here will hold open this stack with all of the above objects
|
||||
|
|
Loading…
Reference in a new issue