2023-11-11 10:11:09 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: AuAsyncKeepGroupAlive.cpp
|
|
|
|
Date: 2023-11-04
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#include <Source/RuntimeInternal.hpp>
|
|
|
|
#include "AuAsyncKeepGroupAlive.hpp"
|
|
|
|
#include "ThreadPool.hpp"
|
2023-11-11 11:27:01 +00:00
|
|
|
#include "Async.hpp"
|
2023-11-11 10:11:09 +00:00
|
|
|
|
|
|
|
namespace Aurora::Async
|
|
|
|
{
|
|
|
|
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 &pState : this->pPool->threadGroups_)
|
|
|
|
{
|
|
|
|
if (pState)
|
|
|
|
{
|
|
|
|
pState->SignalAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AuSPtr<AuAsync::ThreadPool> pPool;
|
|
|
|
};
|
|
|
|
|
|
|
|
AUKN_SYM AuSPtr<void> KeepThreadPoolAlive(AuSPtr<AuAsync::IThreadPool> pPool)
|
|
|
|
{
|
|
|
|
return AuMakeSharedThrow<KeepGroupAlive>(pPool);
|
|
|
|
}
|
|
|
|
}
|