0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-17 17:38:22 +02:00

ircd::ctx: Test for valid then() before calling from here.

This commit is contained in:
Jason Volk 2018-08-28 18:56:41 -07:00
parent 231c95f29e
commit 76e48b3ef3
3 changed files with 33 additions and 6 deletions

View file

@ -18,7 +18,7 @@ namespace ircd::ctx
template<> struct shared_state<void>;
template<class T> struct promise;
template<> struct promise<void>;
enum class future_state;
enum class future_state :uintptr_t;
template<class T> future_state state(const shared_state<T> &);
template<class T> bool is(const shared_state<T> &, const future_state &);
@ -31,8 +31,9 @@ namespace ircd::ctx
/// all be observed through state() or is(); only some can be set(). This is
/// not for public manipulation.
enum class ircd::ctx::future_state
:uintptr_t
{
INVALID, ///< Null.
INVALID = 0, ///< Null.
PENDING, ///< Promise is attached and busy.
READY, ///< Result ready; promise is gone.
OBSERVED, ///< Special case for when_*(); not a state; promise is gone.
@ -47,6 +48,13 @@ struct ircd::ctx::shared_state_base
mutable dock cond;
std::exception_ptr eptr;
std::function<void (shared_state_base &)> then;
shared_state_base();
shared_state_base(shared_state_base &&) = default;
shared_state_base(const shared_state_base &) = delete;
shared_state_base &operator=(shared_state_base &&) = default;
shared_state_base &operator=(const shared_state_base &) = delete;
~shared_state_base() noexcept;
};
/// Internal shared state between future and promise appropos a future value.

View file

@ -45,9 +45,10 @@ ircd::ctx::when_all(it first,
[&p](it &f)
{
state(*f).then = [p]
(shared_state_base &) mutable
(shared_state_base &sb) mutable
{
then(p);
if(sb.then)
then(p);
};
}
};
@ -96,9 +97,10 @@ ircd::ctx::when_any(it first,
[&p](it &f)
{
state(*f).then = [p, f] // alloc
(shared_state_base &) mutable
(shared_state_base &sb) mutable
{
then(p, f);
if(sb.then)
then(p, f);
};
}
};

View file

@ -1477,6 +1477,23 @@ ircd::ctx::ole::pop()
return std::move(c);
}
///////////////////////////////////////////////////////////////////////////////
//
// ctx/shared_shared.h
//
// Linkage
ircd::ctx::shared_state_base::shared_state_base()
{
}
// Linkage
ircd::ctx::shared_state_base::~shared_state_base()
noexcept
{
then = {};
}
///////////////////////////////////////////////////////////////////////////////
//
// ctx_list.h