Common: Fix logging shutdown race condition.

Got a crash during logging on another thread during shutdown.
This commit is contained in:
Unknown W. Brackets 2021-01-01 08:38:27 -08:00
parent 84aa33970b
commit f57c642f0b
2 changed files with 12 additions and 8 deletions

View File

@ -156,6 +156,9 @@ LogManager::~LogManager() {
#endif #endif
} }
// Make sure we don't shutdown while logging. RemoveListener locks too, but there are gaps.
std::lock_guard<std::mutex> listeners_lock(listeners_lock_);
if (fileLog_) if (fileLog_)
delete fileLog_; delete fileLog_;
#if !defined(MOBILE_DEVICE) || defined(_DEBUG) #if !defined(MOBILE_DEVICE) || defined(_DEBUG)
@ -262,6 +265,7 @@ bool LogManager::IsEnabled(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type)
} }
void LogManager::Init(bool *enabledSetting) { void LogManager::Init(bool *enabledSetting) {
_assert_(logManager_ == nullptr);
logManager_ = new LogManager(enabledSetting); logManager_ = new LogManager(enabledSetting);
} }

View File

@ -1402,14 +1402,6 @@ void NativeShutdown() {
#endif #endif
g_Config.Save("NativeShutdown"); g_Config.Save("NativeShutdown");
// Avoid shutting this down when restarting core.
if (!restarting)
LogManager::Shutdown();
#ifdef ANDROID_NDK_PROFILER
moncleanup();
#endif
INFO_LOG(SYSTEM, "NativeShutdown called"); INFO_LOG(SYSTEM, "NativeShutdown called");
ShutdownWebServer(); ShutdownWebServer();
@ -1420,6 +1412,14 @@ void NativeShutdown() {
g_Discord.Shutdown(); g_Discord.Shutdown();
// Avoid shutting this down when restarting core.
if (!restarting)
LogManager::Shutdown();
#ifdef ANDROID_NDK_PROFILER
moncleanup();
#endif
if (logger) { if (logger) {
delete logger; delete logger;
logger = nullptr; logger = nullptr;