summaryrefslogtreecommitdiff
path: root/src/common/logging/backend.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2019-02-16 15:34:49 -0500
committerGravatar GitHub2019-02-16 15:34:49 -0500
commitcd7e1183e21002e9941e97358ff373abfade9132 (patch)
tree10f77ac5b28e08f1380a27410b15d0e0ab92e9c9 /src/common/logging/backend.cpp
parentMerge pull request #2123 from lioncash/coretiming-global (diff)
parentAdressed review comments (diff)
downloadyuzu-cd7e1183e21002e9941e97358ff373abfade9132.tar.gz
yuzu-cd7e1183e21002e9941e97358ff373abfade9132.tar.xz
yuzu-cd7e1183e21002e9941e97358ff373abfade9132.zip
Merge pull request #2128 from FearlessTobi/port-4197
Port citra-emu/citra#4197: "threadsafe_queue: Add PopWait and use it where possible "
Diffstat (limited to 'src/common/logging/backend.cpp')
-rw-r--r--src/common/logging/backend.cpp19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index a5e031189..b369f199f 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -40,9 +40,7 @@ public:
40 const Impl& operator=(Impl const&) = delete; 40 const Impl& operator=(Impl const&) = delete;
41 41
42 void PushEntry(Entry e) { 42 void PushEntry(Entry e) {
43 std::lock_guard<std::mutex> lock(message_mutex);
44 message_queue.Push(std::move(e)); 43 message_queue.Push(std::move(e));
45 message_cv.notify_one();
46 } 44 }
47 45
48 void AddBackend(std::unique_ptr<Backend> backend) { 46 void AddBackend(std::unique_ptr<Backend> backend) {
@@ -86,15 +84,13 @@ private:
86 } 84 }
87 }; 85 };
88 while (true) { 86 while (true) {
89 { 87 entry = message_queue.PopWait();
90 std::unique_lock<std::mutex> lock(message_mutex); 88 if (entry.final_entry) {
91 message_cv.wait(lock, [&] { return !running || message_queue.Pop(entry); });
92 }
93 if (!running) {
94 break; 89 break;
95 } 90 }
96 write_logs(entry); 91 write_logs(entry);
97 } 92 }
93
98 // Drain the logging queue. Only writes out up to MAX_LOGS_TO_WRITE to prevent a case 94 // Drain the logging queue. Only writes out up to MAX_LOGS_TO_WRITE to prevent a case
99 // where a system is repeatedly spamming logs even on close. 95 // where a system is repeatedly spamming logs even on close.
100 const int MAX_LOGS_TO_WRITE = filter.IsDebug() ? INT_MAX : 100; 96 const int MAX_LOGS_TO_WRITE = filter.IsDebug() ? INT_MAX : 100;
@@ -106,14 +102,13 @@ private:
106 } 102 }
107 103
108 ~Impl() { 104 ~Impl() {
109 running = false; 105 Entry entry;
110 message_cv.notify_one(); 106 entry.final_entry = true;
107 message_queue.Push(entry);
111 backend_thread.join(); 108 backend_thread.join();
112 } 109 }
113 110
114 std::atomic_bool running{true}; 111 std::mutex writing_mutex;
115 std::mutex message_mutex, writing_mutex;
116 std::condition_variable message_cv;
117 std::thread backend_thread; 112 std::thread backend_thread;
118 std::vector<std::unique_ptr<Backend>> backends; 113 std::vector<std::unique_ptr<Backend>> backends;
119 Common::MPSCQueue<Log::Entry> message_queue; 114 Common::MPSCQueue<Log::Entry> message_queue;