From 26800d5db4a4e3ee4d5b5732011bb122682fbc63 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 1 Nov 2017 15:56:40 -0700 Subject: [PATCH] ircd::ctx: Improve the spawn sequence to avoid complications. --- ircd/ctx.cc | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/ircd/ctx.cc b/ircd/ctx.cc index 7f04c85d6..6ecc02cfb 100644 --- a/ircd/ctx.cc +++ b/ircd/ctx.cc @@ -549,23 +549,28 @@ ircd::ctx::context::context(const char *const &name, std::bind(&ircd::ctx::spawn, c.get(), std::move(func)) }; - if(flags & POST) - ios->post(std::move(spawn)); - else if(flags & DISPATCH) - ios->dispatch(std::move(spawn)); - else + const unwind release{[this, &flags] { - // The current context must be reasserted if spawn returns here - const unwind recurrent([current(ircd::ctx::current)] - { - ircd::ctx::current = current; - }); + if(flags & DETACH) + this->c.release(); + }}; - spawn(); + if(flags & POST) + { + ios->post(std::move(spawn)); + return; } - if(flags & DETACH) - c.release(); + // The current context must be reasserted if spawn returns here + const unwind recurrent([current(ircd::ctx::current)] + { + ircd::ctx::current = current; + }); + + if(flags & DISPATCH) + ios->dispatch(std::move(spawn)); + else + spawn(); } ircd::ctx::context::context(const char *const &name,