summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Morph2023-03-19 03:20:05 -0400
committerGravatar Morph2023-03-21 19:17:38 -0400
commitf28ca5361f5242f5b65a5c54bdde55639fba71f5 (patch)
tree7a520db2cb3956b79587d70ba7bfb95a1eb40465
parentbounded_threadsafe_queue: Use simplified impl of bounded queue (diff)
downloadyuzu-f28ca5361f5242f5b65a5c54bdde55639fba71f5.tar.gz
yuzu-f28ca5361f5242f5b65a5c54bdde55639fba71f5.tar.xz
yuzu-f28ca5361f5242f5b65a5c54bdde55639fba71f5.zip
logging: Make use of bounded queue
-rw-r--r--src/common/logging/backend.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 2a3bded40..e1ce9db99 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -28,7 +28,7 @@
28#ifdef _WIN32 28#ifdef _WIN32
29#include "common/string_util.h" 29#include "common/string_util.h"
30#endif 30#endif
31#include "common/threadsafe_queue.h" 31#include "common/bounded_threadsafe_queue.h"
32 32
33namespace Common::Log { 33namespace Common::Log {
34 34
@@ -204,11 +204,11 @@ public:
204 204
205 void PushEntry(Class log_class, Level log_level, const char* filename, unsigned int line_num, 205 void PushEntry(Class log_class, Level log_level, const char* filename, unsigned int line_num,
206 const char* function, std::string&& message) { 206 const char* function, std::string&& message) {
207 if (!filter.CheckMessage(log_class, log_level)) 207 if (!filter.CheckMessage(log_class, log_level)) {
208 return; 208 return;
209 const Entry& entry = 209 }
210 CreateEntry(log_class, log_level, filename, line_num, function, std::move(message)); 210 message_queue.Push(
211 message_queue.Push(entry); 211 CreateEntry(log_class, log_level, filename, line_num, function, std::move(message)));
212 } 212 }
213 213
214private: 214private:
@@ -225,7 +225,7 @@ private:
225 ForEachBackend([&entry](Backend& backend) { backend.Write(entry); }); 225 ForEachBackend([&entry](Backend& backend) { backend.Write(entry); });
226 }; 226 };
227 while (!stop_token.stop_requested()) { 227 while (!stop_token.stop_requested()) {
228 entry = message_queue.PopWait(stop_token); 228 message_queue.PopWait(entry, stop_token);
229 if (entry.filename != nullptr) { 229 if (entry.filename != nullptr) {
230 write_logs(); 230 write_logs();
231 } 231 }
@@ -233,7 +233,7 @@ private:
233 // Drain the logging queue. Only writes out up to MAX_LOGS_TO_WRITE to prevent a 233 // Drain the logging queue. Only writes out up to MAX_LOGS_TO_WRITE to prevent a
234 // case where a system is repeatedly spamming logs even on close. 234 // case where a system is repeatedly spamming logs even on close.
235 int max_logs_to_write = filter.IsDebug() ? INT_MAX : 100; 235 int max_logs_to_write = filter.IsDebug() ? INT_MAX : 100;
236 while (max_logs_to_write-- && message_queue.Pop(entry)) { 236 while (max_logs_to_write-- && message_queue.TryPop(entry)) {
237 write_logs(); 237 write_logs();
238 } 238 }
239 }); 239 });
@@ -273,7 +273,7 @@ private:
273 ColorConsoleBackend color_console_backend{}; 273 ColorConsoleBackend color_console_backend{};
274 FileBackend file_backend; 274 FileBackend file_backend;
275 275
276 MPSCQueue<Entry, true> message_queue{}; 276 MPSCQueue<Entry> message_queue{};
277 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; 278 std::jthread backend_thread;
279}; 279};