diff --git a/event_loop.cpp b/event_loop.cpp index a30f0fb..1c65b92 100644 --- a/event_loop.cpp +++ b/event_loop.cpp @@ -109,7 +109,7 @@ static inline void main_window(bool latest_log_entries_read, bool* show_settings } #ifndef NDEBUG -static inline void debug_window() { +static inline void debug_window(LogcatThread& logcat_thread) { static bool show_demo_window = false; static size_t add_log_entry_presses = 1; static bool log_entry_every_second = false; @@ -138,6 +138,9 @@ static inline void debug_window() { if (ImGui::Button("Add Log Entry with Newlines")) { log("The following should have five spaces: \"\n\n\n\n\n\""); } + if (ImGui::Button("Request log entry from Logcat thread")) { + logcat_thread.debug_log_request.test_and_set(); + } if (log_entry_every_second) { log_entry_every_second_delta += ImGui::GetIO().DeltaTime; @@ -159,7 +162,7 @@ void event_loop(ImFont* monospace_font, Config& config, float* config_write_time check_for_logcat_items(logcat_thread); #ifndef NDEBUG - debug_window(); + debug_window(logcat_thread); #endif if (show_settings_window) { diff --git a/logcat_thread.cpp b/logcat_thread.cpp index 86c097c..2b1736c 100644 --- a/logcat_thread.cpp +++ b/logcat_thread.cpp @@ -106,6 +106,12 @@ void LogcatThread::_run(std::stop_token stoken) { while (!stoken.stop_requested()) { printf("(boop)\n"); +#ifndef NDEBUG + if (this->debug_log_request.test()) { + this->atomic_ring_buffer.put_and_increment_write(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) { diff --git a/logcat_thread.h b/logcat_thread.h index c9dee9c..e0e8ca4 100644 --- a/logcat_thread.h +++ b/logcat_thread.h @@ -19,6 +19,10 @@ public: AtomicRingBuffer atomic_ring_buffer; +#ifndef NDEBUG + std::atomic_flag debug_log_request; +#endif + private: void _run(std::stop_token stoken);