mirror of
https://github.com/PabloMK7/citra.git
synced 2024-11-28 02:14:07 +00:00
assert/logging: Stop the logging thread and flush the backends before crashing (#7146)
This commit is contained in:
parent
222b1cc0d7
commit
ceeda05798
3 changed files with 25 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <cstdlib>
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/logging/backend.h"
|
||||
#include "common/logging/log.h"
|
||||
|
||||
// For asserts we'd like to keep all the junk executed when an assert happens away from the
|
||||
|
@ -17,6 +18,7 @@
|
|||
if (!(_a_)) [[unlikely]] { \
|
||||
[]() CITRA_NO_INLINE CITRA_NO_RETURN { \
|
||||
LOG_CRITICAL(Debug, "Assertion Failed!"); \
|
||||
Common::Log::Stop(); \
|
||||
Crash(); \
|
||||
exit(1); \
|
||||
}(); \
|
||||
|
@ -28,6 +30,7 @@
|
|||
if (!(_a_)) [[unlikely]] { \
|
||||
[&]() CITRA_NO_INLINE CITRA_NO_RETURN { \
|
||||
LOG_CRITICAL(Debug, "Assertion Failed!\n" __VA_ARGS__); \
|
||||
Common::Log::Stop(); \
|
||||
Crash(); \
|
||||
exit(1); \
|
||||
}(); \
|
||||
|
@ -37,6 +40,7 @@
|
|||
#define UNREACHABLE() \
|
||||
([]() CITRA_NO_INLINE CITRA_NO_RETURN { \
|
||||
LOG_CRITICAL(Debug, "Unreachable code!"); \
|
||||
Common::Log::Stop(); \
|
||||
Crash(); \
|
||||
exit(1); \
|
||||
}())
|
||||
|
@ -44,6 +48,7 @@
|
|||
#define UNREACHABLE_MSG(...) \
|
||||
([&]() CITRA_NO_INLINE CITRA_NO_RETURN { \
|
||||
LOG_CRITICAL(Debug, "Unreachable code!\n" __VA_ARGS__); \
|
||||
Common::Log::Stop(); \
|
||||
Crash(); \
|
||||
exit(1); \
|
||||
}())
|
||||
|
|
|
@ -220,6 +220,10 @@ public:
|
|||
instance->StartBackendThread();
|
||||
}
|
||||
|
||||
static void Stop() {
|
||||
instance->StopBackendThread();
|
||||
}
|
||||
|
||||
Impl(const Impl&) = delete;
|
||||
Impl& operator=(const Impl&) = delete;
|
||||
|
||||
|
@ -330,6 +334,15 @@ private:
|
|||
});
|
||||
}
|
||||
|
||||
void StopBackendThread() {
|
||||
backend_thread.request_stop();
|
||||
if (backend_thread.joinable()) {
|
||||
backend_thread.join();
|
||||
}
|
||||
|
||||
ForEachBackend([](Backend& backend) { backend.Flush(); });
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -421,6 +434,10 @@ void Start() {
|
|||
Impl::Start();
|
||||
}
|
||||
|
||||
void Stop() {
|
||||
Impl::Stop();
|
||||
}
|
||||
|
||||
void DisableLoggingInTests() {
|
||||
initialization_in_progress_suppress_logging = true;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@ void Initialize(std::string_view log_file = "");
|
|||
|
||||
void Start();
|
||||
|
||||
/// Explictily stops the logger thread and flushes the buffers
|
||||
void Stop();
|
||||
|
||||
void DisableLoggingInTests();
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue