From ac775cd75ea2f86f6e6c5923c7d080a19a28e078 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 5 Jan 2019 13:34:02 +0300 Subject: [PATCH] Simplify gui_listener Use lf_queue --- Utilities/lockless.h | 5 +++++ rpcs3/rpcs3qt/log_frame.cpp | 41 ++++++++++++++----------------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/Utilities/lockless.h b/Utilities/lockless.h index 1974062e2a..67eb7434ea 100644 --- a/Utilities/lockless.h +++ b/Utilities/lockless.h @@ -287,6 +287,11 @@ public: return m_head != nullptr; } + T* get() const + { + return m_head ? &m_head->m_data : nullptr; + } + lf_queue_iterator begin() const { lf_queue_iterator result; diff --git a/rpcs3/rpcs3qt/log_frame.cpp b/rpcs3/rpcs3qt/log_frame.cpp index 5155fdbe12..a0feadc47f 100644 --- a/rpcs3/rpcs3qt/log_frame.cpp +++ b/rpcs3/rpcs3qt/log_frame.cpp @@ -14,6 +14,7 @@ #include #include #include "Utilities/mutex.h" +#include "Utilities/lockless.h" extern fs::file g_tty; extern atomic_t g_tty_size; @@ -26,29 +27,18 @@ struct gui_listener : logs::listener { atomic_t enabled{logs::level::_uninit}; - struct packet + struct packet_t { - atomic_t next{}; - logs::level sev{}; std::string msg; - - ~packet() - { - for (auto ptr = next.raw(); UNLIKELY(ptr);) - { - delete std::exchange(ptr, std::exchange(ptr->next.raw(), nullptr)); - } - } }; - atomic_t last; // Packet for writing another packet - atomic_t read; // Packet for reading + lf_queue_slice pending; + + lf_queue queue; gui_listener() : logs::listener() - , last(new packet) - , read(+last) { // Self-registration logs::listener::add(this); @@ -56,7 +46,6 @@ struct gui_listener : logs::listener ~gui_listener() { - delete read; } void log(u64 stamp, const logs::message& msg, const std::string& prefix, const std::string& text) @@ -65,7 +54,7 @@ struct gui_listener : logs::listener if (msg.sev <= enabled) { - const auto _new = new packet; + packet_t p,* _new = &p; _new->sev = msg.sev; if (prefix.size() > 0) @@ -88,24 +77,24 @@ struct gui_listener : logs::listener _new->msg += text; _new->msg += '\n'; - last.exchange(_new)->next = _new; + queue.push(std::move(p)); } } void pop() { - if (const auto head = read.load()->next.exchange(nullptr)) - { - delete read.exchange(head); - } + pending.pop_front(); } - void clear() + packet_t* get() { - while (read.load()->next) + if (packet_t* _head = pending.get()) { - pop(); + return _head; } + + pending = queue.pop_all(); + return pending.get(); } }; @@ -502,7 +491,7 @@ void log_frame::UpdateUI() } // Check main logs - while (const auto packet = s_gui_listener.read.load()->next.load()) + while (auto* packet = s_gui_listener.get()) { // Confirm log level if (packet->sev <= s_gui_listener.enabled)