diff --git a/include/xo/reactor/Reactor.hpp b/include/xo/reactor/Reactor.hpp index 2b265b0b..229b7421 100644 --- a/include/xo/reactor/Reactor.hpp +++ b/include/xo/reactor/Reactor.hpp @@ -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 diff --git a/src/reactor/Reactor.cpp b/src/reactor/Reactor.cpp index 199ec562..d0803d14 100644 --- a/src/reactor/Reactor.cpp +++ b/src/reactor/Reactor.cpp @@ -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; irun_one(); + retval += this->run_one(); } } + + return retval; } /*run_n*/ } /*namespace reactor*/ } /*namespace xo*/ diff --git a/utest/PollingReactor.test.cpp b/utest/PollingReactor.test.cpp index 97d679cb..106acaf6 100644 --- a/utest/PollingReactor.test.cpp +++ b/utest/PollingReactor.test.cpp @@ -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;