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

ircd::ctx: Improve the spawn sequence to avoid complications.

This commit is contained in:
Jason Volk 2017-11-01 15:56:40 -07:00
parent 570f4d7f54
commit 26800d5db4

View file

@ -549,25 +549,30 @@ 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]
{
if(flags & DETACH)
this->c.release();
}};
if(flags & POST)
{
ios->post(std::move(spawn));
return;
}
// 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();
}
if(flags & DETACH)
c.release();
}
ircd::ctx::context::context(const char *const &name,
const size_t &stack_size,
function func,