[+] IThreadPool::AddDependency
This commit is contained in:
parent
bde0014d16
commit
f265ca267a
@ -128,5 +128,11 @@ namespace Aurora::Async
|
||||
|
||||
//
|
||||
virtual AuSPtr<Aurora::Threading::IWaitable> GetShutdownEvent() = 0;
|
||||
|
||||
/**
|
||||
* @brief Prevents preemptive shutdown in ::SetRunningMode(true) mode given loosely held delegation thread pools
|
||||
* @param pPool
|
||||
*/
|
||||
virtual void AddDependency(AuSPtr<IThreadPool> pPool) = 0;
|
||||
};
|
||||
}
|
@ -55,6 +55,11 @@ namespace Aurora::Async
|
||||
return ThreadPool::GetShutdownEvent();
|
||||
}
|
||||
|
||||
void AsyncApp::AddDependency(AuSPtr<IThreadPool> pPool)
|
||||
{
|
||||
ThreadPool::AddDependency(pPool);
|
||||
}
|
||||
|
||||
void AsyncApp::CleanUpWorker(WorkerId_t id)
|
||||
{
|
||||
// This shouldn't be a problem; however, we're going to handle the one edge case where
|
||||
|
@ -55,6 +55,7 @@ namespace Aurora::Async
|
||||
void SetConsoleCommandDispatcher(WorkerId_t id) override;
|
||||
|
||||
AuSPtr<Aurora::Threading::IWaitable> GetShutdownEvent() override;
|
||||
void AddDependency(AuSPtr<IThreadPool> pPool) override;
|
||||
|
||||
void CleanUpWorker(WorkerId_t wid) override;
|
||||
void CleanWorkerPoolReservedZeroFree() override;
|
||||
|
@ -483,10 +483,9 @@ namespace Aurora::Async
|
||||
{
|
||||
if (InRunnerMode())
|
||||
{
|
||||
auto queue = ToKernelWorkQueue();
|
||||
|
||||
if ((this->uAtomicCounter == 0) &&
|
||||
(!queue || queue->GetSourceCount() <= 1))
|
||||
this->IsDepleted())
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
@ -514,7 +513,7 @@ namespace Aurora::Async
|
||||
auto queue = ToKernelWorkQueue();
|
||||
|
||||
if ((this->uAtomicCounter == tlsCallStack) &&
|
||||
(!queue || queue->GetSourceCount() <= 1 + this->uAtomicIOProcessorsWorthlessSources + this->uAtomicIOProcessors))
|
||||
this->IsDepleted())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -585,7 +584,7 @@ namespace Aurora::Async
|
||||
|
||||
if ((runningTasks == 0) &&
|
||||
(this->uAtomicCounter == 0) &&
|
||||
(!queue || queue->GetSourceCount() <= 1 + this->uAtomicIOProcessorsWorthlessSources + this->uAtomicIOProcessors))
|
||||
this->IsDepleted())
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
@ -1000,6 +999,43 @@ namespace Aurora::Async
|
||||
return worker->runMode;
|
||||
}
|
||||
|
||||
bool ThreadPool::IsSelfDepleted()
|
||||
{
|
||||
auto queue = ToKernelWorkQueue();
|
||||
return (!queue || queue->GetSourceCount() <= 1 + this->uAtomicIOProcessorsWorthlessSources + this->uAtomicIOProcessors);
|
||||
}
|
||||
|
||||
bool ThreadPool::IsDepleted()
|
||||
{
|
||||
if (!IsSelfDepleted())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto &wOther : this->listWeakDeps_)
|
||||
{
|
||||
if (auto pThat = AuTryLockMemoryType(wOther))
|
||||
{
|
||||
if (!pThat->IsSelfDepleted())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pThat->uAtomicCounter)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ThreadPool::AddDependency(AuSPtr<IThreadPool> pPool)
|
||||
{
|
||||
this->listWeakDeps_.push_back(AuStaticCast<ThreadPool>(pPool));
|
||||
}
|
||||
|
||||
AuSPtr<AuThreading::IWaitable> ThreadPool::GetShutdownEvent()
|
||||
{
|
||||
return AuSPtr<AuThreading::IWaitable>(AuSharedFromThis(), this->shutdownEvent_.AsPointer());
|
||||
|
@ -84,6 +84,10 @@ namespace Aurora::Async
|
||||
virtual ERunMode GetThreadRunMode(WorkerId_t workerId) override;
|
||||
|
||||
virtual AuSPtr<AuThreading::IWaitable> GetShutdownEvent() override;
|
||||
virtual void AddDependency(AuSPtr<IThreadPool> pPool) override;
|
||||
|
||||
bool IsSelfDepleted();
|
||||
bool IsDepleted();
|
||||
|
||||
//virtual bool ScheduleLoopSource(const AuSPtr<Loop::ILoopSource> &loopSource, WorkerId_t workerId, AuUInt32 timeout, const AuConsumer<AuSPtr<Loop::ILoopSource>, bool> &callback) override;
|
||||
|
||||
@ -142,6 +146,7 @@ namespace Aurora::Async
|
||||
AuThreadPrimitives::RWRenterableLock rwlock_;
|
||||
AuThreadPrimitives::Event shutdownEvent_;
|
||||
bool runnersRunning_ {};
|
||||
AuList<AuWPtr<ThreadPool>> listWeakDeps_;
|
||||
|
||||
friend struct KeepGroupAlive;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user