0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-27 07:54:05 +01:00

ircd::ctx: yield the promise-notifying ctx until any then() has posted.

This commit is contained in:
Jason Volk 2018-04-07 04:48:45 -07:00
parent db93acf8fb
commit 8d91c90574

View file

@ -104,11 +104,21 @@ ircd::ctx::notify(shared_state<T> &st)
return;
}
ircd::post([&st]
// Need a fresh stack to execute then(), not this ctx's.
ircd::post([&st]() noexcept
{
assert(bool(st.then));
st.cond.notify_all();
st.then(st);
st.then = {};
st.cond.notify_all();
});
// If we don't hold the ctx here then it's too easy to destroy the future
// between now and when then() posts. This is completely effective if the
// future is on this ctx as long as then() itself doesn't hose it.
st.cond.wait([&st]
{
return !bool(st.then);
});
}