AuroraRuntime/Include/Aurora/Async/IThreadPool.hpp

171 lines
6.3 KiB
C++
Raw Normal View History

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: IThreadPool.hpp
Date: 2021-11-1
Author: Reece
***/
#pragma once
namespace Aurora::IO::Loop
2022-03-10 15:35:01 +00:00
{
struct ILoopQueue;
struct ILoopSource;
2022-03-10 15:35:01 +00:00
}
namespace Aurora::IO::Net
{
struct INetInterface;
struct INetWorker;
}
namespace Aurora::IO::CompletionGroup
{
struct ICompletionGroup;
}
namespace Aurora::Async
{
struct IThreadPool
{
// Spawning
2022-08-20 06:53:48 +00:00
virtual bool Spawn(WorkerId_t workerId) = 0;
2022-08-20 06:53:48 +00:00
// Event runner threads release the thread pool upon encountering a zero work condition,
// allowing for a clean exit out of event driven apps, without the headache of carefully
// chaining together exit callbacks.
//
// Applications that aren't designed around an event driven model should set/keep running
2022-08-21 04:09:41 +00:00
// mode to false to keep-alive the runners during work exhaustion
2022-08-20 06:53:48 +00:00
//
// tl'dr: runner = true, async app; runner = false, thread pool
2022-08-21 04:09:41 +00:00
virtual void SetRunningMode(bool bRunnerMode) = 0;
// Converts the current thread into an async thread
// Use with RunOnce, Poll
2022-08-20 06:53:48 +00:00
virtual bool Create(WorkerId_t workerId) = 0;
2022-08-20 06:53:48 +00:00
//virtual bool CreateAndRun(WorkerId_t workerId) = 0;
// @returns any threads with runner = true
2022-08-20 06:53:48 +00:00
virtual bool InRunnerMode() = 0;
2022-08-20 06:53:48 +00:00
// Manual execution for ::Create() users and those wishing to nest ticks
virtual bool Poll() = 0;
// Block for one
2022-08-20 06:53:48 +00:00
virtual bool RunOnce() = 0;
// Block for standard execution
2022-08-20 06:53:48 +00:00
virtual bool Run() = 0;
// Poll for any counted
virtual AuUInt32 PollAndCount(bool bStrict = true) = 0;
// Alternative ::Poll that's safer to use with mixed IO
// Returns exact amount of AuAsync callbacks dispatched
virtual AuUInt32 RunAllPending() = 0;
//
2022-08-20 06:53:48 +00:00
virtual void Shutdown() = 0;
virtual bool Exiting() = 0;
//
2022-08-20 06:53:48 +00:00
virtual AuSPtr<IWorkItem> NewWorkItem(const WorkerId_t &worker,
const AuSPtr<IWorkItemHandler> &task) = 0;
virtual AuSPtr<IWorkItem> NewWorkFunction(const WorkerId_t &worker,
AuVoidFunc callback) = 0;
2022-08-20 06:53:48 +00:00
virtual AuSPtr<IWorkItem> NewFence() = 0;
//
2022-08-20 06:53:48 +00:00
virtual Threading::Threads::ThreadShared_t ResolveHandle(WorkerId_t) = 0;
//
2022-08-20 06:53:48 +00:00
virtual AuBST<ThreadGroup_t, AuList<ThreadId_t>> GetThreads() = 0;
//
2022-08-20 06:53:48 +00:00
virtual WorkerId_t GetCurrentThread() = 0;
//
virtual AuSPtr<IO::IIOProcessor> GetIOProcessor(WorkerId_t id) = 0;
virtual AuSPtr<IO::Net::INetInterface> GetIONetInterface(WorkerId_t id) = 0;
virtual AuSPtr<IO::Net::INetWorker> GetIONetWorker(WorkerId_t id) = 0;
virtual AuSPtr<IO::CompletionGroup::ICompletionGroup> GetIOGroup(WorkerId_t id) = 0;
// Synchronization
// Legacy Barrier: blocks a/a group of threads
[*/+/-] MEGA COMMIT. ~2 weeks compressed. The intention is to quickly improve and add util apis, enhance functionality given current demands, go back to the build pipeline, finish that, publish runtime tests, and then use what we have to go back to to linux support with a more stable api. [+] AuMakeSharedArray [+] Technet ArgvQuote [+] Grug subsystem (UNIX signal thread async safe ipc + telemetry flusher + log flusher.) [+] auEndianness -> Endian swap utils [+] AuGet<N>(...) [*] AUE_DEFINE conversion for ECompresionType, EAnsiColor, EHashType, EStreamError, EHexDump [+] ConsoleMessage ByteBuffer serialization [+] CmdLine subsystem for parsing command line arguments and simple switch/flag checks [*] Split logger from console subsystem [+] StartupParameters -> A part of a clean up effort under Process [*] Refactor SysErrors header + get caller hack [+] Atomic APIs [+] popcnt [+] Ring Buffer sink [+] Added more standard errors Catch, Submission, LockError, NoAccess, ResourceMissing, ResourceLocked, MalformedData, InSandboxContext, ParseError [+] Added ErrorCategorySet, ErrorCategoryClear, GetStackTrace [+] IExitSubscriber, ETriggerLevel [*] Write bias the high performance RWLockImpl read-lock operation operation [+] ExitHandlerAdd/ExitHandlerRemove (exit subsystem) [*] Updated API style Digests [+] CpuId::CpuBitCount [+] GetUserProgramsFolder [+] GetPackagePath [*] Split IStreamReader with an inl file [*] BlobWriter/BlobReader/BlobArbitraryReader can now take shared pointers to bytebuffers. default constructor allocates a new scalable bytebuffer [+] ICharacterProvider [+] ICharacterProviderEx [+] IBufferedCharacterConsumer [+] ProviderFromSharedString [+] ProviderFromString [+] BufferConsumerFromProvider [*] Parse Subsystem uses character io bufferer [*] Rewritten NT's high perf semaphore to use userland SRW/ConVars [like mutex, based on generic semaphore] [+] ByteBuffer::ResetReadPointer [*] Bug fix bytebuffer base not reset on free and some scaling issues [+] ProcessMap -> Added kSectionNameStack, kSectionNameFile, kSectionNameHeap for Section [*] ProcessMap -> Refactor Segment to Section. I was stupid for keeping a type conflict hack API facing [+] Added 64 *byte* fast RNG seeds [+] File Advisorys/File Lock Awareness [+] Added extended IAuroraThread from OS identifier caches for debug purposes [*] Tweaked how memory is reported on Windows. Better consistency of what values mean across functions. [*] Broke AuroraUtils/Typedefs out into a separate library [*] Update build script [+] Put some more effort into adding detail to the readme before rewriting it, plus, added some media [*] Improved public API documentation [*] Bug fix `SetConsoleCtrlHandler` [+] Locale TimeDateToFileNameISO8601 [+] Console config stdOutShortTime [*] Begin using internal UTF8/16 decoders when platform support isnt available (instead of stl) [*] Bug fixes in decoders [*] Major bug fix, AuMax [+] RateLimiter [+] Binary file sink [+] Log directory sink [*] Data header usability (more operators) [+] AuRemoveRange [+] AuRemove [+] AuTryRemove [+] AuTryRemoveRange [+] auCastUtils [+] Finish NewLSWin32Source [+] AuTryFindByTupleN, AuTryRemoveByTupleN [+] Separated AuRead/Write types, now in auTypeUtils [+] Added GetPosition/SetPosition to FileWriter [*] Fix stupid AuMin in place of AuMax in SpawnThread.Unix.Cpp [*] Refactored Arbitrary readers to SeekingReaders (as in, they could be atomic and/or parallelized, and accept an arbitrary position as a work parameter -> not Seekable, as in, you can simply set the position) [*] Hack back in the sched deinit [+] File AIO loop source interop [+] Begin to prototype a LoopQueue object I had in mind for NT, untested btw [+] Stub code for networking [+] Compression BaseStream/IngestableStreamBase [*] Major: read/write locks now support write-entrant read routines. [*] Compression subsystem now uses the MemoryView concept [*] Rewrite the base stream compressions, made them less broken [*] Update hashing api [*] WriterTryGoForward and ReaderTryGoForward now revert to the previous relative index instead of panicing [+] Added new AuByteBuffer apis Trim, Pad, WriteFrom, WriteString, [TODO: ReadString] [+] Added ByteBufferPushReadState [+] Added ByteBufferPushWriteState [*] Move from USC-16 to full UTF-16. Win32 can handle full UTF-16. [*] ELogLevel is now an Aurora enum [+] Raised arbitrary limit in header to 255, the max filter buffer [+] Explicit GZip support [+] Explicit Zip support [+] Added [some] compressors et al
2022-02-17 00:11:40 +00:00
// Note: syncing to yourself will nullify requireSignal to prevent deadlock conditions
2022-08-20 06:53:48 +00:00
virtual bool Sync(WorkerId_t workerId,
AuUInt32 timeoutMs = 0,
bool bRequireSignal = false) = 0;
// Legacy Barrier: wakes up a/a group of ::Sync()'d threads
2022-08-20 06:53:48 +00:00
virtual void Signal(WorkerId_t workerId) = 0;
// Breaks ::RunOnce()
virtual void Wakeup(WorkerId_t workerId) = 0;
2022-08-20 06:53:48 +00:00
virtual AuSPtr<IO::Loop::ILoopSource> WorkerToLoopSource(WorkerId_t id) = 0;
virtual void SyncAllSafe() = 0;
// Features
2022-08-20 06:53:48 +00:00
/**
* @brief
* @param id
* @param feature
* @param bDontBlockUntilComplete inverse of block until complete.
default: block until after IThreadFeature::Init
*/
virtual void AddFeature(WorkerId_t id,
AuSPtr<Threading::Threads::IThreadFeature> feature,
bool bDontBlockUntilComplete = false) = 0;
// Debug
2022-08-20 06:53:48 +00:00
virtual void AssertInThreadGroup(ThreadGroup_t group) = 0;
virtual void AssertWorker(WorkerId_t id) = 0;
2022-08-20 06:53:48 +00:00
// AuIO overlapped-IO glue
virtual AuSPtr<IO::Loop::ILoopQueue> ToKernelWorkQueue() = 0;
virtual AuSPtr<IO::Loop::ILoopQueue> ToKernelWorkQueue(WorkerId_t workerId) = 0;
//
virtual AuSPtr<Aurora::Threading::IWaitable> GetShutdownEvent() = 0;
2023-08-13 08:30:17 +00:00
/**
* @brief Prevents preemptive shutdown in ::SetRunningMode(true) mode given loosely held delegation thread pools
* @param pPool
*/
virtual void AddDependency(AuSPtr<IThreadPool> pPool) = 0;
/**
* @brief
*/
virtual void IncrementAbortFenceOnPool() = 0;
/**
* @brief
* @param workerId
*/
virtual void IncrementAbortFenceOnWorker(WorkerId_t workerId) = 0;
/**
* @brief
* @return
*/
virtual AuUInt64 QueryAbortFence(AuOptional<WorkerId_t> optWorkerId) = 0;
/**
* @brief
* @param uFenceMagic
* @return
*/
virtual bool QueryShouldAbort(AuOptional<WorkerId_t> optWorkerId, AuUInt64 uFenceMagic) = 0;
AURT_ADD_USR_DATA;
};
}