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));
}
void LogcatThread::_run(std::stop_token stoken) {
void LogcatThread::_run_epoll_round() {
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);
if (ready_fds == -1) {
std::string log_entry = format_log(std::string("epoll_wait(): ") + strerror(errno));
printf("%s\n", log_entry.c_str());
this->_put_if_not_stopped(std::move(log_entry));
break;
return;
}
for (int i=0; i < ready_fds; i++) {
@ -239,5 +231,17 @@ void LogcatThread::_run(std::stop_token stoken) {
this->_put_if_not_stopped(std::move(log_entry));
}
}
}
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:
void _put_if_not_stopped(LogcatThreadItem item);
void _handle_line(char* buf, size_t length, bool is_stdout);
void _run_epoll_round();
void _run(std::stop_token stoken);
int _epoll_fd = -1;