diff --git a/include/ircd/ctx/parallel.h b/include/ircd/ctx/parallel.h index 529b701e4..3cb3878d3 100644 --- a/include/ircd/ctx/parallel.h +++ b/include/ircd/ctx/parallel.h @@ -33,7 +33,6 @@ struct ircd::ctx::parallel void rethrow_any_exception(); void receiver() noexcept; void sender() noexcept; - void sender(const arg &a) noexcept; public: void wait_avail(); @@ -43,6 +42,8 @@ struct ircd::ctx::parallel void operator()(const arg &a); parallel(pool &, const vector_view &, closure); + parallel(parallel &&) = delete; + parallel(const parallel &) = delete; ~parallel() noexcept; }; @@ -70,8 +71,11 @@ void ircd::ctx::parallel::operator()(const arg &a) { rethrow_any_exception(); - sender(a); + assert(snd < this->a.size()); + this->a.at(snd) = a; + sender(); wait_avail(); + assert(out < this->a.size()); } template @@ -81,27 +85,7 @@ ircd::ctx::parallel::operator()() rethrow_any_exception(); sender(); wait_avail(); -} - -template -void -ircd::ctx::parallel::sender(const arg &a) -noexcept -{ - auto &p(*this->p); - auto func - { - std::bind(¶llel::receiver, this) - }; - - this->a.at(snd++) = a; - snd %= this->a.size(); - out++; - - if(likely(p.size())) - p(std::move(func)); - else - func(); + assert(out < this->a.size()); } template @@ -109,16 +93,18 @@ void ircd::ctx::parallel::sender() noexcept { + ++snd; + snd %= this->a.size(); + + ++out; + assert(out <= this->a.size()); + auto &p(*this->p); auto func { std::bind(¶llel::receiver, this) }; - snd++; - snd %= this->a.size(); - out++; - if(likely(p.size())) p(std::move(func)); else @@ -130,8 +116,8 @@ void ircd::ctx::parallel::receiver() noexcept { - auto &a(this->a.at(rcv % this->a.size())); - rcv++; + auto &a{this->a.at(rcv % this->a.size())}; + ++rcv; if(!this->eptr) try { @@ -142,7 +128,9 @@ noexcept this->eptr = std::current_exception(); } - out--; + assert(out <= this->a.size()); + assert(out > 0); + --out; d.notify_one(); }