0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-01-14 16:46:50 +01:00

ircd::ctx::promise: Inline trivial accessors; explicit bool operator.

This commit is contained in:
Jason Volk 2019-08-13 20:43:46 -07:00
parent 42b65fa271
commit 765ec46b91
3 changed files with 46 additions and 44 deletions

View file

@ -80,7 +80,6 @@ struct ircd::ctx::future<void>
bool valid() const { return !is(state(), future_state::INVALID); }
bool operator!() const { return !valid(); }
operator bool() const { return valid(); }
template<class U, class time_point> friend bool wait_until(const future<U> &, const time_point &, std::nothrow_t);
template<class U, class time_point> friend void wait_until(const future<U> &, const time_point &);

View file

@ -47,18 +47,18 @@ struct ircd::ctx::promise_base
shared_state_base *st {nullptr};
mutable promise_base *next {nullptr};
template<class T> const shared_state<T> &state() const;
template<class T> shared_state<T> &state();
const shared_state_base &state() const;
shared_state_base &state();
template<class T> const shared_state<T> &state() const noexcept;
template<class T> shared_state<T> &state() noexcept;
const shared_state_base &state() const noexcept;
shared_state_base &state() noexcept;
void check_pending() const;
void make_ready();
public:
bool valid() const;
operator bool() const;
bool operator!() const;
bool valid() const noexcept;
bool operator!() const noexcept;
explicit operator bool() const noexcept;
void set_exception(std::exception_ptr eptr);
@ -172,9 +172,31 @@ const
// promise_base
//
inline bool
ircd::ctx::promise_base::operator!()
const noexcept
{
return !valid();
}
inline ircd::ctx::promise_base::operator
bool()
const noexcept
{
return valid();
}
inline bool
ircd::ctx::promise_base::valid()
const noexcept
{
return bool(st);
}
template<class T>
ircd::ctx::shared_state<T> &
ircd::ctx::promise_base::state()
noexcept
{
return static_cast<shared_state<T> &>(state());
}
@ -182,7 +204,23 @@ ircd::ctx::promise_base::state()
template<class T>
const ircd::ctx::shared_state<T> &
ircd::ctx::promise_base::state()
const
const noexcept
{
return static_cast<const shared_state<T> &>(state());
}
inline ircd::ctx::shared_state_base &
ircd::ctx::promise_base::state()
noexcept
{
assert(valid());
return *st;
}
inline const ircd::ctx::shared_state_base &
ircd::ctx::promise_base::state()
const noexcept
{
assert(valid());
return *st;
}

View file

@ -2035,41 +2035,6 @@ const
throw promise_already_satisfied{};
}
bool
ircd::ctx::promise_base::operator!()
const
{
return !valid();
}
ircd::ctx::promise_base::operator bool()
const
{
return valid();
}
bool
ircd::ctx::promise_base::valid()
const
{
return bool(st);
}
ircd::ctx::shared_state_base &
ircd::ctx::promise_base::state()
{
assert(valid());
return *st;
}
const ircd::ctx::shared_state_base &
ircd::ctx::promise_base::state()
const
{
assert(valid());
return *st;
}
/// Internal semantics; chases the linked list of promises and adds a reference
/// to a new copy at the end (for copy semantic).
void