mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 10:42:36 +01:00
Simplify gui_listener
Use lf_queue
This commit is contained in:
parent
3fed4dcc5a
commit
ac775cd75e
@ -287,6 +287,11 @@ public:
|
|||||||
return m_head != nullptr;
|
return m_head != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
T* get() const
|
||||||
|
{
|
||||||
|
return m_head ? &m_head->m_data : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
lf_queue_iterator<T> begin() const
|
lf_queue_iterator<T> begin() const
|
||||||
{
|
{
|
||||||
lf_queue_iterator<T> result;
|
lf_queue_iterator<T> result;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include <deque>
|
#include <deque>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include "Utilities/mutex.h"
|
#include "Utilities/mutex.h"
|
||||||
|
#include "Utilities/lockless.h"
|
||||||
|
|
||||||
extern fs::file g_tty;
|
extern fs::file g_tty;
|
||||||
extern atomic_t<s64> g_tty_size;
|
extern atomic_t<s64> g_tty_size;
|
||||||
@ -26,29 +27,18 @@ struct gui_listener : logs::listener
|
|||||||
{
|
{
|
||||||
atomic_t<logs::level> enabled{logs::level::_uninit};
|
atomic_t<logs::level> enabled{logs::level::_uninit};
|
||||||
|
|
||||||
struct packet
|
struct packet_t
|
||||||
{
|
{
|
||||||
atomic_t<packet*> next{};
|
|
||||||
|
|
||||||
logs::level sev{};
|
logs::level sev{};
|
||||||
std::string msg;
|
std::string msg;
|
||||||
|
|
||||||
~packet()
|
|
||||||
{
|
|
||||||
for (auto ptr = next.raw(); UNLIKELY(ptr);)
|
|
||||||
{
|
|
||||||
delete std::exchange(ptr, std::exchange(ptr->next.raw(), nullptr));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
atomic_t<packet*> last; // Packet for writing another packet
|
lf_queue_slice<packet_t> pending;
|
||||||
atomic_t<packet*> read; // Packet for reading
|
|
||||||
|
lf_queue<packet_t> queue;
|
||||||
|
|
||||||
gui_listener()
|
gui_listener()
|
||||||
: logs::listener()
|
: logs::listener()
|
||||||
, last(new packet)
|
|
||||||
, read(+last)
|
|
||||||
{
|
{
|
||||||
// Self-registration
|
// Self-registration
|
||||||
logs::listener::add(this);
|
logs::listener::add(this);
|
||||||
@ -56,7 +46,6 @@ struct gui_listener : logs::listener
|
|||||||
|
|
||||||
~gui_listener()
|
~gui_listener()
|
||||||
{
|
{
|
||||||
delete read;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void log(u64 stamp, const logs::message& msg, const std::string& prefix, const std::string& text)
|
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)
|
if (msg.sev <= enabled)
|
||||||
{
|
{
|
||||||
const auto _new = new packet;
|
packet_t p,* _new = &p;
|
||||||
_new->sev = msg.sev;
|
_new->sev = msg.sev;
|
||||||
|
|
||||||
if (prefix.size() > 0)
|
if (prefix.size() > 0)
|
||||||
@ -88,24 +77,24 @@ struct gui_listener : logs::listener
|
|||||||
_new->msg += text;
|
_new->msg += text;
|
||||||
_new->msg += '\n';
|
_new->msg += '\n';
|
||||||
|
|
||||||
last.exchange(_new)->next = _new;
|
queue.push(std::move(p));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pop()
|
void pop()
|
||||||
{
|
{
|
||||||
if (const auto head = read.load()->next.exchange(nullptr))
|
pending.pop_front();
|
||||||
{
|
|
||||||
delete read.exchange(head);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
// Check main logs
|
||||||
while (const auto packet = s_gui_listener.read.load()->next.load())
|
while (auto* packet = s_gui_listener.get())
|
||||||
{
|
{
|
||||||
// Confirm log level
|
// Confirm log level
|
||||||
if (packet->sev <= s_gui_listener.enabled)
|
if (packet->sev <= s_gui_listener.enabled)
|
||||||
|
Loading…
Reference in New Issue
Block a user