0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 16:22:35 +01:00

ircd: Add synchronization for runlevel changes.

This commit is contained in:
Jason Volk 2018-12-04 15:25:15 -08:00
parent c75ccd5a1c
commit d6241c66de

View file

@ -288,10 +288,18 @@ try
ircd::_runlevel = new_runlevel;
ircd::runlevel_changed::dock.notify_all();
// This latch is used to block this call when setting the runlevel
// from an ircd::ctx. If the runlevel is set from the main stack then
// the caller will have to do synchronization themselves.
ctx::latch latch
{
bool(ctx::current) // latch has count of 1 if we're on an ircd::ctx
};
// This function will notify the user of the change to IRCd. When there
// are listeners, function is posted to the io_context ensuring THERE IS
// NO CONTINUATION ON THIS STACK by the user.
const auto call_users{[new_runlevel]
const auto call_users{[new_runlevel, &latch, latching(!latch.is_ready())]
{
assert(new_runlevel == ircd::_runlevel);
@ -307,13 +315,19 @@ try
for(const auto &handler : ircd::runlevel_changed::list)
(*handler)(new_runlevel);
if(latching)
latch.count_down();
}};
if(!ircd::runlevel_changed::list.empty())
if(ircd::runlevel_changed::list.size())
ircd::post(call_users);
else
call_users();
if(ctx::current)
latch.wait();
return true;
}
catch(const std::exception &e)