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

ircd:Ⓜ️:init::backfill: Split term() from fini() for blocking joins.

This commit is contained in:
Jason Volk 2022-07-02 19:18:20 -07:00
parent 9768546c1e
commit e2d1e0c3b2
2 changed files with 44 additions and 11 deletions

View file

@ -20,7 +20,10 @@ namespace ircd::m::init
/// Internal use only; do not call
namespace ircd::m::init::backfill
{
void init(), fini() noexcept;
void
init(),
term() noexcept,
fini() noexcept;
}
/// Internal use only; do not call

View file

@ -131,7 +131,7 @@ ircd::m::init::backfill::handle_quit
{
run::level::QUIT, []
{
fini();
term();
}
};
@ -163,30 +163,60 @@ ircd::m::init::backfill::init()
worker_context = context.detach();
}
void
ircd::m::init::backfill::term()
noexcept
{
assert(!worker_pool || worker_context);
if(worker_pool)
{
log::debug
{
log, "Terminating worker pool...",
};
worker_pool->terminate();
}
if(worker_context)
{
log::debug
{
log, "Terminating worker context...",
};
ctx::terminate(*worker_context);
}
}
void
ircd::m::init::backfill::fini()
noexcept
{
term();
if(worker_context)
log::debug
log::dwarning
{
log, "Terminating worker context..."
log, "Waiting for worker context...",
};
if(worker_pool)
worker_pool->terminate();
while(worker_context)
ctx::sleep(333ms);
if(worker_context)
ctx::terminate(*worker_context);
worker_context = nullptr;
worker_pool = nullptr;
assert(!worker_pool);
assert(!worker_context);
}
void
ircd::m::init::backfill::worker()
try
{
const unwind nullify{[]
{
worker_context = nullptr;
}};
// Wait for runlevel RUN before proceeding...
run::barrier<ctx::interrupted>{};