diff options
| author | 2023-12-26 11:46:04 -0500 | |
|---|---|---|
| committer | 2023-12-26 11:46:04 -0500 | |
| commit | 1559984f77c4cf7474a8f806046b709576e4e439 (patch) | |
| tree | 670b041b44aeff91afb8fce0e0e0bb288f86f326 /src | |
| parent | Merge pull request #12472 from FearlessTobi/port-7239 (diff) | |
| parent | assert/logging: Stop the logging thread and flush the backends before crashing (diff) | |
| download | yuzu-1559984f77c4cf7474a8f806046b709576e4e439.tar.gz yuzu-1559984f77c4cf7474a8f806046b709576e4e439.tar.xz yuzu-1559984f77c4cf7474a8f806046b709576e4e439.zip | |
Merge pull request #12471 from FearlessTobi/port-7146
Port citra-emu/citra#7146: "assert/logging: Stop the logging thread and flush the backends before crashing"
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/assert.cpp | 3 | ||||
| -rw-r--r-- | src/common/logging/backend.cpp | 17 | ||||
| -rw-r--r-- | src/common/logging/backend.h | 3 |
3 files changed, 23 insertions, 0 deletions
diff --git a/src/common/assert.cpp b/src/common/assert.cpp index 6026b7dc2..e2c2cade3 100644 --- a/src/common/assert.cpp +++ b/src/common/assert.cpp | |||
| @@ -3,16 +3,19 @@ | |||
| 3 | 3 | ||
| 4 | #include "common/assert.h" | 4 | #include "common/assert.h" |
| 5 | #include "common/common_funcs.h" | 5 | #include "common/common_funcs.h" |
| 6 | #include "common/logging/backend.h" | ||
| 6 | 7 | ||
| 7 | #include "common/settings.h" | 8 | #include "common/settings.h" |
| 8 | 9 | ||
| 9 | void assert_fail_impl() { | 10 | void assert_fail_impl() { |
| 10 | if (Settings::values.use_debug_asserts) { | 11 | if (Settings::values.use_debug_asserts) { |
| 12 | Common::Log::Stop(); | ||
| 11 | Crash(); | 13 | Crash(); |
| 12 | } | 14 | } |
| 13 | } | 15 | } |
| 14 | 16 | ||
| 15 | [[noreturn]] void unreachable_impl() { | 17 | [[noreturn]] void unreachable_impl() { |
| 18 | Common::Log::Stop(); | ||
| 16 | Crash(); | 19 | Crash(); |
| 17 | throw std::runtime_error("Unreachable code"); | 20 | throw std::runtime_error("Unreachable code"); |
| 18 | } | 21 | } |
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index d4f27197c..7a267f8c0 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp | |||
| @@ -208,6 +208,10 @@ public: | |||
| 208 | instance->StartBackendThread(); | 208 | instance->StartBackendThread(); |
| 209 | } | 209 | } |
| 210 | 210 | ||
| 211 | static void Stop() { | ||
| 212 | instance->StopBackendThread(); | ||
| 213 | } | ||
| 214 | |||
| 211 | Impl(const Impl&) = delete; | 215 | Impl(const Impl&) = delete; |
| 212 | Impl& operator=(const Impl&) = delete; | 216 | Impl& operator=(const Impl&) = delete; |
| 213 | 217 | ||
| @@ -259,6 +263,15 @@ private: | |||
| 259 | }); | 263 | }); |
| 260 | } | 264 | } |
| 261 | 265 | ||
| 266 | void StopBackendThread() { | ||
| 267 | backend_thread.request_stop(); | ||
| 268 | if (backend_thread.joinable()) { | ||
| 269 | backend_thread.join(); | ||
| 270 | } | ||
| 271 | |||
| 272 | ForEachBackend([](Backend& backend) { backend.Flush(); }); | ||
| 273 | } | ||
| 274 | |||
| 262 | Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, | 275 | Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, |
| 263 | const char* function, std::string&& message) const { | 276 | const char* function, std::string&& message) const { |
| 264 | using std::chrono::duration_cast; | 277 | using std::chrono::duration_cast; |
| @@ -313,6 +326,10 @@ void Start() { | |||
| 313 | Impl::Start(); | 326 | Impl::Start(); |
| 314 | } | 327 | } |
| 315 | 328 | ||
| 329 | void Stop() { | ||
| 330 | Impl::Stop(); | ||
| 331 | } | ||
| 332 | |||
| 316 | void DisableLoggingInTests() { | 333 | void DisableLoggingInTests() { |
| 317 | initialization_in_progress_suppress_logging = true; | 334 | initialization_in_progress_suppress_logging = true; |
| 318 | } | 335 | } |
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index 12e5e2498..2a9926e9e 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h | |||
| @@ -14,6 +14,9 @@ void Initialize(); | |||
| 14 | 14 | ||
| 15 | void Start(); | 15 | void Start(); |
| 16 | 16 | ||
| 17 | /// Explicitly stops the logger thread and flushes the buffers | ||
| 18 | void Stop(); | ||
| 19 | |||
| 17 | void DisableLoggingInTests(); | 20 | void DisableLoggingInTests(); |
| 18 | 21 | ||
| 19 | /** | 22 | /** |