Stop logcat thread when the event loop is stopped

This commit is contained in:
blankie 2023-01-17 20:59:04 +07:00
parent ace07768ee
commit 708fc3b16a
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
3 changed files with 7 additions and 8 deletions

View File

@ -7,12 +7,12 @@
#define EPOLL_MAX_EVENTS 10
LogcatThread::LogcatThread() {
LogcatThread::LogcatThread(bool* run_event_loop) {
this->_epoll_fd = epoll_create1(EPOLL_CLOEXEC);
if (this->_epoll_fd == -1) {
throw make_system_error("epoll_create1()");
}
this->_thread = std::thread(&LogcatThread::_run, this);
this->_thread = std::thread(&LogcatThread::_run, this, run_event_loop);
}
LogcatThread::~LogcatThread() {
@ -25,11 +25,10 @@ void LogcatThread::join() {
this->_thread.join();
}
void LogcatThread::_run() {
void LogcatThread::_run(bool* run_event_loop) {
struct epoll_event events[EPOLL_MAX_EVENTS];
// TODO break when run_main_loop is false
while (true) {
while (*run_event_loop) {
printf("(boop)\n");
int ready_fds = epoll_wait(this->_epoll_fd, events, EPOLL_MAX_EVENTS, 1000);
if (ready_fds == -1) {

View File

@ -8,12 +8,12 @@ public:
LogcatThread(const LogcatThread&) = delete;
LogcatThread& operator=(const LogcatThread&) = delete;
LogcatThread();
LogcatThread(bool* run_event_loop);
~LogcatThread();
void join();
private:
void _run();
void _run(bool* run_event_loop);
int _epoll_fd = -1;
std::thread _thread;

View File

@ -133,7 +133,7 @@ int main(int, char**) {
float config_write_timer = 0.0f;
LogcatThread logcat_thread = [&]() {
try {
return LogcatThread();
return LogcatThread(&run_event_loop);
} catch (const std::exception& e) {
fprintf(stderr, "Failed to spawn logcat thread: %s\n", e.what());
exit(1);