(urgent) fix log mutex breaking forward compat mode

yes, this single mutex would break geode loading in forward compat mode
entirely.. because the forward compat hooks log at static init time! and
since static init stuff is weird, the mutex wasnt initialized yet. so
now we force it to be initialized by having it in a getter
This commit is contained in:
matcool 2024-02-12 15:55:13 -03:00
parent 55dae8bde3
commit 456075a2cb

View file

@ -215,18 +215,22 @@ void Logger::setup() {
m_logStream = std::ofstream(dirs::getGeodeLogDir() / log::generateLogName());
}
std::mutex g_logMutex;
std::mutex& getLogMutex() {
static std::mutex mutex;
return mutex;
}
void Logger::push(Severity sev, std::string&& thread, std::string&& source, int32_t nestCount,
std::string&& content) {
Log* log;
{
std::lock_guard g(g_logMutex);
std::lock_guard g(getLogMutex());
log = &m_logs.emplace_back(sev, std::move(thread), std::move(source), nestCount,
std::move(content));
}
auto const logStr = log->toString();
{
std::lock_guard g(g_logMutex);
std::lock_guard g(getLogMutex());
console::log(logStr, log->getSeverity());
m_logStream << logStr << std::endl;
}
@ -241,7 +245,7 @@ std::vector<Log> const& Logger::list() {
}
void Logger::clear() {
std::lock_guard g(g_logMutex);
std::lock_guard g(getLogMutex());
m_logs.clear();
}