diff --git a/Source/Grug/AuGrug.cpp b/Source/Grug/AuGrug.cpp index c9c2bc13..d7c16f8b 100644 --- a/Source/Grug/AuGrug.cpp +++ b/Source/Grug/AuGrug.cpp @@ -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 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(); } } \ No newline at end of file diff --git a/Source/Grug/AuGrug.hpp b/Source/Grug/AuGrug.hpp index 79af1397..929859fb 100644 --- a/Source/Grug/AuGrug.hpp +++ b/Source/Grug/AuGrug.hpp @@ -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); } \ No newline at end of file diff --git a/Source/IO/AuIOHandle.NT.cpp b/Source/IO/AuIOHandle.NT.cpp index 6a0364fe..690790a8 100644 --- a/Source/IO/AuIOHandle.NT.cpp +++ b/Source/IO/AuIOHandle.NT.cpp @@ -11,6 +11,7 @@ #include "FS/FS.hpp" #include "FS/FileAdvisory.NT.hpp" +#include 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)