diff options
author | Yabin Cui <yabinc@google.com> | 2022-04-01 18:26:21 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-04-01 18:26:21 +0000 |
commit | b7a4062363c942cbe2c00734f930d0bc1d0258fd (patch) | |
tree | 38ccb6a58bc5f1c67d68dc981be6cf466482c9ec /simpleperf/IOEventLoop.cpp | |
parent | e0d4d7e891757f19379c8150cc5d853fd3538c73 (diff) | |
parent | d01120acf01401bd422df447fe18d6d0b71070ad (diff) | |
download | extras-b7a4062363c942cbe2c00734f930d0bc1d0258fd.tar.gz |
Merge changes Ib0160fe1,Ib5a11b7c am: 09fe7d7b48 am: e0c446c7d2 am: d01120acf0
Original change: https://android-review.googlesource.com/c/platform/system/extras/+/2052097
Change-Id: Iee4910a4379eb44170d59e00b55fa0e9a2e5dc46
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
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; |