35 else if (!tq.empty()) {
37 if ((now.mono_time() - tq.front().expiry()) > 100
ms) {
54 epoll_.
del(notify_.
fd());
61 if (fd >=
static_cast<int>(data_.size())) {
64 auto&
ref = data_[fd];
65 epoll_.
add(fd, ++
ref.sid, events);
69 return {*
this, fd,
ref.sid};
75 using namespace chrono;
99 now = CyclTime::now();
100 last_time_priority_io_polled_ = now.
wall_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]] {
160 if (priority_io_poll_threshold == Micros::max()) {
165 if (now - last_time_priority_io_polled_ > priority_io_poll_threshold) {
166 last_time_priority_io_polled_ = now;
175 <<
ec <<
" [" <<
ec.message() <<
']';
181 cycle_work_ += dispatch_user_hp_hook();
185int Reactor::dispatch_user_hp_hook()
187 currently_handling_priority_events_ =
true;
189 currently_handling_priority_events_ =
false;
195 if (priority_poll_user_hook_) {
196 ret = priority_poll_user_hook_(CyclTime::current());
198 }
catch (
const std::exception& e) {
199 TOOLBOX_ERROR <<
"exception during user high priority hook: " << e.what();
205int Reactor::dispatch(CyclTime now, Event*
buf,
int size,
Priority priority)
208 assert(!currently_handling_priority_events_);
209 currently_handling_priority_events_ =
true;
212 currently_handling_priority_events_ =
false;
216 for (
int i{0};
i <
size; ++
i) {
220 const auto&
ref = data_[fd];
222 if (
ref.priority != priority) {
226 if (fd == notify_.
fd()) {
251 ref.slot(now, fd, events);
252 }
catch (
const std::exception& e) {
253 TOOLBOX_ERROR <<
"exception in i/o event handler: " << e.what();
260void Reactor::set_events(
int fd,
int sid,
unsigned events,
IoSlot slot, error_code&
ec)
noexcept
262 auto&
ref = data_[fd];
263 if (
ref.sid == sid) {
264 if (
ref.events != events) {
265 epoll_.mod(fd, sid, events,
ec);
275void Reactor::set_events(
int fd,
int sid,
unsigned events,
IoSlot slot)
277 auto&
ref = data_[fd];
278 if (
ref.sid == sid) {
279 if (
ref.events != events) {
280 epoll_.
mod(fd, sid, events);
287void Reactor::set_events(
int fd,
int sid,
unsigned events, error_code&
ec)
noexcept
289 auto&
ref = data_[fd];
290 if (
ref.sid == sid &&
ref.events != events) {
291 epoll_.mod(fd, sid, events,
ec);
299void Reactor::set_events(
int fd,
int sid,
unsigned events)
301 auto&
ref = data_[fd];
302 if (
ref.sid == sid &&
ref.events != events) {
303 epoll_.
mod(fd, sid, events);
308void Reactor::unsubscribe(
int fd,
int sid)
noexcept
310 auto&
ref = data_[fd];
311 if (
ref.sid == sid) {
319void Reactor::set_io_priority(
int fd,
int sid,
Priority priority)
noexcept
321 auto&
ref = data_[fd];
322 if (
ref.sid == sid &&
ref.priority != priority) {
323 ref.priority = priority;
#define TOOLBOX_PROBE_SCOPED(provider, name,...)