summaryrefslogtreecommitdiff
path: root/src/common/logging/backend.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/common/logging/backend.cpp18
1 files changed, 5 insertions, 13 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index c51c05b28..f1c9ed6c4 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -218,19 +218,17 @@ private:
218 Impl(const std::filesystem::path& file_backend_filename, const Filter& filter_) 218 Impl(const std::filesystem::path& file_backend_filename, const Filter& filter_)
219 : filter{filter_}, file_backend{file_backend_filename} {} 219 : filter{filter_}, file_backend{file_backend_filename} {}
220 220
221 ~Impl() { 221 ~Impl() = default;
222 StopBackendThread();
223 }
224 222
225 void StartBackendThread() { 223 void StartBackendThread() {
226 backend_thread = std::thread([this] { 224 backend_thread = std::jthread([this](std::stop_token stop_token) {
227 Common::SetCurrentThreadName("yuzu:Log"); 225 Common::SetCurrentThreadName("yuzu:Log");
228 Entry entry; 226 Entry entry;
229 const auto write_logs = [this, &entry]() { 227 const auto write_logs = [this, &entry]() {
230 ForEachBackend([&entry](Backend& backend) { backend.Write(entry); }); 228 ForEachBackend([&entry](Backend& backend) { backend.Write(entry); });
231 }; 229 };
232 while (!stop.stop_requested()) { 230 while (!stop_token.stop_requested()) {
233 entry = message_queue.PopWait(stop.get_token()); 231 entry = message_queue.PopWait(stop_token);
234 if (entry.filename != nullptr) { 232 if (entry.filename != nullptr) {
235 write_logs(); 233 write_logs();
236 } 234 }
@@ -244,11 +242,6 @@ private:
244 }); 242 });
245 } 243 }
246 244
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, 245 Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr,
253 const char* function, std::string&& message) const { 246 const char* function, std::string&& message) const {
254 using std::chrono::duration_cast; 247 using std::chrono::duration_cast;
@@ -283,8 +276,7 @@ private:
283 ColorConsoleBackend color_console_backend{}; 276 ColorConsoleBackend color_console_backend{};
284 FileBackend file_backend; 277 FileBackend file_backend;
285 278
286 std::stop_source stop; 279 std::jthread backend_thread;
287 std::thread backend_thread;
288 MPSCQueue<Entry, true> message_queue{}; 280 MPSCQueue<Entry, true> message_queue{};
289 std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()}; 281 std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()};
290}; 282};