summaryrefslogtreecommitdiffstats
path: root/src/common/logging
diff options
context:
space:
mode:
authorB3n30 <benediktthomas@gmail.com>2018-09-09 13:08:57 +0200
committerfearlessTobi <thm.frey@gmail.com>2019-02-15 22:12:54 +0100
commit41549365680f0aae3f82e5812f3470305e939f7d (patch)
tree027ec302d0119e4ded6cc4627c6fa3a94c8699ec /src/common/logging
parentMerge pull request #2112 from lioncash/shadowing (diff)
downloadyuzu-41549365680f0aae3f82e5812f3470305e939f7d.tar
yuzu-41549365680f0aae3f82e5812f3470305e939f7d.tar.gz
yuzu-41549365680f0aae3f82e5812f3470305e939f7d.tar.bz2
yuzu-41549365680f0aae3f82e5812f3470305e939f7d.tar.lz
yuzu-41549365680f0aae3f82e5812f3470305e939f7d.tar.xz
yuzu-41549365680f0aae3f82e5812f3470305e939f7d.tar.zst
yuzu-41549365680f0aae3f82e5812f3470305e939f7d.zip
Diffstat (limited to 'src/common/logging')
-rw-r--r--src/common/logging/backend.cpp20
-rw-r--r--src/common/logging/backend.h1
2 files changed, 8 insertions, 13 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index a5e031189..276e49f86 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -40,9 +40,7 @@ public:
const Impl& operator=(Impl const&) = delete;
void PushEntry(Entry e) {
- std::lock_guard<std::mutex> lock(message_mutex);
message_queue.Push(std::move(e));
- message_cv.notify_one();
}
void AddBackend(std::unique_ptr<Backend> backend) {
@@ -85,16 +83,13 @@ private:
backend->Write(e);
}
};
- while (true) {
- {
- std::unique_lock<std::mutex> lock(message_mutex);
- message_cv.wait(lock, [&] { return !running || message_queue.Pop(entry); });
- }
- if (!running) {
+ while (message_queue.PopWait(entry)) {
+ if (entry.final_entry) {
break;
}
write_logs(entry);
}
+
// 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.
const int MAX_LOGS_TO_WRITE = filter.IsDebug() ? INT_MAX : 100;
@@ -106,14 +101,13 @@ private:
}
~Impl() {
- running = false;
- message_cv.notify_one();
+ Entry entry;
+ entry.final_entry = true;
+ message_queue.Push(entry);
backend_thread.join();
}
- std::atomic_bool running{true};
- std::mutex message_mutex, writing_mutex;
- std::condition_variable message_cv;
+ std::mutex writing_mutex;
std::thread backend_thread;
std::vector<std::unique_ptr<Backend>> backends;
Common::MPSCQueue<Log::Entry> message_queue;
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h
index 91bb0c309..a31ee6968 100644
--- a/src/common/logging/backend.h
+++ b/src/common/logging/backend.h
@@ -27,6 +27,7 @@ struct Entry {
unsigned int line_num;
std::string function;
std::string message;
+ bool final_entry = false;
Entry() = default;
Entry(Entry&& o) = default;