mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 02:02:38 +01:00
ircd::ctx: Remove the cv_status enum.
This commit is contained in:
parent
275fe9d957
commit
26b33a1845
5 changed files with 29 additions and 27 deletions
|
@ -14,7 +14,6 @@
|
|||
namespace ircd::ctx
|
||||
{
|
||||
struct dock;
|
||||
enum class cv_status;
|
||||
}
|
||||
|
||||
/// dock is a condition variable which has no requirement for locking because
|
||||
|
@ -31,10 +30,10 @@ class ircd::ctx::dock
|
|||
size_t size() const;
|
||||
|
||||
template<class time_point, class predicate> bool wait_until(time_point&& tp, predicate&& pred);
|
||||
template<class time_point> cv_status wait_until(time_point&& tp);
|
||||
template<class time_point> bool wait_until(time_point&& tp);
|
||||
|
||||
template<class duration, class predicate> bool wait_for(const duration &dur, predicate&& pred);
|
||||
template<class duration> cv_status wait_for(const duration &dur);
|
||||
template<class duration> bool wait_for(const duration &dur);
|
||||
|
||||
template<class predicate> void wait(predicate&& pred);
|
||||
void wait();
|
||||
|
@ -44,11 +43,6 @@ class ircd::ctx::dock
|
|||
void notify() noexcept;
|
||||
};
|
||||
|
||||
enum class ircd::ctx::cv_status
|
||||
{
|
||||
no_timeout, timeout
|
||||
};
|
||||
|
||||
/// Wake up the next context waiting on the dock
|
||||
///
|
||||
/// Unlike notify_one(), the next context in the queue is repositioned in the
|
||||
|
@ -122,8 +116,9 @@ ircd::ctx::dock::wait(predicate&& pred)
|
|||
while(!pred());
|
||||
}
|
||||
|
||||
/// Returns true if notified; false if timed out
|
||||
template<class duration>
|
||||
ircd::ctx::cv_status
|
||||
bool
|
||||
ircd::ctx::dock::wait_for(const duration &dur)
|
||||
{
|
||||
static const duration zero(0);
|
||||
|
@ -135,10 +130,10 @@ ircd::ctx::dock::wait_for(const duration &dur)
|
|||
}};
|
||||
|
||||
q.push_back(current);
|
||||
return ircd::ctx::wait<std::nothrow_t>(dur) > zero? cv_status::no_timeout:
|
||||
cv_status::timeout;
|
||||
return ircd::ctx::wait<std::nothrow_t>(dur) > zero;
|
||||
}
|
||||
|
||||
/// Returns true if predicate passed; false if timed out
|
||||
template<class duration,
|
||||
class predicate>
|
||||
bool
|
||||
|
@ -169,8 +164,9 @@ ircd::ctx::dock::wait_for(const duration &dur,
|
|||
while(1);
|
||||
}
|
||||
|
||||
/// Returns true if notified; false if timed out
|
||||
template<class time_point>
|
||||
ircd::ctx::cv_status
|
||||
bool
|
||||
ircd::ctx::dock::wait_until(time_point&& tp)
|
||||
{
|
||||
assert(current);
|
||||
|
@ -180,10 +176,10 @@ ircd::ctx::dock::wait_until(time_point&& tp)
|
|||
}};
|
||||
|
||||
q.push_back(current);
|
||||
return ircd::ctx::wait_until<std::nothrow_t>(tp)? cv_status::timeout:
|
||||
cv_status::no_timeout;
|
||||
return !ircd::ctx::wait_until<std::nothrow_t>(tp);
|
||||
}
|
||||
|
||||
/// Returns true if predicate passed; false if timed out
|
||||
template<class time_point,
|
||||
class predicate>
|
||||
bool
|
||||
|
|
|
@ -96,13 +96,16 @@ template<class duration>
|
|||
T
|
||||
ircd::ctx::queue<T>::pop_for(const duration &dur)
|
||||
{
|
||||
const auto status(dock.wait_for(dur, [this]
|
||||
const bool ready
|
||||
{
|
||||
return !q.empty();
|
||||
}));
|
||||
dock.wait_for(dur, [this]
|
||||
{
|
||||
return !q.empty();
|
||||
})
|
||||
};
|
||||
|
||||
if(status == cv_status::timeout)
|
||||
throw timeout();
|
||||
if(!ready)
|
||||
throw timeout{};
|
||||
|
||||
const unwind pop([this]
|
||||
{
|
||||
|
@ -118,13 +121,16 @@ template<class time_point>
|
|||
T
|
||||
ircd::ctx::queue<T>::pop_until(time_point&& tp)
|
||||
{
|
||||
const auto status(dock.wait_until(tp, [this]
|
||||
const bool ready
|
||||
{
|
||||
return !q.empty();
|
||||
}));
|
||||
dock.wait_until(tp, [this]
|
||||
{
|
||||
return !q.empty();
|
||||
})
|
||||
};
|
||||
|
||||
if(status == cv_status::timeout)
|
||||
throw timeout();
|
||||
if(!ready)
|
||||
throw timeout{};
|
||||
|
||||
const unwind pop([this]
|
||||
{
|
||||
|
|
|
@ -145,7 +145,7 @@ ircd::client::wait_all()
|
|||
context.join();
|
||||
while(!client::list.empty())
|
||||
{
|
||||
if(dock.wait_for(seconds(2)) == ctx::cv_status::no_timeout)
|
||||
if(dock.wait_for(seconds(2)))
|
||||
continue;
|
||||
|
||||
log::warning
|
||||
|
|
|
@ -21,7 +21,7 @@ void
|
|||
ircd::net::wait_close_sockets()
|
||||
{
|
||||
while(socket::instances)
|
||||
if(dock.wait_for(seconds(2)) != ctx::cv_status::no_timeout)
|
||||
if(!dock.wait_for(seconds(2)))
|
||||
log.warning("Waiting for %zu sockets to destruct",
|
||||
socket::instances);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ ircd::server::wait_all()
|
|||
{
|
||||
while(peer_unfinished())
|
||||
{
|
||||
if(dock.wait_for(seconds(2)) == ctx::cv_status::no_timeout)
|
||||
if(dock.wait_for(seconds(2)))
|
||||
continue;
|
||||
|
||||
log.warning("Waiting for %zu tags on %zu links on %zu of %zu peers to close...",
|
||||
|
|
Loading…
Reference in a new issue