diff options
Diffstat (limited to 'src/common/logging/backend.cpp')
| -rw-r--r-- | src/common/logging/backend.cpp | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index c51c05b28..15d92505e 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp | |||
| @@ -1,14 +1,11 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | 1 | // SPDX-FileCopyrightText: 2014 Citra Emulator Project |
| 2 | // Licensed under GPLv2 or any later version | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | // Refer to the license.txt file included. | ||
| 4 | 3 | ||
| 5 | #include <atomic> | 4 | #include <atomic> |
| 6 | #include <chrono> | 5 | #include <chrono> |
| 7 | #include <climits> | 6 | #include <climits> |
| 8 | #include <exception> | ||
| 9 | #include <stop_token> | 7 | #include <stop_token> |
| 10 | #include <thread> | 8 | #include <thread> |
| 11 | #include <vector> | ||
| 12 | 9 | ||
| 13 | #include <fmt/format.h> | 10 | #include <fmt/format.h> |
| 14 | 11 | ||
| @@ -218,19 +215,17 @@ private: | |||
| 218 | Impl(const std::filesystem::path& file_backend_filename, const Filter& filter_) | 215 | Impl(const std::filesystem::path& file_backend_filename, const Filter& filter_) |
| 219 | : filter{filter_}, file_backend{file_backend_filename} {} | 216 | : filter{filter_}, file_backend{file_backend_filename} {} |
| 220 | 217 | ||
| 221 | ~Impl() { | 218 | ~Impl() = default; |
| 222 | StopBackendThread(); | ||
| 223 | } | ||
| 224 | 219 | ||
| 225 | void StartBackendThread() { | 220 | void StartBackendThread() { |
| 226 | backend_thread = std::thread([this] { | 221 | backend_thread = std::jthread([this](std::stop_token stop_token) { |
| 227 | Common::SetCurrentThreadName("yuzu:Log"); | 222 | Common::SetCurrentThreadName("Logger"); |
| 228 | Entry entry; | 223 | Entry entry; |
| 229 | const auto write_logs = [this, &entry]() { | 224 | const auto write_logs = [this, &entry]() { |
| 230 | ForEachBackend([&entry](Backend& backend) { backend.Write(entry); }); | 225 | ForEachBackend([&entry](Backend& backend) { backend.Write(entry); }); |
| 231 | }; | 226 | }; |
| 232 | while (!stop.stop_requested()) { | 227 | while (!stop_token.stop_requested()) { |
| 233 | entry = message_queue.PopWait(stop.get_token()); | 228 | entry = message_queue.PopWait(stop_token); |
| 234 | if (entry.filename != nullptr) { | 229 | if (entry.filename != nullptr) { |
| 235 | write_logs(); | 230 | write_logs(); |
| 236 | } | 231 | } |
| @@ -244,11 +239,6 @@ private: | |||
| 244 | }); | 239 | }); |
| 245 | } | 240 | } |
| 246 | 241 | ||
| 247 | void StopBackendThread() { | ||
| 248 | stop.request_stop(); | ||
| 249 | backend_thread.join(); | ||
| 250 | } | ||
| 251 | |||
| 252 | Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, | 242 | Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, |
| 253 | const char* function, std::string&& message) const { | 243 | const char* function, std::string&& message) const { |
| 254 | using std::chrono::duration_cast; | 244 | using std::chrono::duration_cast; |
| @@ -283,10 +273,9 @@ private: | |||
| 283 | ColorConsoleBackend color_console_backend{}; | 273 | ColorConsoleBackend color_console_backend{}; |
| 284 | FileBackend file_backend; | 274 | FileBackend file_backend; |
| 285 | 275 | ||
| 286 | std::stop_source stop; | ||
| 287 | std::thread backend_thread; | ||
| 288 | MPSCQueue<Entry, true> message_queue{}; | 276 | MPSCQueue<Entry, true> message_queue{}; |
| 289 | std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()}; | 277 | std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()}; |
| 278 | std::jthread backend_thread; | ||
| 290 | }; | 279 | }; |
| 291 | } // namespace | 280 | } // namespace |
| 292 | 281 | ||