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