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
23
ircd/ctx.cc
23
ircd/ctx.cc
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue