Seperate epoll into its own function

This commit is contained in:
blankie 2023-01-21 14:55:09 +07:00
parent 6cca794fee
commit 35ee4d3ff4
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
2 changed files with 30 additions and 25 deletions

View File

@ -204,23 +204,15 @@ void LogcatThread::_handle_line(char* buf, size_t length, bool is_stdout) {
this->_put_if_not_stopped(std::move(log_entry)); this->_put_if_not_stopped(std::move(log_entry));
} }
void LogcatThread::_run(std::stop_token stoken) { void LogcatThread::_run_epoll_round() {
struct epoll_event events[EPOLL_MAX_EVENTS]; struct epoll_event events[EPOLL_MAX_EVENTS];
while (!stoken.stop_requested()) {
#ifndef NDEBUG
if (this->debug_log_request.test()) {
this->_put_if_not_stopped(format_log("A log entry from the logcat thread :D"));
this->debug_log_request.clear();
}
#endif
int ready_fds = epoll_wait(this->_epoll_fd, events, EPOLL_MAX_EVENTS, 1000); int ready_fds = epoll_wait(this->_epoll_fd, events, EPOLL_MAX_EVENTS, 1000);
if (ready_fds == -1) { if (ready_fds == -1) {
std::string log_entry = format_log(std::string("epoll_wait(): ") + strerror(errno)); std::string log_entry = format_log(std::string("epoll_wait(): ") + strerror(errno));
printf("%s\n", log_entry.c_str()); printf("%s\n", log_entry.c_str());
this->_put_if_not_stopped(std::move(log_entry)); this->_put_if_not_stopped(std::move(log_entry));
break; return;
} }
for (int i=0; i < ready_fds; i++) { for (int i=0; i < ready_fds; i++) {
@ -240,4 +232,16 @@ void LogcatThread::_run(std::stop_token stoken) {
} }
} }
} }
void LogcatThread::_run(std::stop_token stoken) {
while (!stoken.stop_requested()) {
#ifndef NDEBUG
if (this->debug_log_request.test()) {
this->_put_if_not_stopped(format_log("A log entry from the logcat thread :D"));
this->debug_log_request.clear();
}
#endif
this->_run_epoll_round();
}
} }

View File

@ -28,6 +28,7 @@ public:
private: private:
void _put_if_not_stopped(LogcatThreadItem item); void _put_if_not_stopped(LogcatThreadItem item);
void _handle_line(char* buf, size_t length, bool is_stdout); void _handle_line(char* buf, size_t length, bool is_stdout);
void _run_epoll_round();
void _run(std::stop_token stoken); void _run(std::stop_token stoken);
int _epoll_fd = -1; int _epoll_fd = -1;