diff options
author | bunnei <bunneidev@gmail.com> | 2019-02-16 15:34:49 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-16 15:34:49 -0500 |
commit | cd7e1183e21002e9941e97358ff373abfade9132 (patch) | |
tree | 10f77ac5b28e08f1380a27410b15d0e0ab92e9c9 /src/common/logging/backend.cpp | |
parent | 99da6362c43a24c608a2790f668f10a62e3b80a6 (diff) | |
parent | 2195f10d152a52e01ccab0a6528f8758752d66a9 (diff) |
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.cpp | 19 |
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: 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) { @@ -86,15 +84,13 @@ private: } }; while (true) { - { - std::unique_lock<std::mutex> lock(message_mutex); - message_cv.wait(lock, [&] { return !running || message_queue.Pop(entry); }); - } - if (!running) { + entry = message_queue.PopWait(); + 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 +102,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; |