46 lines
1.1 KiB
C++
46 lines
1.1 KiB
C++
/***
|
|
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"
|
|
#include "Async.hpp"
|
|
|
|
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);
|
|
}
|
|
} |