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:
parent
570f4d7f54
commit
26800d5db4
1 changed files with 18 additions and 13 deletions
31
ircd/ctx.cc
31
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,
|
||||
|
|
Loading…
Reference in a new issue