0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-15 14:31:11 +01:00

ircd::ctx: Detach context in dtor on main/async stacks.

This commit is contained in:
Jason Volk 2018-05-28 03:12:11 -07:00
parent 1f92aee9dd
commit c8902654a0

View file

@ -889,14 +889,12 @@ ircd::ctx::context::context(function func,
ircd::ctx::context::~context() ircd::ctx::context::~context()
noexcept noexcept
{ {
if(!c)
return;
// Can't join to bare metal, only from within another context. // Can't join to bare metal, only from within another context.
if(current) if(c && current)
{ {
interrupt(); interrupt();
join(); join();
return;
} }
// because *this uses unique_ptr's, if we dtor the ircd::ctx from // because *this uses unique_ptr's, if we dtor the ircd::ctx from
@ -905,8 +903,17 @@ noexcept
// queue. // queue.
if(c && !started(*c)) if(c && !started(*c))
{ {
c->flags |= context::DETACH; detach();
c.release(); return;
}
// When this is bare metal the above join branch will not have been
// taken. In that case we should detach the context so it frees itself,
// but only if the context has not already finished.
if(c && !current && !finished(*c))
{
detach();
return;
} }
} }