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:
parent
7f4bb1a7db
commit
84265c3a13
1 changed files with 21 additions and 7 deletions
|
@ -32,6 +32,8 @@ struct ircd::ctx::parallel
|
|||
|
||||
void rethrow_any_exception();
|
||||
void receiver() noexcept;
|
||||
void sender() noexcept;
|
||||
void sender(const arg &a) noexcept;
|
||||
|
||||
public:
|
||||
void wait_avail();
|
||||
|
@ -68,7 +70,24 @@ void
|
|||
ircd::ctx::parallel<arg>::operator()(const arg &a)
|
||||
{
|
||||
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;
|
||||
snd %= this->a.size();
|
||||
out++;
|
||||
|
@ -79,16 +98,13 @@ ircd::ctx::parallel<arg>::operator()(const arg &a)
|
|||
p(std::move(func));
|
||||
else
|
||||
func();
|
||||
|
||||
wait_avail();
|
||||
}
|
||||
|
||||
template<class arg>
|
||||
void
|
||||
ircd::ctx::parallel<arg>::operator()()
|
||||
ircd::ctx::parallel<arg>::sender()
|
||||
noexcept
|
||||
{
|
||||
rethrow_any_exception();
|
||||
|
||||
snd++;
|
||||
snd %= this->a.size();
|
||||
out++;
|
||||
|
@ -99,8 +115,6 @@ ircd::ctx::parallel<arg>::operator()()
|
|||
p(std::move(func));
|
||||
else
|
||||
func();
|
||||
|
||||
wait_avail();
|
||||
}
|
||||
|
||||
template<class arg>
|
||||
|
|
Loading…
Reference in a new issue