[+] Secret AuAsync::KeepThreadPoolAlive api (for now)

This commit is contained in:
Reece Wilson 2023-08-09 10:25:22 +01:00
parent dd13098022
commit e68dc02e7e
2 changed files with 31 additions and 1 deletions

View File

@ -586,7 +586,7 @@ namespace Aurora::Async
auto queue = ToKernelWorkQueue();
if ((runningTasks == 0) &&
(this->uAtomicCounter == 0 ) &&
(this->uAtomicCounter == 0) &&
(!queue || queue->GetSourceCount() <= 1 + this->uAtomicIOProcessorsWorthlessSources + this->uAtomicIOProcessors))
{
Shutdown();
@ -1512,4 +1512,32 @@ namespace Aurora::Async
StartSched();
return AuMakeShared<ThreadPool>();
}
struct KeepGroupAlive
{
KeepGroupAlive(AuSPtr<AuAsync::IThreadPool> pPool) : pPool(AuStaticCast<AuAsync::ThreadPool>(pPool))
{
AuAtomicAdd(&this->pPool->uAtomicCounter, 1u);
}
~KeepGroupAlive()
{
auto uNow = AuAtomicSub(&this->pPool->uAtomicCounter, 1u);
if (uNow == 0)
{
for (const auto &[group, pState] : this->pPool->threads_)
{
pState->BroadCast();
}
}
}
AuSPtr<AuAsync::ThreadPool> pPool;
};
AUKN_SYM AuSPtr<void> KeepThreadPoolAlive(AuSPtr<AuAsync::IThreadPool> pPool)
{
return AuMakeSharedThrow<KeepGroupAlive>(pPool);
}
}

View File

@ -143,5 +143,7 @@ namespace Aurora::Async
AuThreadPrimitives::RWRenterableLock rwlock_;
AuThreadPrimitives::Event shutdownEvent_;
bool runnersRunning_ {};
friend struct KeepGroupAlive;
};
}