summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2022-03-03 04:09:26 +0100
committerGitHub <noreply@github.com>2022-03-03 04:09:26 +0100
commita31c19574982d81d299f94d52fed2a28352f8fe8 (patch)
treee6c4d98cd050183f40f8fe74732584f797a54c75
parentMerge pull request #7956 from bunnei/improve-mem-manager (diff)
parentlogging: Convert `backend_thread` into an `std::jthread` (diff)
downloadyuzu-a31c19574982d81d299f94d52fed2a28352f8fe8.tar
yuzu-a31c19574982d81d299f94d52fed2a28352f8fe8.tar.gz
yuzu-a31c19574982d81d299f94d52fed2a28352f8fe8.tar.bz2
yuzu-a31c19574982d81d299f94d52fed2a28352f8fe8.tar.lz
yuzu-a31c19574982d81d299f94d52fed2a28352f8fe8.tar.xz
yuzu-a31c19574982d81d299f94d52fed2a28352f8fe8.tar.zst
yuzu-a31c19574982d81d299f94d52fed2a28352f8fe8.zip
-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:
Impl(const std::filesystem::path& file_backend_filename, const Filter& filter_)
: filter{filter_}, file_backend{file_backend_filename} {}
- ~Impl() {
- StopBackendThread();
- }
+ ~Impl() = default;
void StartBackendThread() {
- backend_thread = std::thread([this] {
+ backend_thread = std::jthread([this](std::stop_token stop_token) {
Common::SetCurrentThreadName("yuzu:Log");
Entry entry;
const auto write_logs = [this, &entry]() {
ForEachBackend([&entry](Backend& backend) { backend.Write(entry); });
};
- while (!stop.stop_requested()) {
- entry = message_queue.PopWait(stop.get_token());
+ while (!stop_token.stop_requested()) {
+ entry = message_queue.PopWait(stop_token);
if (entry.filename != nullptr) {
write_logs();
}
@@ -244,11 +242,6 @@ private:
});
}
- void StopBackendThread() {
- stop.request_stop();
- backend_thread.join();
- }
-
Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr,
const char* function, std::string&& message) const {
using std::chrono::duration_cast;
@@ -283,8 +276,7 @@ private:
ColorConsoleBackend color_console_backend{};
FileBackend file_backend;
- std::stop_source stop;
- std::thread backend_thread;
+ std::jthread backend_thread;
MPSCQueue<Entry, true> message_queue{};
std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()};
};