Reactor.run_n() returns #events delivered

This commit is contained in:
Roland Conybeare 2023-10-12 01:31:20 -04:00
commit 9adfbb822d
3 changed files with 9 additions and 8 deletions

View file

@ -54,7 +54,7 @@ namespace xo {
* otherwise dispatch up to n events.
* n = 0 is a noop
*/
void run_n(int32_t n);
std::uint64_t run_n(int32_t n);
/* borrow calling thread to run indefinitely.
* suitable implementation for dedicated reactor threads

View file

@ -17,18 +17,22 @@ namespace xo {
Subsystem::initialize_all();
}
void
std::uint64_t
Reactor::run_n(int32_t n)
{
std::uint64_t retval = 0;
if (n == -1) {
for (;;) {
this->run_one();
retval += this->run_one();
}
} else {
for (int32_t i=0; i<n; ++i) {
this->run_one();
retval += this->run_one();
}
}
return retval;
} /*run_n*/
} /*namespace reactor*/
} /*namespace xo*/

View file

@ -155,10 +155,7 @@ namespace xo {
/* pick random #of elements to remove (from front of queue) */
{
for (std::size_t j = 0; j < n_deq_attempted; ++j)
n_deq_done += reactor->run_one();
n_deq_done += reactor->run_n(n_deq_attempted);
n_work_attempted += n_deq_attempted;
n_work_done += n_deq_done;