34 }
else if (!tq.empty()) {
36 if ((now.mono_time() - tq.front().expiry()) > 100
ms) {
53 epoll_.
del(notify_.
fd());
60 if (fd >=
static_cast<int>(data_.size())) {
63 auto&
ref = data_[fd];
64 epoll_.
add(fd, ++
ref.sid, events);
68 return {*
this, fd,
ref.sid};
74 using namespace chrono;
98 now = CyclTime::now();
99 last_time_priority_io_polled_ = now.
mono_time();
100 last_time_user_hook_polled_ = now.
mono_time();
104 throw system_error{
ec};
111 cycle_work_ = tqs_[
High].dispatch(now);
118 if (cycle_work_ > 0) {
135 using namespace chrono;
137 const auto& tq = tqs_[
High];
141 next =
min(next, tq.front().expiry() - 200u
s);
145 const auto& tq = tqs_[
Low];
148 next =
min(next, tq.front().expiry());
156 if (currently_handling_priority_events_) [[
unlikely]] {
161 cycle_work_ += do_io_priority_poll(now);
162 cycle_work_ += do_user_priority_poll(now);
165int Reactor::do_io_priority_poll(
MonoTime now)
noexcept
169 const bool enabled = priority_io_poll_threshold_ != Micros::max();
175 [
this]()
noexcept { last_time_priority_io_polled_ = MonoClock::now(); });
183 TOOLBOX_ERROR <<
"epoll failure during high priority io poll: " <<
ec <<
" ["
184 <<
ec.message() <<
']';
190 }
catch (
const std::exception& e) {
191 TOOLBOX_ERROR <<
"exception during high priority io poll: " << e.what();
197int Reactor::do_user_priority_poll(
MonoTime now)
noexcept
202 = (user_hook_poll_threshold_ != Micros::max()) && priority_poll_user_hook_;
208 [
this]()
noexcept { last_time_user_hook_polled_ = MonoClock::now(); });
210 currently_handling_priority_events_ =
true;
212 =
make_finally([
this]()
noexcept { currently_handling_priority_events_ =
false; });
214 ret = priority_poll_user_hook_(CyclTime::current());
216 }
catch (
const std::exception& e) {
217 TOOLBOX_ERROR <<
"exception during user high priority hook: " << e.what();
223int Reactor::dispatch(CyclTime now, Event*
buf,
int size,
Priority priority)
226 assert(!currently_handling_priority_events_);
227 currently_handling_priority_events_ =
true;
230 =
make_finally([
this]()
noexcept { currently_handling_priority_events_ =
false; });
233 for (
int i{0};
i <
size; ++
i) {
237 const auto&
ref = data_[fd];
239 if (
ref.priority != priority) {
243 if (fd == notify_.
fd()) {
268 ref.slot(now, fd, events);
269 }
catch (
const std::exception& e) {
270 TOOLBOX_ERROR <<
"exception in i/o event handler: " << e.what();
277void Reactor::set_events(
int fd,
int sid,
unsigned events,
IoSlot slot, error_code&
ec)
noexcept
279 auto&
ref = data_[fd];
280 if (
ref.sid == sid) {
281 if (
ref.events != events) {
282 epoll_.mod(fd, sid, events,
ec);
292void Reactor::set_events(
int fd,
int sid,
unsigned events,
IoSlot slot)
294 auto&
ref = data_[fd];
295 if (
ref.sid == sid) {
296 if (
ref.events != events) {
297 epoll_.
mod(fd, sid, events);
304void Reactor::set_events(
int fd,
int sid,
unsigned events, error_code&
ec)
noexcept
306 auto&
ref = data_[fd];
307 if (
ref.sid == sid &&
ref.events != events) {
308 epoll_.mod(fd, sid, events,
ec);
316void Reactor::set_events(
int fd,
int sid,
unsigned events)
318 auto&
ref = data_[fd];
319 if (
ref.sid == sid &&
ref.events != events) {
320 epoll_.
mod(fd, sid, events);
325void Reactor::unsubscribe(
int fd,
int sid)
noexcept
327 auto&
ref = data_[fd];
328 if (
ref.sid == sid) {
336void Reactor::set_io_priority(
int fd,
int sid,
Priority priority)
noexcept
338 auto&
ref = data_[fd];
339 if (
ref.sid == sid &&
ref.priority != priority) {
340 ref.priority = priority;
#define TOOLBOX_PROBE_SCOPED(provider, name,...)