0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 23:40:57 +01:00

ircd::ctx::parallel: Ensure the counters are not affected by exceptions.

This commit is contained in:
Jason Volk 2019-01-01 20:39:00 -08:00
parent 7f4bb1a7db
commit 84265c3a13

View file

@ -32,6 +32,8 @@ struct ircd::ctx::parallel
void rethrow_any_exception(); void rethrow_any_exception();
void receiver() noexcept; void receiver() noexcept;
void sender() noexcept;
void sender(const arg &a) noexcept;
public: public:
void wait_avail(); void wait_avail();
@ -68,7 +70,24 @@ void
ircd::ctx::parallel<arg>::operator()(const arg &a) ircd::ctx::parallel<arg>::operator()(const arg &a)
{ {
rethrow_any_exception(); rethrow_any_exception();
sender(a);
wait_avail();
}
template<class arg>
void
ircd::ctx::parallel<arg>::operator()()
{
rethrow_any_exception();
sender();
wait_avail();
}
template<class arg>
void
ircd::ctx::parallel<arg>::sender(const arg &a)
noexcept
{
this->a.at(snd++) = a; this->a.at(snd++) = a;
snd %= this->a.size(); snd %= this->a.size();
out++; out++;
@ -79,16 +98,13 @@ ircd::ctx::parallel<arg>::operator()(const arg &a)
p(std::move(func)); p(std::move(func));
else else
func(); func();
wait_avail();
} }
template<class arg> template<class arg>
void void
ircd::ctx::parallel<arg>::operator()() ircd::ctx::parallel<arg>::sender()
noexcept
{ {
rethrow_any_exception();
snd++; snd++;
snd %= this->a.size(); snd %= this->a.size();
out++; out++;
@ -99,8 +115,6 @@ ircd::ctx::parallel<arg>::operator()()
p(std::move(func)); p(std::move(func));
else else
func(); func();
wait_avail();
} }
template<class arg> template<class arg>