0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 00:32:35 +01:00

ircd::ctx: Add this non-standard finished() observer for now.

This commit is contained in:
Jason Volk 2018-01-16 22:43:33 -08:00
parent b9fe5c69ad
commit 8366c735b4

View file

@ -45,6 +45,7 @@ class ircd::ctx::promise
using reference_type = typename shared_state<T>::reference_type; using reference_type = typename shared_state<T>::reference_type;
bool valid() const { return bool(st); } bool valid() const { return bool(st); }
bool finished() const { return !valid() || st->finished; }
bool operator!() const { return !valid(); } bool operator!() const { return !valid(); }
operator bool() const { return valid(); } operator bool() const { return valid(); }
@ -73,6 +74,7 @@ class ircd::ctx::promise<void>
using value_type = typename shared_state<void>::value_type; using value_type = typename shared_state<void>::value_type;
bool valid() const { return bool(st); } bool valid() const { return bool(st); }
bool finished() const { return !valid() || st->finished; }
bool operator!() const { return !valid(); } bool operator!() const { return !valid(); }
operator bool() const { return valid(); } operator bool() const { return valid(); }
@ -162,6 +164,7 @@ template<class T>
void void
ircd::ctx::promise<T>::set_value(T&& val) ircd::ctx::promise<T>::set_value(T&& val)
{ {
assert(!finished());
st->val = std::move(val); st->val = std::move(val);
st->finished = true; st->finished = true;
st->cond.notify_all(); st->cond.notify_all();
@ -170,6 +173,7 @@ ircd::ctx::promise<T>::set_value(T&& val)
inline void inline void
ircd::ctx::promise<void>::set_value() ircd::ctx::promise<void>::set_value()
{ {
assert(!finished());
st->finished = true; st->finished = true;
st->cond.notify_all(); st->cond.notify_all();
} }
@ -178,6 +182,7 @@ template<class T>
void void
ircd::ctx::promise<T>::set_value(const T &val) ircd::ctx::promise<T>::set_value(const T &val)
{ {
assert(!finished());
st->val = val; st->val = val;
st->finished = true; st->finished = true;
st->cond.notify_all(); st->cond.notify_all();
@ -186,6 +191,7 @@ ircd::ctx::promise<T>::set_value(const T &val)
inline void inline void
ircd::ctx::promise<void>::set_exception(std::exception_ptr eptr) ircd::ctx::promise<void>::set_exception(std::exception_ptr eptr)
{ {
assert(!finished());
st->eptr = std::move(eptr); st->eptr = std::move(eptr);
st->finished = true; st->finished = true;
st->cond.notify_all(); st->cond.notify_all();
@ -195,6 +201,7 @@ template<class T>
void void
ircd::ctx::promise<T>::set_exception(std::exception_ptr eptr) ircd::ctx::promise<T>::set_exception(std::exception_ptr eptr)
{ {
assert(!finished());
st->eptr = std::move(eptr); st->eptr = std::move(eptr);
st->finished = true; st->finished = true;
st->cond.notify_all(); st->cond.notify_all();