diff --git a/quic/common/events/LibevQuicEventBase.cpp b/quic/common/events/LibevQuicEventBase.cpp index d4dad3762..25da00777 100644 --- a/quic/common/events/LibevQuicEventBase.cpp +++ b/quic/common/events/LibevQuicEventBase.cpp @@ -126,6 +126,9 @@ void LibevQuicEventBase::scheduleLibevTimeoutImpl( libEvTimeoutCallback, seconds /* after */, 0. /* repeat */); + if (prioritizeTimers_) { + ev_set_priority(&wrapper->ev_timer_, EV_MAXPRI); + } setImplHandle(timerCallback, wrapper); } else { // We already have a wrapper. Just re-arm it. @@ -144,7 +147,8 @@ void LibevQuicEventBase::scheduleTimerFDTimeoutImpl( if (wrapper == nullptr) { // This is the first time this timer callback is getting scheduled. Create // a wrapper for it. - wrapper = new TimerCallbackWrapperTimerFD(timerCallback, ev_loop_); + wrapper = new TimerCallbackWrapperTimerFD( + timerCallback, ev_loop_, prioritizeTimers_); wrapper->ev_io_watcher_.data = wrapper; setImplHandle(timerCallback, wrapper); } diff --git a/quic/common/events/LibevQuicEventBase.h b/quic/common/events/LibevQuicEventBase.h index 53f03c504..cabe1aca5 100644 --- a/quic/common/events/LibevQuicEventBase.h +++ b/quic/common/events/LibevQuicEventBase.h @@ -140,6 +140,10 @@ class LibevQuicEventBase #endif } + void prioritizeTimers() { + prioritizeTimers_ = true; + } + struct ev_loop* getLibevLoop() { return ev_loop_; } @@ -191,9 +195,10 @@ class LibevQuicEventBase class TimerCallbackWrapperTimerFD : public QuicTimerCallback::TimerCallbackImpl { public: - explicit TimerCallbackWrapperTimerFD( + TimerCallbackWrapperTimerFD( QuicTimerCallback* callback, - struct ev_loop* ev_loop) + struct ev_loop* ev_loop, + bool prioritizeTimers) : callback_(callback), ev_loop_(ev_loop) { #if defined(HAS_TIMERFD) ev_io_watcher_.fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); @@ -211,6 +216,9 @@ class LibevQuicEventBase }, ev_io_watcher_.fd, EV_READ); + if (prioritizeTimers) { + ev_set_priority(&ev_io_watcher_, EV_MAXPRI); + } #else LOG(FATAL) << "TimerFD not supported on this platform"; #endif @@ -339,5 +347,6 @@ class LibevQuicEventBase ev_timer ev_timer_internal_; bool internalTimerInitialized_{false}; bool useTimerFd_{false}; + bool prioritizeTimers_{false}; }; } // namespace quic