AuroraRuntime/Source/Async/AuGroupState.hpp

43 lines
1018 B
C++
Raw Normal View History

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
2023-11-11 11:27:01 +00:00
File: AuGroupState.hpp
Date: 2021-11-1
Author: Reece
***/
#pragma once
#include "ThreadState.hpp"
#include "AuGroupWorkQueue.hpp"
namespace Aurora::Async
{
2023-09-05 12:54:05 +00:00
struct ThreadPool;
struct GroupState :
AuEnableSharedFromThis<GroupState>
{
// group id
ThreadGroup_t group;
// work items
GroupWorkQueue workQueue;
// tracked workers
AuThreadPrimitives::Mutex workersMutex;
AuFutexMutex deinitMutex;
AuBST<ThreadId_t, AuSPtr<ThreadState>> workers;
AuWPtr<ThreadState> wpWorkers[32]; // linear non-locking lookup table
//
bool Init();
void SignalAll();
2023-10-25 19:08:42 +00:00
void Decommit(ThreadId_t id);
bool AddWorker(ThreadId_t id, AuSPtr<ThreadState> pState);
AuSPtr<ThreadState> CreateWorker(WorkerId_t id, bool bCreate);
AuSPtr<ThreadState> GetThreadByIndex(ThreadId_t uIndex);
};
}