[*] Cleanup and harden log classes
This commit is contained in:
parent
a60c1e9503
commit
168e6e1e39
@ -17,11 +17,13 @@ namespace Aurora::Logging
|
||||
static AuUInt32 gIterator {};
|
||||
static AuThreadPrimitives::MutexSOO gMutex;
|
||||
|
||||
static const auto kBitsPerWord = 8 * sizeof(*gInUseMap);
|
||||
|
||||
AUKN_SYM bool LogClassInUse(AuUInt8 uIndex);
|
||||
|
||||
static bool TryAcquire(AuUInt8 uIdx)
|
||||
{
|
||||
if (AuAtomicSet(&gInUseMap[uIdx / (8 * sizeof(*gInUseMap))], uIdx % (8 * sizeof(*gInUseMap))))
|
||||
if (AuAtomicSet(&gInUseMap[uIdx / kBitsPerWord], uIdx % kBitsPerWord))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -32,7 +34,7 @@ namespace Aurora::Logging
|
||||
|
||||
static void Release(AuUInt8 uIdx)
|
||||
{
|
||||
if (AuAtomicUnset(&gInUseMap[uIdx / (8 * sizeof(*gInUseMap))], uIdx % (8 * sizeof(*gInUseMap))))
|
||||
if (AuAtomicUnset(&gInUseMap[uIdx / kBitsPerWord], uIdx % kBitsPerWord))
|
||||
{
|
||||
AuAtomicSub(&gAtomicInUseCount, 1u);
|
||||
|
||||
@ -63,7 +65,7 @@ namespace Aurora::Logging
|
||||
if (TryAcquire(uIndex))
|
||||
{
|
||||
gIterator = uIndex;
|
||||
return AuUInt8(i);
|
||||
return AuUInt8(uIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,23 +79,49 @@ namespace Aurora::Logging
|
||||
|
||||
AUKN_SYM void LogClassAssociateName(AuUInt8 uIndex, const AuString &str)
|
||||
{
|
||||
SetString(uIndex - AuLog::kLogLevelUsr, str);
|
||||
uIndex -= AuLog::kLogLevelUsr;
|
||||
|
||||
if (uIndex >= kAvailableSlots)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SetString(uIndex, str);
|
||||
}
|
||||
|
||||
AUKN_SYM const AuString &LogClassGetNameUnsafe(AuUInt8 uIndex)
|
||||
{
|
||||
return gStringMap[uIndex - AuLog::kLogLevelUsr];
|
||||
uIndex -= AuLog::kLogLevelUsr;
|
||||
|
||||
SysAssertDbg(uIndex >= kAvailableSlots);
|
||||
|
||||
return gStringMap[uIndex];
|
||||
}
|
||||
|
||||
AUKN_SYM AuString LogClassGetNameSafe(AuUInt8 uIndex)
|
||||
{
|
||||
AU_LOCK_GUARD(gMutex);
|
||||
return gStringMap[uIndex - AuLog::kLogLevelUsr];
|
||||
|
||||
uIndex -= AuLog::kLogLevelUsr;
|
||||
|
||||
if (uIndex >= kAvailableSlots)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return gStringMap[uIndex];
|
||||
}
|
||||
|
||||
AUKN_SYM void LogClassRelease(AuUInt8 uIndex)
|
||||
{
|
||||
Release(uIndex - AuLog::kLogLevelUsr);
|
||||
uIndex -= AuLog::kLogLevelUsr;
|
||||
|
||||
if (uIndex >= kAvailableSlots)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Release(uIndex);
|
||||
}
|
||||
|
||||
AUKN_SYM AuResult<AuUInt8> LogClassGetNext()
|
||||
@ -110,7 +138,13 @@ namespace Aurora::Logging
|
||||
AUKN_SYM bool LogClassInUse(AuUInt8 uIndex)
|
||||
{
|
||||
uIndex -= AuLog::kLogLevelUsr;
|
||||
return gInUseMap[uIndex / (8 * sizeof(*gInUseMap))] & (1u << (uIndex % (8 * sizeof(*gInUseMap))));
|
||||
|
||||
if (uIndex >= kAvailableSlots)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return AuTestBit(gInUseMap[uIndex / kBitsPerWord], uIndex % kBitsPerWord);
|
||||
}
|
||||
|
||||
AUKN_SYM AuUInt8 LogClassTotalAvailable()
|
||||
|
Loading…
Reference in New Issue
Block a user