diff options
Diffstat (limited to 'simpleperf/IOEventLoop.cpp')
-rw-r--r-- | simpleperf/IOEventLoop.cpp | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/simpleperf/IOEventLoop.cpp b/simpleperf/IOEventLoop.cpp index 06bdd713..239fff97 100644 --- a/simpleperf/IOEventLoop.cpp +++ b/simpleperf/IOEventLoop.cpp @@ -84,6 +84,10 @@ bool IOEventLoop::EnsureInit() { return false; } event_config_free(cfg); + if (event_base_priority_init(ebase_, 2) != 0) { + LOG(ERROR) << "event_base_priority_init failed"; + return false; + } } if (ebase_ == nullptr) { LOG(ERROR) << "failed to create event_base"; @@ -110,39 +114,44 @@ static bool MakeFdNonBlocking(int fd) { return true; } -IOEventRef IOEventLoop::AddReadEvent(int fd, const std::function<bool()>& callback) { +IOEventRef IOEventLoop::AddReadEvent(int fd, const std::function<bool()>& callback, + IOEventPriority priority) { if (!MakeFdNonBlocking(fd)) { return nullptr; } - return AddEvent(fd, EV_READ | EV_PERSIST, nullptr, callback); + return AddEvent(fd, EV_READ | EV_PERSIST, nullptr, callback, priority); } -IOEventRef IOEventLoop::AddWriteEvent(int fd, const std::function<bool()>& callback) { +IOEventRef IOEventLoop::AddWriteEvent(int fd, const std::function<bool()>& callback, + IOEventPriority priority) { if (!MakeFdNonBlocking(fd)) { return nullptr; } - return AddEvent(fd, EV_WRITE | EV_PERSIST, nullptr, callback); + return AddEvent(fd, EV_WRITE | EV_PERSIST, nullptr, callback, priority); } -bool IOEventLoop::AddSignalEvent(int sig, const std::function<bool()>& callback) { - return AddEvent(sig, EV_SIGNAL | EV_PERSIST, nullptr, callback) != nullptr; +bool IOEventLoop::AddSignalEvent(int sig, const std::function<bool()>& callback, + IOEventPriority priority) { + return AddEvent(sig, EV_SIGNAL | EV_PERSIST, nullptr, callback, priority) != nullptr; } -bool IOEventLoop::AddSignalEvents(std::vector<int> sigs, const std::function<bool()>& callback) { +bool IOEventLoop::AddSignalEvents(std::vector<int> sigs, const std::function<bool()>& callback, + IOEventPriority priority) { for (auto sig : sigs) { - if (!AddSignalEvent(sig, callback)) { + if (!AddSignalEvent(sig, callback, priority)) { return false; } } return true; } -IOEventRef IOEventLoop::AddPeriodicEvent(timeval duration, const std::function<bool()>& callback) { - return AddEvent(-1, EV_PERSIST, &duration, callback); +IOEventRef IOEventLoop::AddPeriodicEvent(timeval duration, const std::function<bool()>& callback, + IOEventPriority priority) { + return AddEvent(-1, EV_PERSIST, &duration, callback, priority); } IOEventRef IOEventLoop::AddEvent(int fd_or_sig, int16_t events, timeval* timeout, - const std::function<bool()>& callback) { + const std::function<bool()>& callback, IOEventPriority priority) { if (!EnsureInit()) { return nullptr; } @@ -152,6 +161,7 @@ IOEventRef IOEventLoop::AddEvent(int fd_or_sig, int16_t events, timeval* timeout LOG(ERROR) << "event_new() failed"; return nullptr; } + event_priority_set(e->e, priority); if (event_add(e->e, timeout) != 0) { LOG(ERROR) << "event_add() failed"; return nullptr; |