From c8902654a0abd300f2cf1b9c58019f44a9469393 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 28 May 2018 03:12:11 -0700 Subject: [PATCH] ircd::ctx: Detach context in dtor on main/async stacks. --- ircd/ctx.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ircd/ctx.cc b/ircd/ctx.cc index 2bec90d50..a7dee2e6e 100644 --- a/ircd/ctx.cc +++ b/ircd/ctx.cc @@ -889,14 +889,12 @@ ircd::ctx::context::context(function func, ircd::ctx::context::~context() noexcept { - if(!c) - return; - // Can't join to bare metal, only from within another context. - if(current) + if(c && current) { interrupt(); join(); + return; } // because *this uses unique_ptr's, if we dtor the ircd::ctx from @@ -905,8 +903,17 @@ noexcept // queue. if(c && !started(*c)) { - c->flags |= context::DETACH; - c.release(); + detach(); + 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; } }