diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-05-08 04:54:57 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2022-05-08 04:54:57 +0000 |
commit | 544787af01137e8f298cd116227ccc7580373e54 (patch) | |
tree | cf80819eeabb636749e9e6dad02bf3f10d3c8028 /simpleperf/IOEventLoop.h | |
parent | c7c1d5dd08656b5c29453196d48aef971c7c0ad6 (diff) | |
parent | fe90e7d64697d86a5d73e0342ee6dbbf434ea5a8 (diff) | |
download | extras-platform-tools-33.0.2.tar.gz |
Merge "Snap for 8554636 from 3c93569dc609ee27fd796b450918522c8c172514 to sdk-release" into sdk-releaseplatform-tools-33.0.2
Diffstat (limited to 'simpleperf/IOEventLoop.h')
-rw-r--r-- | simpleperf/IOEventLoop.h | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/simpleperf/IOEventLoop.h b/simpleperf/IOEventLoop.h index f0192969..1578a4d0 100644 --- a/simpleperf/IOEventLoop.h +++ b/simpleperf/IOEventLoop.h @@ -18,6 +18,7 @@ #define SIMPLE_PERF_IOEVENT_LOOP_H_ #include <stdint.h> +#include <sys/time.h> #include <time.h> #include <functional> @@ -31,6 +32,12 @@ namespace simpleperf { struct IOEvent; typedef IOEvent* IOEventRef; +enum IOEventPriority { + // Lower value means higher priority. + IOEventHighPriority = 0, + IOEventLowPriority = 1, +}; + // IOEventLoop is a class wrapper of libevent, it monitors events happened, // and calls the corresponding callbacks. Possible events are: file ready to // read, file ready to write, signal happens, periodic timer timeout. @@ -45,22 +52,27 @@ class IOEventLoop { // Register a read Event, so [callback] is called when [fd] can be read // without blocking. If registered successfully, return the reference // to control the Event, otherwise return nullptr. - IOEventRef AddReadEvent(int fd, const std::function<bool()>& callback); + IOEventRef AddReadEvent(int fd, const std::function<bool()>& callback, + IOEventPriority priority = IOEventLowPriority); // Register a write Event, so [callback] is called when [fd] can be written // without blocking. - IOEventRef AddWriteEvent(int fd, const std::function<bool()>& callback); + IOEventRef AddWriteEvent(int fd, const std::function<bool()>& callback, + IOEventPriority priority = IOEventLowPriority); // Register a signal Event, so [callback] is called each time signal [sig] // happens. - bool AddSignalEvent(int sig, const std::function<bool()>& callback); + bool AddSignalEvent(int sig, const std::function<bool()>& callback, + IOEventPriority priority = IOEventLowPriority); // Register a vector of signal Events. - bool AddSignalEvents(std::vector<int> sigs, const std::function<bool()>& callback); + bool AddSignalEvents(std::vector<int> sigs, const std::function<bool()>& callback, + IOEventPriority priority = IOEventLowPriority); // Register a periodic Event, so [callback] is called periodically every // [duration]. - IOEventRef AddPeriodicEvent(timeval duration, const std::function<bool()>& callback); + IOEventRef AddPeriodicEvent(timeval duration, const std::function<bool()>& callback, + IOEventPriority priority = IOEventLowPriority); // Run a loop polling for Events. It only exits when ExitLoop() is called // in a callback function of registered Events. @@ -80,7 +92,8 @@ class IOEventLoop { private: bool EnsureInit(); IOEventRef AddEvent(int fd_or_sig, int16_t events, timeval* timeout, - const std::function<bool()>& callback); + const std::function<bool()>& callback, + IOEventPriority priority = IOEventLowPriority); static void EventCallbackFn(int, int16_t, void*); event_base* ebase_; |