Refactor Logging Impl

Loop on stop_token and remove final_entry in Entry.
Move Backend thread out of Impl Constructor to its own function.
Add Start function for backend thread.
This commit is contained in:
Levi Behunin
2021-10-21 17:25:51 -06:00
parent 92f8d0d76c
commit 3e5d69b522

View File

@@ -223,17 +223,15 @@ private:
}
void StartBackendThread() {
backend_thread = std::thread([this] {
backend_thread{std::thread([this] {
Common::SetCurrentThreadName("yuzu:Log");
Entry entry;
const auto write_logs = [this, &entry]() {
ForEachBackend([&entry](Backend& backend) { backend.Write(entry); });
};
while (!stop.stop_requested()) {
entry = message_queue.PopWait(stop.get_token());
if (entry.filename != nullptr) {
write_logs();
}
entry = message_queue.PopWait();
write_logs();
}
// Drain the logging queue. Only writes out up to MAX_LOGS_TO_WRITE to prevent a
// case where a system is repeatedly spamming logs even on close.
@@ -241,7 +239,7 @@ private:
while (max_logs_to_write-- && message_queue.Pop(entry)) {
write_logs();
}
});
})};
}
void StopBackendThread() {