mirror of
https://github.com/matrix-construct/construct
synced 2025-01-14 00:34:18 +01:00
ircd::ctx::pool: Add wouldblock() convenience to interface.
This commit is contained in:
parent
becc51af01
commit
e2ed860c04
2 changed files with 15 additions and 7 deletions
|
@ -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&&...);
|
||||
|
|
21
ircd/ctx.cc
21
ircd/ctx.cc
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue