2021-06-27 21:33:58 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: AsyncApp.hpp
|
|
|
|
Date: 2021-6-26
|
|
|
|
Author: Reece
|
|
|
|
***/
|
2021-06-27 21:25:29 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-11-05 17:34:23 +00:00
|
|
|
#include "ThreadPool.hpp"
|
|
|
|
|
2021-06-27 21:25:29 +00:00
|
|
|
namespace Aurora::Async
|
|
|
|
{
|
2021-11-05 17:34:23 +00:00
|
|
|
void InitApp();
|
|
|
|
void ReleaseApp();
|
2022-05-17 01:43:26 +00:00
|
|
|
|
|
|
|
inline struct AsyncApp *gAsyncApp;
|
2021-06-30 12:00:32 +00:00
|
|
|
|
2023-05-24 07:19:47 +00:00
|
|
|
struct AsyncApp : IAsyncApp, ThreadPool
|
2021-06-30 09:28:52 +00:00
|
|
|
{
|
2021-11-05 17:34:23 +00:00
|
|
|
bool Spawn(WorkerId_t workerId) override;
|
|
|
|
void SetRunningMode(bool eventRunning) override;
|
|
|
|
bool Create(WorkerId_t workerId) override;
|
|
|
|
bool InRunnerMode() override;
|
|
|
|
bool Poll() override;
|
|
|
|
bool RunOnce() override;
|
|
|
|
bool Run() override;
|
|
|
|
void Shutdown() override;
|
|
|
|
bool Exiting() override;
|
2023-03-05 12:55:07 +00:00
|
|
|
AuUInt32 PollAndCount(bool bStrict = true) override;
|
|
|
|
AuUInt32 RunAllPending() override;
|
2023-08-10 02:34:44 +00:00
|
|
|
AuSPtr<IWorkItem> NewWorkItem(const WorkerId_t &worker, const AuSPtr<IWorkItemHandler> &task) override;
|
|
|
|
AuSPtr<IWorkItem> NewWorkFunction(const WorkerId_t &worker, AuVoidFunc callback) override;
|
2021-11-05 17:34:23 +00:00
|
|
|
AuSPtr<IWorkItem> NewFence() override;
|
|
|
|
Threading::Threads::ThreadShared_t ResolveHandle(WorkerId_t) override;
|
|
|
|
AuBST<ThreadGroup_t, AuList<ThreadId_t>> GetThreads() override;
|
|
|
|
WorkerId_t GetCurrentThread() override;
|
|
|
|
bool Sync(WorkerId_t workerId, AuUInt32 timeoutMs = 0, bool requireSignal = false) override;
|
2023-03-05 12:55:07 +00:00
|
|
|
AuSPtr<AuLoop::ILoopSource> WorkerToLoopSource(WorkerId_t id) override;
|
2021-11-05 17:34:23 +00:00
|
|
|
void Signal(WorkerId_t workerId) override;
|
2024-05-03 10:32:31 +00:00
|
|
|
void Wakeup(WorkerId_t workerId) override;
|
2021-11-05 17:34:23 +00:00
|
|
|
void SyncAllSafe() override;
|
|
|
|
void AddFeature(WorkerId_t id, AuSPtr<Threading::Threads::IThreadFeature> feature, bool async) override;
|
|
|
|
void AssertInThreadGroup(ThreadGroup_t group) override;
|
|
|
|
void AssertWorker(WorkerId_t id) override;
|
2023-12-01 09:22:51 +00:00
|
|
|
AuSPtr<AuIO::IIOProcessor> GetIOProcessor(WorkerId_t pid) override;
|
|
|
|
AuSPtr<AuIO::Net::INetInterface> GetIONetInterface(WorkerId_t pid) override;
|
|
|
|
AuSPtr<AuIO::Net::INetWorker> GetIONetWorker(WorkerId_t pid) override;
|
2023-03-05 12:55:07 +00:00
|
|
|
AuSPtr<AuLoop::ILoopQueue> ToKernelWorkQueue() override;
|
|
|
|
AuSPtr<AuLoop::ILoopQueue> ToKernelWorkQueue(WorkerId_t workerId) override;
|
2024-07-12 16:22:07 +00:00
|
|
|
AuSPtr<IO::CompletionGroup::ICompletionGroup> GetIOGroup(WorkerId_t id) override;
|
2021-06-30 09:28:52 +00:00
|
|
|
|
|
|
|
// Main thread logic
|
2023-03-05 12:55:07 +00:00
|
|
|
void Start() override;
|
|
|
|
void Main() override;
|
|
|
|
void SetConsoleCommandDispatcher(WorkerId_t id) override;
|
2021-06-30 09:28:52 +00:00
|
|
|
|
2023-05-24 07:19:47 +00:00
|
|
|
AuSPtr<Aurora::Threading::IWaitable> GetShutdownEvent() override;
|
2023-08-13 08:30:17 +00:00
|
|
|
void AddDependency(AuSPtr<IThreadPool> pPool) override;
|
2023-05-24 07:19:47 +00:00
|
|
|
|
2023-10-24 14:33:30 +00:00
|
|
|
void IncrementAbortFenceOnPool() override;
|
|
|
|
void IncrementAbortFenceOnWorker(WorkerId_t workerId) override;
|
|
|
|
|
|
|
|
AuUInt64 QueryAbortFence(AuOptional<WorkerId_t> optWorkerId) override;
|
|
|
|
bool QueryShouldAbort(AuOptional<WorkerId_t> optWorkerId, AuUInt64 uFenceMagic) override;
|
|
|
|
|
2021-11-05 17:34:23 +00:00
|
|
|
void CleanUpWorker(WorkerId_t wid) override;
|
|
|
|
void CleanWorkerPoolReservedZeroFree() override;
|
2021-06-30 09:28:52 +00:00
|
|
|
|
2021-09-06 10:58:08 +00:00
|
|
|
AuOptional<WorkerId_t> commandDispatcher_;
|
2021-06-30 09:28:52 +00:00
|
|
|
};
|
2021-06-27 21:25:29 +00:00
|
|
|
}
|