[*] Fix race condition. Read after logger detor bug in rw to spinlock optimization
This commit is contained in:
parent
cd8cfd4f1c
commit
c6d649e3de
@ -125,10 +125,11 @@ namespace Aurora::Grug
|
||||
|
||||
void DeinitGrug()
|
||||
{
|
||||
Aurora::Grug::GrugFlushWrites();
|
||||
Aurora::Grug::GrugFlushFlushs();
|
||||
|
||||
gGrugsBigWorld.reset();
|
||||
|
||||
GrugFlushWrites();
|
||||
GrugFlushFlushs();
|
||||
|
||||
gMutex.reset();
|
||||
gCondVar.reset();
|
||||
gArrows.reset();
|
||||
|
@ -16,6 +16,7 @@ namespace Aurora::Logging
|
||||
|
||||
static AuList<AuTuple<Logger *, AuUInt8, ConsoleMessage>> gLogTasks;
|
||||
static AuThreadPrimitives::SpinLock gGlobalSpin;
|
||||
static AuThreadPrimitives::SpinLock gTaskSpin;
|
||||
static AuList<Logger *> gFlushableLoggers;
|
||||
|
||||
Logger::Logger(const AuList<AuSPtr<IBasicSink>> &sinks) : sinks(sinks)
|
||||
@ -85,7 +86,7 @@ namespace Aurora::Logging
|
||||
void Logger::AddToPushQueue(AuUInt8 level, const ConsoleMessage &msg)
|
||||
{
|
||||
{
|
||||
AU_LOCK_GUARD(gGlobalSpin);
|
||||
AU_LOCK_GUARD(gTaskSpin);
|
||||
|
||||
while (!AuTryInsert(gLogTasks, AuMakeTuple(this, level, msg)))
|
||||
{
|
||||
@ -141,13 +142,50 @@ namespace Aurora::Logging
|
||||
void ForceFlushLoggers()
|
||||
{
|
||||
decltype(gLogTasks) logTasks;
|
||||
AU_LOCK_GUARD(gGlobalSpin);
|
||||
|
||||
{
|
||||
AU_LOCK_GUARD(gGlobalSpin);
|
||||
AU_LOCK_GUARD(gTaskSpin);
|
||||
|
||||
try
|
||||
{
|
||||
logTasks = AuExchange(gLogTasks, {});
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (logTasks.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
for (const auto &logEntry : logTasks)
|
||||
{
|
||||
auto &logger = AuGet<0>(logEntry);
|
||||
auto &level = AuGet<1>(logEntry);
|
||||
auto &message = AuGet<2>(logEntry);
|
||||
|
||||
logger->WriteLater(level, message);
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ForceFlushLoggersNoLock()
|
||||
{
|
||||
decltype(gLogTasks) logTasks;
|
||||
|
||||
{
|
||||
try
|
||||
{
|
||||
logTasks = AuExchange(gLogTasks, {});
|
||||
}
|
||||
catch (...)
|
||||
@ -206,17 +244,18 @@ namespace Aurora::Logging
|
||||
|
||||
void Logger::Disable()
|
||||
{
|
||||
AU_LOCK_GUARD(gGlobalSpin);
|
||||
|
||||
ForceFlushLoggersNoLock();
|
||||
|
||||
{
|
||||
AU_LOCK_GUARD(spin);
|
||||
AuMemset(shouldFilter, 1, sizeof(shouldFilter));
|
||||
}
|
||||
|
||||
{
|
||||
AU_LOCK_GUARD(gGlobalSpin);
|
||||
AuTryDeleteList(gFlushableLoggers, this);
|
||||
}
|
||||
|
||||
ForceFlushLoggers();
|
||||
}
|
||||
|
||||
bool Logger::WriteNow(AuUInt8 level, const ConsoleMessage &msg)
|
||||
|
@ -34,7 +34,10 @@ namespace Aurora::Logging
|
||||
AuUInt8 shouldFilter[0xFF];
|
||||
};
|
||||
|
||||
AuThreadPrimitives::SpinLock &GetLock();
|
||||
|
||||
void ForceFlushLoggers();
|
||||
void ForceFlushLoggersNoLock();
|
||||
void ForceFlushFlush();
|
||||
|
||||
void DeinitLoggers();
|
||||
|
Loading…
Reference in New Issue
Block a user