0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 18:18:56 +02:00

ircd::ctx::pool: Add wouldblock() convenience to interface.

This commit is contained in:
Jason Volk 2019-09-18 20:03:24 -07:00
parent becc51af01
commit e2ed860c04
2 changed files with 15 additions and 7 deletions

View file

@ -47,6 +47,7 @@ struct ircd::ctx::pool
auto active() const { return working; }
auto avail() const { return running - active(); }
auto pending() const { return active() + queued(); }
bool wouldblock() const;
// dispatch to pool
template<class F, class... A> future_void<F, A...> async(F&&, A&&...);

View file

@ -1476,13 +1476,7 @@ ircd::ctx::pool::operator()(closure closure)
if(current && opt->queue_max_soft >= 0 && opt->queue_max_blocking)
q_max.wait([this]
{
if(q.size() < size_t(opt->queue_max_soft))
return true;
if(!opt->queue_max_soft && q.size() < avail())
return true;
return false;
return !wouldblock();
});
if(unlikely(q.size() >= size_t(opt->queue_max_hard)))
@ -1501,6 +1495,19 @@ ircd::ctx::pool::operator()(closure closure)
q.push(std::move(closure));
}
bool
ircd::ctx::pool::wouldblock()
const
{
if(q.size() < size_t(opt->queue_max_soft))
return false;
if(!opt->queue_max_soft && q.size() < avail())
return false;
return true;
}
/// Main execution loop for a pool.
void
ircd::ctx::pool::main()