[+] NT: Let Grug handle io handle closures

This commit is contained in:
Reece Wilson 2023-12-13 02:31:59 +00:00
parent a3046658fe
commit e7d8e5b010
3 changed files with 46 additions and 4 deletions

View File

@ -30,10 +30,12 @@ namespace Aurora::Grug
static const auto kGrugSleepMs = 100;
static const auto kGrugFlushMs = 500;
static AuThreads::ThreadUnique_t gGrugsBigWorld;
static AuThreadPrimitives::ConditionMutex gMutex; // ^ that
static AuThreadPrimitives::ConditionVariable gCondVar(AuUnsafeRaiiToShared(gMutex.AsPointer())); // slow logger work queue
static AuThreadPrimitives::Semaphore gArrows;
static AuThreads::ThreadUnique_t gGrugsBigWorld;
static AuCondMutex gMutex; // ^ that
static AuConditionVariable gCondVar(AuUnsafeRaiiToShared(gMutex.AsPointer())); // slow logger work queue
static AuSemaphore gArrows;
static AuMutex gOtherMutex;
static AuList<AuUInt> gHandlesToClose;
static void SlowStartupTasks()
{
@ -100,6 +102,7 @@ namespace Aurora::Grug
::LinuxSuperSecretIOTick();
#endif
GrugDoIoWork();
}
}
@ -189,10 +192,41 @@ namespace Aurora::Grug
Logging::ForceFlushLoggers();
}
void GrugDoIoWork()
{
if (gHandlesToClose.empty())
{
return;
}
AU_LOCK_GUARD(gOtherMutex);
for (const auto uHandle : AuExchange(gHandlesToClose, {}))
{
#if defined(AURORA_IS_MODERNNT_DERIVED)
auto pHandle = (void *)uHandle;
AuWin32CloseHandle(pHandle);
#elif defined(AURORA_IS_POSIX_DERIVED)
close(uHandle);
#endif
}
}
void GrugFlushFlushs()
{
Logging::ForceFlushFlush();
Console::PumpOffMain();
Console::ForceFlush();
GrugDoIoWork();
}
void CloseHandle(AuUInt64 handle)
{
{
AU_DEBUG_MEMCRUNCH;
AU_LOCK_GUARD(gOtherMutex);
gHandlesToClose.push_back(handle);
}
NotifyGrugOfTelemetry();
}
}

View File

@ -16,10 +16,13 @@ namespace Aurora::Grug
void GrugFlushFlushs();
void NotifyGrugOfLogs();
void NotifyGrugOfTelemetry();
void GrugDoIoWork();
void DrachenlordScreech();
bool IsGrug();
void InitGrug();
void DeinitGrug();
void CloseHandle(AuUInt64 handle);
}

View File

@ -11,6 +11,7 @@
#include "FS/FS.hpp"
#include "FS/FileAdvisory.NT.hpp"
#include <Source/Grug/AuGrug.hpp>
namespace Aurora::IO
{
@ -41,8 +42,12 @@ namespace Aurora::IO
void AFileHandle::CloseHandle(AuUInt64 uOSHandle)
{
#if 0
HANDLE hHandle = (HANDLE)uOSHandle;
AuWin32CloseHandle(hHandle);
#else
Grug::CloseHandle(uOSHandle);
#endif
}
void AFileHandle::InitStdIn(bool bSharing)