2021-11-05 17:34:23 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: GroupState.hpp
|
|
|
|
Date: 2021-11-1
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
#include "ThreadState.hpp"
|
|
|
|
|
|
|
|
namespace Aurora::Async
|
|
|
|
{
|
2023-09-05 12:54:05 +00:00
|
|
|
struct ThreadPool;
|
2023-05-25 00:55:55 +00:00
|
|
|
struct GroupWorkQueue
|
|
|
|
{
|
|
|
|
AuThreadPrimitives::Mutex mutex;
|
|
|
|
AuUInt32 uItems {};
|
|
|
|
AuList<WorkEntry_t> sortedWork[AuAsync::kEWorkPrioCount];
|
|
|
|
|
|
|
|
bool IsEmpty();
|
2023-09-05 12:54:05 +00:00
|
|
|
bool IsEmpty(ThreadPool *pPool, AuWorkerId_t id);
|
2023-05-25 00:55:55 +00:00
|
|
|
|
2023-09-05 12:54:05 +00:00
|
|
|
void AddWorkEntry(ThreadState *pState, WorkEntry_t entry);
|
2023-05-25 00:55:55 +00:00
|
|
|
|
|
|
|
void Dequeue(AuList<WorkEntry_t> &queue, int maxPopCount, AuAsync::ThreadId_t idd);
|
|
|
|
};
|
|
|
|
|
2021-11-05 17:34:23 +00:00
|
|
|
struct GroupState
|
|
|
|
{
|
|
|
|
ThreadGroup_t group;
|
|
|
|
|
2023-05-25 00:55:55 +00:00
|
|
|
GroupWorkQueue workQueue;
|
2021-11-05 17:34:23 +00:00
|
|
|
|
2023-05-25 00:55:55 +00:00
|
|
|
AuThreadPrimitives::Mutex workersMutex;
|
2021-11-05 17:34:23 +00:00
|
|
|
AuBST<ThreadId_t, AuSPtr<ThreadState>> workers;
|
2023-05-25 00:55:55 +00:00
|
|
|
AuWPtr<ThreadState> wpWorkers[32];
|
2021-11-05 17:34:23 +00:00
|
|
|
|
|
|
|
bool Init();
|
|
|
|
|
2023-05-25 00:55:55 +00:00
|
|
|
void BroadCast();
|
|
|
|
|
|
|
|
void AddWorker(ThreadId_t id, AuSPtr<ThreadState> pState);
|
|
|
|
|
|
|
|
AuSPtr<ThreadState> GetThreadByIndex(ThreadId_t uIndex);
|
|
|
|
|
2021-11-05 17:34:23 +00:00
|
|
|
bool inline IsSysThread()
|
|
|
|
{
|
|
|
|
return group == 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|