AuroraRuntime/Source/Async/AsyncApp.cpp

266 lines
6.2 KiB
C++
Raw Permalink Normal View History

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AsyncApp.cpp
Date: 2021-6-26
Author: Reece
***/
2021-09-30 14:57:41 +00:00
#include <Source/RuntimeInternal.hpp>
2021-06-30 09:28:52 +00:00
#include "Async.hpp"
2021-06-27 21:25:29 +00:00
#include "AsyncApp.hpp"
2021-06-30 09:28:52 +00:00
#include "WorkItem.hpp"
#include "AuSchedular.hpp"
2021-09-30 14:57:41 +00:00
#include <Source/Console/Commands/Commands.hpp>
2021-06-27 21:25:29 +00:00
2021-06-27 21:25:29 +00:00
namespace Aurora::Async
{
static AuSPtr<AsyncApp> gAsyncAppMem;
2021-06-30 12:00:32 +00:00
void InitApp()
2021-06-30 12:00:32 +00:00
{
gAsyncAppMem = AuMakeShared<AsyncApp>();
gAsyncApp = gAsyncAppMem.get();
2021-06-30 12:00:32 +00:00
}
void ReleaseApp()
2021-06-30 12:00:32 +00:00
{
2023-07-07 18:39:28 +00:00
if (gAsyncAppMem)
{
gAsyncAppMem->Shutdown();
AuResetMember(gAsyncAppMem);
AuResetMember(gAsyncApp);
2023-07-07 18:39:28 +00:00
}
2021-06-30 12:00:32 +00:00
}
void AsyncApp::Start()
2021-06-30 09:28:52 +00:00
{
ThreadPool::SetRunningMode(true);
SysAssert(ThreadPool::Create({ 0, 0 }));
StartSched(); // this is now an init once function
2021-06-30 09:28:52 +00:00
}
void AsyncApp::Main()
2021-06-30 09:28:52 +00:00
{
ThreadPool::Entrypoint({ 0, 0 });
2021-06-30 09:28:52 +00:00
}
void AsyncApp::SetConsoleCommandDispatcher(WorkerId_t id)
2021-06-30 09:28:52 +00:00
{
this->commandDispatcher_ = id;
Console::Commands::UpdateDispatcher(WorkerPId_t(GetSharedAsyncApp(), id));
2021-06-30 09:28:52 +00:00
}
AuSPtr<Aurora::Threading::IWaitable> AsyncApp::GetShutdownEvent()
{
return ThreadPool::GetShutdownEvent();
}
2023-08-13 08:30:17 +00:00
void AsyncApp::AddDependency(AuSPtr<IThreadPool> pPool)
{
ThreadPool::AddDependency(pPool);
}
void AsyncApp::CleanUpWorker(WorkerId_t id)
2021-06-30 09:28:52 +00:00
{
// This shouldn't be a problem; however, we're going to handle the one edge case where
// some angry sysadmin is spamming commands
if ((commandDispatcher_.has_value())
&& (commandDispatcher_.value() == id))
{
Console::Commands::UpdateDispatcher({});
}
2021-06-30 09:28:52 +00:00
}
void AsyncApp::CleanWorkerPoolReservedZeroFree()
{
[*/+/-] 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
// TODO: this is a hack. we need to reference count
DeinitSched();
ThreadPool::Shutdown();
}
void AsyncApp::IncrementAbortFenceOnPool()
{
ThreadPool::IncrementAbortFenceOnPool();
}
void AsyncApp::IncrementAbortFenceOnWorker(WorkerId_t workerId)
{
ThreadPool::IncrementAbortFenceOnWorker(workerId);
}
AuUInt64 AsyncApp::QueryAbortFence(AuOptional<WorkerId_t> optWorkerId)
{
return ThreadPool::QueryAbortFence(optWorkerId);
}
bool AsyncApp::QueryShouldAbort(AuOptional<WorkerId_t> optWorkerId, AuUInt64 uFenceMagic)
{
return ThreadPool::QueryShouldAbort(optWorkerId, uFenceMagic);
}
AUKN_SYM IAsyncApp *GetAsyncApp()
{
2022-06-23 12:25:20 +00:00
return gAsyncAppMem.get();
}
2022-03-23 16:33:02 +00:00
AUKN_SYM AuSPtr<IAsyncApp> GetSharedAsyncApp()
{
2022-06-23 12:25:20 +00:00
return gAsyncAppMem;
2022-03-23 16:33:02 +00:00
}
bool AsyncApp::Spawn(WorkerId_t workerId)
{
return ThreadPool::Spawn(workerId);
}
2021-06-30 09:28:52 +00:00
void AsyncApp::SetRunningMode(bool eventRunning)
{
ThreadPool::SetRunningMode(eventRunning);
}
bool AsyncApp::Create(WorkerId_t workerId)
{
return ThreadPool::Create(workerId);
}
bool AsyncApp::InRunnerMode()
2021-06-30 09:28:52 +00:00
{
return ThreadPool::InRunnerMode();
2021-06-30 09:28:52 +00:00
}
bool AsyncApp::Poll()
2021-06-30 09:28:52 +00:00
{
return ThreadPool::Poll();
2021-06-30 09:28:52 +00:00
}
bool AsyncApp::RunOnce()
2021-06-30 09:28:52 +00:00
{
return ThreadPool::RunOnce();
2021-06-30 09:28:52 +00:00
}
bool AsyncApp::Run()
{
return ThreadPool::Run();
}
2021-06-30 09:28:52 +00:00
AuUInt32 AsyncApp::PollAndCount(bool bStrict)
{
return ThreadPool::PollAndCount(bStrict);
}
AuUInt32 AsyncApp::RunAllPending()
{
return ThreadPool::RunAllPending();
}
2021-06-30 09:28:52 +00:00
void AsyncApp::Shutdown()
{
ThreadPool::Shutdown();
2021-06-30 09:28:52 +00:00
}
bool AsyncApp::Exiting()
{
return ThreadPool::Exiting();
2021-06-30 09:28:52 +00:00
}
AuSPtr<IWorkItem> AsyncApp::NewWorkItem(const WorkerId_t &worker, const AuSPtr<IWorkItemHandler> &task)
{
return ThreadPool::NewWorkItem(worker, task);
}
AuSPtr<IWorkItem> AsyncApp::NewWorkFunction(const WorkerId_t &worker, AuVoidFunc callback)
{
return ThreadPool::NewWorkFunction(worker, callback);
2021-06-30 09:28:52 +00:00
}
AuSPtr<IWorkItem> AsyncApp::NewFence()
2021-06-30 09:28:52 +00:00
{
return ThreadPool::NewFence();
}
Threading::Threads::ThreadShared_t AsyncApp::ResolveHandle(WorkerId_t id)
{
return ThreadPool::ResolveHandle(id);
2021-06-30 09:28:52 +00:00
}
AuBST<ThreadGroup_t, AuList<ThreadId_t>> AsyncApp::GetThreads()
{
return ThreadPool::GetThreads();
2021-06-30 09:28:52 +00:00
}
WorkerId_t AsyncApp::GetCurrentThread()
{
return ThreadPool::GetCurrentThread();
2021-06-30 09:28:52 +00:00
}
bool AsyncApp::Sync(WorkerId_t workerId, AuUInt32 timeoutMs, bool requireSignal)
2021-06-30 09:28:52 +00:00
{
return ThreadPool::Sync(workerId, timeoutMs, requireSignal);
2021-06-30 09:28:52 +00:00
}
AuSPtr<AuLoop::ILoopSource> AsyncApp::WorkerToLoopSource(WorkerId_t id)
[*/+/-] 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
{
return ThreadPool::WorkerToLoopSource(id);
}
void AsyncApp::Signal(WorkerId_t workerId)
2021-06-30 09:28:52 +00:00
{
ThreadPool::Signal(workerId);
2021-06-30 09:28:52 +00:00
}
void AsyncApp::Wakeup(WorkerId_t workerId)
{
ThreadPool::Wakeup(workerId);
}
2021-06-30 09:28:52 +00:00
void AsyncApp::SyncAllSafe()
{
ThreadPool::SyncAllSafe();
}
2021-06-30 09:28:52 +00:00
void AsyncApp::AddFeature(WorkerId_t id, AuSPtr<Threading::Threads::IThreadFeature> feature, bool async)
{
ThreadPool::AddFeature(id, feature, async);
2021-06-30 09:28:52 +00:00
}
void AsyncApp::AssertInThreadGroup(ThreadGroup_t group)
{
ThreadPool::AssertInThreadGroup(group);
2021-06-30 09:28:52 +00:00
}
void AsyncApp::AssertWorker(WorkerId_t id)
{
ThreadPool::AssertWorker(id);
2021-06-30 09:28:52 +00:00
}
AuSPtr<AuIO::IIOProcessor> AsyncApp::GetIOProcessor(WorkerId_t pid)
{
return ThreadPool::GetIOProcessor(pid);
}
AuSPtr<AuIO::Net::INetInterface> AsyncApp::GetIONetInterface(WorkerId_t pid)
{
return ThreadPool::GetIONetInterface(pid);
}
AuSPtr<AuIO::Net::INetWorker> AsyncApp::GetIONetWorker(WorkerId_t pid)
{
return ThreadPool::GetIONetWorker(pid);
}
AuSPtr<IO::CompletionGroup::ICompletionGroup> AsyncApp::GetIOGroup(WorkerId_t pid)
{
return ThreadPool::GetIOGroup(pid);
}
AuSPtr<AuLoop::ILoopQueue> AsyncApp::ToKernelWorkQueue()
2021-06-30 09:28:52 +00:00
{
2022-03-10 15:35:01 +00:00
return ThreadPool::ToKernelWorkQueue();
}
AuSPtr<AuLoop::ILoopQueue> AsyncApp::ToKernelWorkQueue(WorkerId_t workerId)
2022-03-10 15:35:01 +00:00
{
return ThreadPool::ToKernelWorkQueue(workerId);
}
2021-06-27 21:25:29 +00:00
}