AuroraRuntime/Source/Async/GroupState.cpp
Reece 6af9940bd4 [*] Rewrite a bit of AuAsync
(maybe 1/3 of a rewrite)
2023-05-25 01:55:55 +01:00

63 lines
1.4 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: GroupState.cpp
Date: 2021-11-1
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Async.hpp"
#include "GroupState.hpp"
#include <Source/IO/Loop/LSAsync.hpp>
namespace Aurora::Async
{
bool GroupState::Init()
{
return true;
}
AuSPtr<ThreadState> GroupState::GetThreadByIndex(ThreadId_t uIndex)
{
AU_LOCK_GUARD(this->workersMutex);
if (AuArraySize(this->wpWorkers) > uIndex)
{
if (auto pState = AuTryLockMemoryType(this->wpWorkers[uIndex]))
{
return pState;
}
}
auto itr = this->workers.find(uIndex);
if (itr == this->workers.end())
{
return {};
}
return itr->second;
}
void GroupState::BroadCast()
{
AU_LOCK_GUARD(this->workersMutex);
for (const auto &worker : this->workers)
{
worker.second->cvVariable->Broadcast();
worker.second->eventLs->Set();
}
}
void GroupState::AddWorker(ThreadId_t id, AuSPtr<ThreadState> pState)
{
AU_LOCK_GUARD(this->workersMutex);
if (AuArraySize(this->wpWorkers) > id)
{
this->wpWorkers[id] = pState;
}
SysAssert(AuTryInsert(this->workers, AuMakePair(id, pState)));
}
}