diff --git a/logcat_thread.cpp b/logcat_thread.cpp index bc92c01..c11a33c 100644 --- a/logcat_thread.cpp +++ b/logcat_thread.cpp @@ -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) { diff --git a/logcat_thread.h b/logcat_thread.h index cf8976c..cdd6ae8 100644 --- a/logcat_thread.h +++ b/logcat_thread.h @@ -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; diff --git a/main.cpp b/main.cpp index a8de46f..88d32d2 100644 --- a/main.cpp +++ b/main.cpp @@ -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);