From b8fde0bdf04f8c0154da8ec375f5c4dc5484cd62 Mon Sep 17 00:00:00 2001 From: Reece Date: Sun, 24 Oct 2021 11:19:47 +0100 Subject: [PATCH] [*] Refactor and clean up exception and threading API [-] Deprecated abstract vectors struct --- .../Aurora/Compression/StreamProcessor.hpp | 4 +-- Include/Aurora/Locale/Encoding/Encoding.hpp | 13 ++++---- Include/Aurora/Loop/Loop.hpp | 2 +- Include/Aurora/Runtime.hpp | 1 + ...ctThreadVectors.hpp => IThreadVectors.hpp} | 10 ++----- .../Aurora/Threading/Threads/ThreadInfo.hpp | 7 ++--- Include/Aurora/Threading/Threads/Threads.hpp | 2 +- Source/Async/AsyncApp.cpp | 30 +++++++++---------- Source/Async/AsyncApp.hpp | 2 +- Source/Async/Schedular.cpp | 4 +-- Source/Async/WorkItem.cpp | 4 +-- Source/Async/WorkItem.hpp | 4 +-- Source/Compression/BlockCompressor.hpp | 4 +-- Source/Compression/BlockDecompressor.cpp | 18 +++++------ Source/Compression/BlockDecompressor.hpp | 4 +-- Source/Console/Commands/Commands.cpp | 4 +-- Source/Console/ConsoleFIO/ConsoleFIO.cpp | 4 +-- Source/Console/ConsoleStd/ConsoleStd.cpp | 2 +- .../ConsoleWxWidgets/ConsoleWxWidgets.cpp | 26 +++++++--------- Source/Console/Flusher.cpp | 13 ++++---- Source/Console/Hooks/Hooks.cpp | 10 +++---- Source/Crypto/PEM/PEM.cpp | 2 +- Source/Debug/ExceptionWatcher.Win32.cpp | 23 +++++--------- Source/Locale/Encoding/Encoding.cpp | 12 ++++---- Source/Loop/LSCondition.cpp | 2 +- Source/Memory/Heap.cpp | 4 +-- Source/Processes/Process.Win32.cpp | 15 ++++++---- Source/RNG/WELL.hpp | 2 +- Source/RNG/mtwister.hpp | 2 +- Source/Registry/Registry.cpp | 4 +-- Source/Threading/Primitives/Event.cpp | 4 +-- Source/Threading/Threads/OSThread.cpp | 15 ++-------- Source/Threading/Threads/Threads.cpp | 2 +- Source/Threading/WaitFor.hpp | 2 +- 34 files changed, 115 insertions(+), 142 deletions(-) rename Include/Aurora/Threading/Threads/{AbstractThreadVectors.hpp => IThreadVectors.hpp} (73%) diff --git a/Include/Aurora/Compression/StreamProcessor.hpp b/Include/Aurora/Compression/StreamProcessor.hpp index 139e732c..88017c13 100644 --- a/Include/Aurora/Compression/StreamProcessor.hpp +++ b/Include/Aurora/Compression/StreamProcessor.hpp @@ -11,6 +11,6 @@ namespace Aurora::Compression { - AUKN_SHARED_API(Decompressor, ICompressionStream, const AuSPtr &reader, const DecompressInfo &info); - AUKN_SHARED_API(Compressor, ICompressionStream, const AuSPtr &reader, const CompressionInfo &info); + AUKN_SHARED_API(Decompressor, ICompressionStream, const AuSPtr &reader, const DecompressInfo &info); + AUKN_SHARED_API(Compressor, ICompressionStream, const AuSPtr &reader, const CompressionInfo &info); } \ No newline at end of file diff --git a/Include/Aurora/Locale/Encoding/Encoding.hpp b/Include/Aurora/Locale/Encoding/Encoding.hpp index 1882326b..2c3bc525 100644 --- a/Include/Aurora/Locale/Encoding/Encoding.hpp +++ b/Include/Aurora/Locale/Encoding/Encoding.hpp @@ -9,17 +9,18 @@ namespace Aurora::Locale::Encoding { - AUKN_SYM AuStreamReadWrittenPair_t EncodeUTF8(const Aurora::Memory::MemoryViewRead &utf8, const Aurora::Memory::MemoryViewWrite &binary, ECodePage page = ECodePage::eUnsupported); - static inline AuStreamReadWrittenPair_t EncodeUTF8(const AuString &utf8, const Aurora::Memory::MemoryViewWrite &binary, ECodePage page = ECodePage::eUnsupported) + AUKN_SYM AuStreamReadWrittenPair_t EncodeUTF8(const Memory::MemoryViewRead &utf8, const Memory::MemoryViewWrite &binary, ECodePage page = ECodePage::eUnsupported); + + static inline AuStreamReadWrittenPair_t EncodeUTF8(const AuString &utf8, const Memory::MemoryViewWrite &binary, ECodePage page = ECodePage::eUnsupported) { - return EncodeUTF8(Aurora::Memory::MemoryViewRead(utf8), binary, page); + return EncodeUTF8(Memory::MemoryViewRead(utf8), binary, page); } - AUKN_SYM std::optional> DecodeBOM(const Aurora::Memory::MemoryViewRead & binary); + AUKN_SYM std::optional> DecodeBOM(const Memory::MemoryViewRead & binary); /// Translates a buffer, possibly a slice of a stream, to UTF-8 /// Returns a pair; bytes consumed, bytes written - AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const Aurora::Memory::MemoryViewRead &binary, const Aurora::Memory::MemoryViewWrite &utf8, ECodePage page = ECodePage::eUnsupported); + AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const Memory::MemoryViewRead &binary, const Memory::MemoryViewWrite &utf8, ECodePage page = ECodePage::eUnsupported); - AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const Aurora::Memory::MemoryViewRead &binary, AuString &out, ECodePage page = ECodePage::eUnsupported); + AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const Memory::MemoryViewRead &binary, AuString &out, ECodePage page = ECodePage::eUnsupported); } \ No newline at end of file diff --git a/Include/Aurora/Loop/Loop.hpp b/Include/Aurora/Loop/Loop.hpp index a875cdff..0b602d00 100644 --- a/Include/Aurora/Loop/Loop.hpp +++ b/Include/Aurora/Loop/Loop.hpp @@ -79,7 +79,7 @@ namespace Aurora::Loop virtual void UpdateTime(AuUInt64 absTimeMs) = 0; }; - AUKN_SYM AuSPtr NewLSCondVar(const AuSPtr &primitive); + AUKN_SYM AuSPtr NewLSCondVar(const AuSPtr &primitive); AUKN_SYM AuSPtr NewLSCondVar(const AuSPtr &source); AUKN_SYM AuSPtr NewLSTimer(AuUInt64 absTimeMs); diff --git a/Include/Aurora/Runtime.hpp b/Include/Aurora/Runtime.hpp index f3e0c5d1..021f1a9d 100644 --- a/Include/Aurora/Runtime.hpp +++ b/Include/Aurora/Runtime.hpp @@ -90,6 +90,7 @@ namespace AuTelemetry = Aurora::Telemetry; namespace AuTime = Aurora::Time; namespace AuTypes = Aurora::Types; namespace AuLog = Aurora::Console::Logging; +namespace AuMemory = Aurora::Memory; static inline void AuDebugBreak() { diff --git a/Include/Aurora/Threading/Threads/AbstractThreadVectors.hpp b/Include/Aurora/Threading/Threads/IThreadVectors.hpp similarity index 73% rename from Include/Aurora/Threading/Threads/AbstractThreadVectors.hpp rename to Include/Aurora/Threading/Threads/IThreadVectors.hpp index 4014eb91..58e82552 100644 --- a/Include/Aurora/Threading/Threads/AbstractThreadVectors.hpp +++ b/Include/Aurora/Threading/Threads/IThreadVectors.hpp @@ -1,7 +1,7 @@ /*** Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. - File: AbstractThreadVectors.hpp + File: IThreadVectors.hpp Date: 2021-6-11 Author: Reece ***/ @@ -11,16 +11,10 @@ namespace Aurora::Threading::Threads { class IAuroraThread; - /*! + /* User-provided interface-style callback structure of thread related events
DoRun/DoExit are called within the threads context */ - /// @deprecated - struct AbstractThreadVectors - { - AuConsumer DoRun; - AuConsumer DoExit; - }; AUKN_INTERFACE(IThreadVectors, AUI_METHOD(void, OnEntry, (IAuroraThread *, thread)), diff --git a/Include/Aurora/Threading/Threads/ThreadInfo.hpp b/Include/Aurora/Threading/Threads/ThreadInfo.hpp index 59e6d5aa..a2166012 100644 --- a/Include/Aurora/Threading/Threads/ThreadInfo.hpp +++ b/Include/Aurora/Threading/Threads/ThreadInfo.hpp @@ -11,14 +11,11 @@ namespace Aurora::Threading::Threads { struct ThreadInfo { - /// @deprecated - AbstractThreadVectors vectors; AuSPtr callbacks; - /// @deprecated - ThreadInfo(const AbstractThreadVectors &vectors) : vectors(vectors) + ThreadInfo() {} - + ThreadInfo(const AuSPtr &callbacks) : callbacks(callbacks) {} diff --git a/Include/Aurora/Threading/Threads/Threads.hpp b/Include/Aurora/Threading/Threads/Threads.hpp index 8a02f265..1d5babbb 100644 --- a/Include/Aurora/Threading/Threads/Threads.hpp +++ b/Include/Aurora/Threading/Threads/Threads.hpp @@ -9,7 +9,7 @@ #include "IThreadFeature.hpp" #include "EThreadPrio.hpp" -#include "AbstractThreadVectors.hpp" +#include "IThreadVectors.hpp" #include "IAuroraThread.hpp" #include "ThreadInfo.hpp" #include "Thread.hpp" diff --git a/Source/Async/AsyncApp.cpp b/Source/Async/AsyncApp.cpp index 449d4ec8..131f09f6 100644 --- a/Source/Async/AsyncApp.cpp +++ b/Source/Async/AsyncApp.cpp @@ -60,7 +60,7 @@ namespace Aurora::Async //std::stack jmpStack; AuWPtr parent; - Threading::Primitives::SemaphoreUnique_t syncSema; + AuThreadPrimitives::SemaphoreUnique_t syncSema; AuList> features; bool rejecting {}; @@ -68,7 +68,7 @@ namespace Aurora::Async bool inLoopSourceMode {}; bool shuttingdown {}; - Threading::Primitives::EventUnique_t running; + AuThreadPrimitives::EventUnique_t running; //bool running; bool inline IsSysThread() @@ -84,8 +84,8 @@ namespace Aurora::Async { ThreadGroup_t group; - Threading::Primitives::ConditionMutexUnique_t cvWorkMutex; - Threading::Primitives::ConditionVariableUnique_t cvVariable; + AuThreadPrimitives::ConditionMutexUnique_t cvWorkMutex; + AuThreadPrimitives::ConditionVariableUnique_t cvVariable; AuSPtr eventLs; AuList workQueue; @@ -102,13 +102,13 @@ namespace Aurora::Async bool GroupState::Init() { - this->cvWorkMutex = Threading::Primitives::ConditionMutexUnique(); + this->cvWorkMutex = AuThreadPrimitives::ConditionMutexUnique(); if (!this->cvWorkMutex) { return false; } - this->cvVariable = Threading::Primitives::ConditionVariableUnique(AuUnsafeRaiiToShared(this->cvWorkMutex)); + this->cvVariable = AuThreadPrimitives::ConditionVariableUnique(AuUnsafeRaiiToShared(this->cvWorkMutex)); if (!this->cvVariable) { return false; @@ -124,7 +124,7 @@ namespace Aurora::Async AsyncApp::AsyncApp() { - this->rwlock_ = Threading::Primitives::RWLockUnique(); + this->rwlock_ = AuThreadPrimitives::RWLockUnique(); SysAssert(static_cast(this->rwlock_), "Couldn't initialize AsyncApp. Unable to allocate an RWLock"); } @@ -350,7 +350,7 @@ namespace Aurora::Async } } - auto time = Aurora::Time::CurrentClockMS(); + auto time = Time::CurrentClockMS(); state->loopSources.clear(); state->loopSources.reserve(curLoopReq.size()); @@ -700,19 +700,17 @@ namespace Aurora::Async auto threadState = AuMakeShared(); threadState->parent = group; - threadState->running = Threading::Primitives::EventUnique(true, false, true); - threadState->syncSema = Threading::Primitives::SemaphoreUnique(0); + threadState->running = AuThreadPrimitives::EventUnique(true, false, true); + threadState->syncSema = AuThreadPrimitives::SemaphoreUnique(0); threadState->id = workerId; threadState->eventDriven = true; if (!threadState->IsSysThread()) { - Threading::Threads::AbstractThreadVectors handler; - handler.DoRun = [=](const Threading::Threads::IAuroraThread *thread) - { - Entrypoint(threadState->id); - }; - threadState->threadObject = Threading::Threads::ThreadUnique(handler); + threadState->threadObject = AuThreading::Threads::ThreadUnique(AuThreading::Threads::ThreadInfo( + AuMakeShared(AuThreading::Threads::IThreadVectorsFunctional::OnEntry_t(std::bind(&AsyncApp::Entrypoint, this, threadState->id)), + AuThreading::Threads::IThreadVectorsFunctional::OnExit_t{}) + )); threadState->threadObject->Run(); } else diff --git a/Source/Async/AsyncApp.hpp b/Source/Async/AsyncApp.hpp index 0c66216c..5b8b613c 100644 --- a/Source/Async/AsyncApp.hpp +++ b/Source/Async/AsyncApp.hpp @@ -76,7 +76,7 @@ namespace Aurora::Async // TODO: BarrierMultiple bool Barrier(WorkerId_t, AuUInt32 ms, bool requireSignal, bool drop); - Threading::Primitives::RWLockUnique_t rwlock_; + AuThreadPrimitives::RWLockUnique_t rwlock_; AuSPtr GetGroup(ThreadGroup_t type); diff --git a/Source/Async/Schedular.cpp b/Source/Async/Schedular.cpp index 77a2032a..112e9ce9 100644 --- a/Source/Async/Schedular.cpp +++ b/Source/Async/Schedular.cpp @@ -20,7 +20,7 @@ namespace Aurora::Async }; static Threading::Threads::ThreadUnique_t gThread; - static Threading::Primitives::MutexUnique_t gSchedLock; + static AuThreadPrimitives::MutexUnique_t gSchedLock; static AuList gEntries; static void GetDispatchableTasks(AuList &pending) @@ -103,7 +103,7 @@ namespace Aurora::Async void InitSched() { - gSchedLock = Threading::Primitives::MutexUnique(); + gSchedLock = AuThreadPrimitives::MutexUnique(); } void DeinitSched() diff --git a/Source/Async/WorkItem.cpp b/Source/Async/WorkItem.cpp index 4e2fc767..f9110266 100644 --- a/Source/Async/WorkItem.cpp +++ b/Source/Async/WorkItem.cpp @@ -17,7 +17,7 @@ namespace Aurora::Async { if (supportsBlocking) { - finishedEvent_ = Threading::Primitives::EventUnique(false, true, true); + finishedEvent_ = AuThreadPrimitives::EventUnique(false, true, true); SysAssert(finishedEvent_); } } @@ -284,7 +284,7 @@ namespace Aurora::Async void WorkItem::Schedule() { - Aurora::Async::Schedule(dispatchTimeNs_, worker_, this->shared_from_this()); + Async::Schedule(dispatchTimeNs_, worker_, this->shared_from_this()); } void WorkItem::SendOff() diff --git a/Source/Async/WorkItem.hpp b/Source/Async/WorkItem.hpp index b081be13..58215bc8 100644 --- a/Source/Async/WorkItem.hpp +++ b/Source/Async/WorkItem.hpp @@ -44,8 +44,8 @@ namespace Aurora::Async WorkerId_t worker_; AuList> waitOn_; AuList> waiters_; - Threading::Primitives::SpinLock lock; - Threading::Primitives::EventUnique_t finishedEvent_; + AuThreadPrimitives::SpinLock lock; + AuThreadPrimitives::EventUnique_t finishedEvent_; bool finished {}; bool failed {}; diff --git a/Source/Compression/BlockCompressor.hpp b/Source/Compression/BlockCompressor.hpp index 4596b4d9..38f5db2a 100644 --- a/Source/Compression/BlockCompressor.hpp +++ b/Source/Compression/BlockCompressor.hpp @@ -16,7 +16,7 @@ namespace Aurora::Compression virtual ~BaseCompressionStream() {} - virtual bool Init(const AuSPtr &reader) = 0; + virtual bool Init(const AuSPtr &reader) = 0; virtual AuStreamReadWrittenPair_t Process(AuUInt32 len) = 0; virtual void ProcessFlush() = 0; @@ -34,7 +34,7 @@ namespace Aurora::Compression bool Write(const void *a, AuUInt32 length); protected: - Aurora::Memory::ByteBuffer _outbuffer; + Memory::ByteBuffer _outbuffer; AuUInt32 _lastCount, _count; }; } \ No newline at end of file diff --git a/Source/Compression/BlockDecompressor.cpp b/Source/Compression/BlockDecompressor.cpp index a288f75c..f5aaff23 100644 --- a/Source/Compression/BlockDecompressor.cpp +++ b/Source/Compression/BlockDecompressor.cpp @@ -115,7 +115,7 @@ namespace Aurora::Compression } } - bool Init(const AuSPtr &reader) + bool Init(const AuSPtr &reader) { this->reader_ = reader; this->dctx_ = ZSTD_createDCtx(); @@ -172,7 +172,7 @@ namespace Aurora::Compression private: - AuSPtr reader_; + AuSPtr reader_; ZSTD_DCtx *dctx_; char din_[ZSTD_BLOCKSIZE_MAX + 3 /*ZSTD_BLOCKHEADERSIZE*/]; char dout_[ZSTD_BLOCKSIZE_MAX]; @@ -195,7 +195,7 @@ namespace Aurora::Compression } } - bool Init(const AuSPtr &reader) + bool Init(const AuSPtr &reader) { this->reader_ = reader; @@ -263,7 +263,7 @@ namespace Aurora::Compression private: - AuSPtr reader_; + AuSPtr reader_; z_stream ctx_ {}; bool init_ {}; unsigned char din_[4096]; @@ -286,7 +286,7 @@ namespace Aurora::Compression } } - bool Init(const AuSPtr &reader) + bool Init(const AuSPtr &reader) { this->reader_ = reader; @@ -347,7 +347,7 @@ namespace Aurora::Compression private: - AuSPtr reader_; + AuSPtr reader_; bz_stream ctx_ {}; bool init_ {}; char dout_[4096]; @@ -372,7 +372,7 @@ namespace Aurora::Compression } } - bool Init(const AuSPtr &reader) + bool Init(const AuSPtr &reader) { this->reader_ = reader; @@ -459,11 +459,11 @@ namespace Aurora::Compression private: - AuSPtr reader_; + AuSPtr reader_; LZ4F_dctx* lz4Stream_ {}; }; - AUKN_SYM ICompressionStream *DecompressorNew(const AuSPtr &reader, const DecompressInfo &ref) + AUKN_SYM ICompressionStream *DecompressorNew(const AuSPtr &reader, const DecompressInfo &ref) { DecompressInfo info = ref; BaseStream * ret{}; diff --git a/Source/Compression/BlockDecompressor.hpp b/Source/Compression/BlockDecompressor.hpp index 175982e7..bf9ab99f 100644 --- a/Source/Compression/BlockDecompressor.hpp +++ b/Source/Compression/BlockDecompressor.hpp @@ -16,7 +16,7 @@ namespace Aurora::Compression virtual ~BaseStream() {} - virtual bool Init(const AuSPtr &reader) = 0; + virtual bool Init(const AuSPtr &reader) = 0; virtual bool ReadByProcessedN(void * /*opt*/, AuUInt32 minimumInflated) override; virtual bool ReadByProcessedN(void * /*opt*/, AuUInt32 minimumInflated, AuStreamReadWrittenPair_t &pair, bool ingestUntilEOS = true) override; @@ -31,6 +31,6 @@ namespace Aurora::Compression virtual void Flush() override {} protected: - Aurora::Memory::ByteBuffer _outbuffer; + Memory::ByteBuffer _outbuffer; }; } \ No newline at end of file diff --git a/Source/Console/Commands/Commands.cpp b/Source/Console/Commands/Commands.cpp index 1fafd360..92478a37 100644 --- a/Source/Console/Commands/Commands.cpp +++ b/Source/Console/Commands/Commands.cpp @@ -16,8 +16,8 @@ namespace Aurora::Console::Commands static AuHashMap gCommands; static AuList gLineCallbacks; static AuList gPendingCommands; - static auto gMutex = Threading::Primitives::MutexUnique(); - static auto gPendingCommandsMutex = Threading::Primitives::MutexUnique(); + static auto gMutex = AuThreadPrimitives::MutexUnique(); + static auto gPendingCommandsMutex = AuThreadPrimitives::MutexUnique(); static AuOptional gCommandDispatcher; struct Command diff --git a/Source/Console/ConsoleFIO/ConsoleFIO.cpp b/Source/Console/ConsoleFIO/ConsoleFIO.cpp index e3d10f31..bc454f87 100644 --- a/Source/Console/ConsoleFIO/ConsoleFIO.cpp +++ b/Source/Console/ConsoleFIO/ConsoleFIO.cpp @@ -11,7 +11,7 @@ namespace Aurora::Console::ConsoleFIO { static AuList gLogBuffer; - static Threading::Primitives::RWLockUnique_t gLogMutex; + static AuThreadPrimitives::RWLockUnique_t gLogMutex; static IO::FS::OpenWriteUnique_t gFileHandle; static const auto &gLogConfig = gRuntimeConfig.console.fio; @@ -143,7 +143,7 @@ namespace Aurora::Console::ConsoleFIO return; } - gLogMutex = Threading::Primitives::RWLockUnique(); + gLogMutex = AuThreadPrimitives::RWLockUnique(); if (!gLogMutex) { return; diff --git a/Source/Console/ConsoleStd/ConsoleStd.cpp b/Source/Console/ConsoleStd/ConsoleStd.cpp index 56ca57b4..4ff74f5c 100644 --- a/Source/Console/ConsoleStd/ConsoleStd.cpp +++ b/Source/Console/ConsoleStd/ConsoleStd.cpp @@ -53,7 +53,7 @@ namespace Aurora::Console::ConsoleStd static StreamHandle_t gInputStream = DEFAULT_HANDLE_VAL; static StreamHandle_t gOutputStream = DEFAULT_HANDLE_VAL; - static Threading::Primitives::SpinLock gRingLock; + static AuThreadPrimitives::SpinLock gRingLock; #if defined(AURORA_IS_MODERNNT_DERIVED) diff --git a/Source/Console/ConsoleWxWidgets/ConsoleWxWidgets.cpp b/Source/Console/ConsoleWxWidgets/ConsoleWxWidgets.cpp index 916fe39e..a8d11b95 100644 --- a/Source/Console/ConsoleWxWidgets/ConsoleWxWidgets.cpp +++ b/Source/Console/ConsoleWxWidgets/ConsoleWxWidgets.cpp @@ -25,10 +25,10 @@ class ConsoleFrame; -static AuList gPendingLines; -static Aurora::Threading::Primitives::MutexUnique_t gMutex; -static bool gWxConsoleReady; -static bool gConsoleStarted = false; +static AuList gPendingLines; +static AuThreadPrimitives::MutexUnique_t gMutex; +static bool gWxConsoleReady; +static bool gConsoleStarted = false; static ConsoleFrame *gWxFrame; @@ -79,7 +79,7 @@ public: ~ConsoleFrame() { - Aurora::Threading::Primitives::MutexUnique_t re(gMutex.get()); + AuThreadPrimitives::MutexUnique_t re(gMutex.get()); gWxConsoleReady = false; } @@ -769,23 +769,19 @@ namespace Aurora::Console::ConsoleWxWidgets { if (std::exchange(gConsoleStarted, true)) return; - gMutex = Aurora::Threading::Primitives::MutexUnique(); + gMutex = AuThreadPrimitives::MutexUnique(); Aurora::Console::Hooks::AddSubscription(AuUnsafeRaiiToShared(&gConsoleMessageSubscriber)); - Aurora::Threading::Threads::AbstractThreadVectors handler; - handler.DoRun = [](Aurora::Threading::Threads::IAuroraThread *) - { - WxWidgetsThreadMain(); - }; - - gWxWidgetsThread = Aurora::Threading::Threads::ThreadUnique(handler); + gWxWidgetsThread = AuThreading::Threads::ThreadUnique(AuThreading::Threads::ThreadInfo( + AuMakeShared(AuThreading::Threads::IThreadVectorsFunctional::OnEntry_t(std::bind(WxWidgetsThreadMain)), + AuThreading::Threads::IThreadVectorsFunctional::OnExit_t{}), + "WxWidgets" + )); if (!gWxWidgetsThread) { return; } - - gWxWidgetsThread->SetName("WxWidgets"); gWxWidgetsThread->Run(); } diff --git a/Source/Console/Flusher.cpp b/Source/Console/Flusher.cpp index fe49f5cc..f9ac3835 100644 --- a/Source/Console/Flusher.cpp +++ b/Source/Console/Flusher.cpp @@ -57,19 +57,16 @@ namespace Aurora::Console static void InitFlushThread() { // Startup a runner thread that will take care of all the stress inducing IO every so often on a remote thread - Threading::Threads::AbstractThreadVectors handler; - handler.DoRun = [](Threading::Threads::IAuroraThread *) - { - LogThreadEP(); - }; - gWriterThread = Threading::Threads::ThreadUnique(handler); + gWriterThread = Threading::Threads::ThreadUnique(AuThreading::Threads::ThreadInfo( + AuMakeShared(AuThreading::Threads::IThreadVectorsFunctional::OnEntry_t(std::bind(LogThreadEP)), + AuThreading::Threads::IThreadVectorsFunctional::OnExit_t{}), + "CasualConsoleAsyncWritter" + )); if (!gWriterThread) { return; } - - gWriterThread->SetName("CasualConsoleAsyncWritter"); gWriterThread->Run(); } diff --git a/Source/Console/Hooks/Hooks.cpp b/Source/Console/Hooks/Hooks.cpp index 15936489..ebb7a696 100644 --- a/Source/Console/Hooks/Hooks.cpp +++ b/Source/Console/Hooks/Hooks.cpp @@ -10,9 +10,9 @@ namespace Aurora::Console::Hooks { - static Threading::Primitives::MutexUnique_t gMutex; - static AuList gLineFunctionalCallbacks; - static AuList> gLineSubscribers; + static AuThreadPrimitives::MutexUnique_t gMutex; + static AuList gLineFunctionalCallbacks; + static AuList> gLineSubscribers; AUKN_SYM void AddSubscription(const AuSPtr &subscriber) { @@ -50,7 +50,7 @@ namespace Aurora::Console::Hooks } else [[unlikely]] { - Aurora::Parse::SplitNewlines(msg.line, + Parse::SplitNewlines(msg.line, [&](const AuString &line) { ConsoleMessage dup = msg; @@ -71,7 +71,7 @@ namespace Aurora::Console::Hooks void Init() { - gMutex = Threading::Primitives::MutexUnique(); + gMutex = AuThreadPrimitives::MutexUnique(); } void Deinit() diff --git a/Source/Crypto/PEM/PEM.cpp b/Source/Crypto/PEM/PEM.cpp index 9b78a05c..e7d4b38a 100644 --- a/Source/Crypto/PEM/PEM.cpp +++ b/Source/Crypto/PEM/PEM.cpp @@ -46,7 +46,7 @@ namespace Aurora::Crypto::PEM static AuString SerializePEM(const AuString &begin, const AuString &end, const AuList &buf) { - auto delm = Aurora::Build::kCurrentVendor == Aurora::Build::EVendor::eGenericMicrosoft ? "\r\n" : "\n"; + auto delm = AuBuild::kCurrentVendor == AuBuild::EVendor::eGenericMicrosoft ? "\r\n" : "\n"; AuString ret; ret += begin; ret += delm; diff --git a/Source/Debug/ExceptionWatcher.Win32.cpp b/Source/Debug/ExceptionWatcher.Win32.cpp index 4c8ee5a0..1ea71edf 100644 --- a/Source/Debug/ExceptionWatcher.Win32.cpp +++ b/Source/Debug/ExceptionWatcher.Win32.cpp @@ -237,7 +237,6 @@ namespace Aurora::Debug handle = reinterpret_cast(ExceptionInfo->ExceptionRecord->ExceptionInformation[3]); } - auto exception = reinterpret_cast(ExceptionInfo->ExceptionRecord->ExceptionInformation[1]); const auto catchableTypeArray = reinterpret_cast(reinterpret_cast(handle) + static_cast(throwInfo->pCatchableTypeArray)); AuString suffix; @@ -252,7 +251,12 @@ namespace Aurora::Debug if (strnicmp(descriptor->raw_name(), ".?AVException@", AuArraySize(".?AVException@") - 1) == 0) { - derivedFromException = true; + auto exception = reinterpret_cast(ExceptionInfo->ExceptionRecord->ExceptionInformation[1]); + auto wptr = exception->what(); + if (wptr) + { + suffix = wptr; + } } else if (strncmp(descriptor->raw_name(), ".PEAD", AuArraySize(".PEAD") - 1) == 0) { @@ -262,8 +266,7 @@ namespace Aurora::Debug auto string = *possibleStringPointer; if (IsReadable(string) && (strnlen(string, 4096) < 1024)) { - if (suffix.size()) suffix += ", "; - suffix += string; + suffix = string; } } } @@ -273,21 +276,11 @@ namespace Aurora::Debug if (IsReadable(possibleStdStringPointer)) { auto string = *possibleStdStringPointer; - if (suffix.size()) suffix += ", "; - suffix += string; + suffix = string; } } } - if (derivedFromException) - { - auto fatanthony = exception->what(); - if (fatanthony) - { - entry.wincxx.str += AuString("\r\n ") + fatanthony; - } - } - if (suffix.size()) { entry.wincxx.str += AuString("\r\n ") + suffix; diff --git a/Source/Locale/Encoding/Encoding.cpp b/Source/Locale/Encoding/Encoding.cpp index 9733d8b8..211be651 100644 --- a/Source/Locale/Encoding/Encoding.cpp +++ b/Source/Locale/Encoding/Encoding.cpp @@ -11,7 +11,7 @@ namespace Aurora::Locale::Encoding { - AUKN_SYM AuOptional> DecodeBOM(const Aurora::Memory::MemoryViewRead & binary) + AUKN_SYM AuOptional> DecodeBOM(const Memory::MemoryViewRead & binary) { #define ADD_PATTERN(str, code) {str, AuArraySize(str) - 1, ECodePage::code} AuList> bows = @@ -41,19 +41,19 @@ namespace Aurora::Locale::Encoding return {}; } - AUKN_SYM AuStreamReadWrittenPair_t EncodeUTF8(const Aurora::Memory::MemoryViewRead & utf8, const Aurora::Memory::MemoryViewWrite & binary, ECodePage page) + AUKN_SYM AuStreamReadWrittenPair_t EncodeUTF8(const Memory::MemoryViewRead & utf8, const Memory::MemoryViewWrite & binary, ECodePage page) { TextStreamEncoder re(page); return re.DecodeUTF8(utf8.ptr, utf8.length, binary.ptr, binary.length); } - AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const Aurora::Memory::MemoryViewRead & binary, const Aurora::Memory::MemoryViewWrite & utf8, ECodePage page) + AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const Memory::MemoryViewRead & binary, const Memory::MemoryViewWrite & utf8, ECodePage page) { TextStreamProcessor re(page); return re.EncodeUTF8(binary.ptr, binary.length, utf8.ptr, utf8.length); } - AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const Aurora::Memory::MemoryViewRead & binary, AuString &out, ECodePage page) + AUKN_SYM AuStreamReadWrittenPair_t DecodeUTF8(const Memory::MemoryViewRead & binary, AuString &out, ECodePage page) { auto aaa = DecodeUTF8(binary, {}, page); out.resize(aaa.second); @@ -64,9 +64,9 @@ namespace Aurora::Locale::Encoding AuStreamReadWrittenPair_t DecodeUTF8(void *binary, AuUInt32 binaryLength, AuString &out, ECodePage page) { - auto aaa = DecodeUTF8(Aurora::Memory::MemoryViewRead(binary, binaryLength), {}, page); + auto aaa = DecodeUTF8(Memory::MemoryViewRead(binary, binaryLength), {}, page); out.resize(aaa.second); - auto ret = DecodeUTF8(Aurora::Memory::MemoryViewRead(binary, binaryLength), Aurora::Memory::MemoryViewWrite(out.data(), out.size()), page); + auto ret = DecodeUTF8(Memory::MemoryViewRead(binary, binaryLength), Memory::MemoryViewWrite(out.data(), out.size()), page); out.resize(ret.second); return ret; } diff --git a/Source/Loop/LSCondition.cpp b/Source/Loop/LSCondition.cpp index 169f47eb..1dc754b9 100644 --- a/Source/Loop/LSCondition.cpp +++ b/Source/Loop/LSCondition.cpp @@ -10,7 +10,7 @@ namespace Aurora::Loop { - AUKN_SYM AuSPtr NewLSCondVar(const AuSPtr &primitive) + AUKN_SYM AuSPtr NewLSCondVar(const AuSPtr &primitive) { return {}; } diff --git a/Source/Memory/Heap.cpp b/Source/Memory/Heap.cpp index 5618ddb2..cfc71910 100644 --- a/Source/Memory/Heap.cpp +++ b/Source/Memory/Heap.cpp @@ -87,7 +87,7 @@ namespace Aurora::Memory void RequestTermination(); private: - Threading::Primitives::MutexUnique_t mutex_; + AuThreadPrimitives::MutexUnique_t mutex_; void *base_ {}; O1HeapInstance *heap_ {}; int _count {}; @@ -118,7 +118,7 @@ namespace Aurora::Memory SysAssert(length, "invalid heap allocation"); length_ = length; - mutex_ = Threading::Primitives::MutexUnique(); + mutex_ = AuThreadPrimitives::MutexUnique(); if (!mutex_) return false; base_ = Memory::FAlloc(length); diff --git a/Source/Processes/Process.Win32.cpp b/Source/Processes/Process.Win32.cpp index 299ff402..cdb743c1 100644 --- a/Source/Processes/Process.Win32.cpp +++ b/Source/Processes/Process.Win32.cpp @@ -280,8 +280,6 @@ namespace Aurora::Processes } } - Threading::Threads::AbstractThreadVectors handler; - PROCESS_INFORMATION processInfo = { 0 }; { STARTUPINFOW startupInfo = { 0 }; @@ -320,7 +318,7 @@ namespace Aurora::Processes } // TODO: delegate to a singular worker thread - handler.DoRun = [=](Threading::Threads::IAuroraThread *) + auto a = [=]() { WaitForSingleObject(processInfo.hProcess, INFINITE); @@ -329,8 +327,15 @@ namespace Aurora::Processes this->exitCode_ = exitCode; }; - this->thread_ = Threading::Threads::ThreadUnique(handler); - if (!this->thread_) return false; + this->thread_ = AuThreading::Threads::ThreadUnique(AuThreading::Threads::ThreadInfo( + AuMakeShared(AuThreading::Threads::IThreadVectorsFunctional::OnEntry_t(std::bind(a)), + AuThreading::Threads::IThreadVectorsFunctional::OnExit_t{}) + )); + + if (!this->thread_) + { + return false; + } this->thread_->Run(); return true; diff --git a/Source/RNG/WELL.hpp b/Source/RNG/WELL.hpp index 94959778..473b32d6 100644 --- a/Source/RNG/WELL.hpp +++ b/Source/RNG/WELL.hpp @@ -4,7 +4,7 @@ struct WELLRand { AuUInt32 state[16]; int index; - Aurora::Threading::Primitives::SpinLock lock; + AuThreadPrimitives::SpinLock lock; }; WELLRand WELL_SeedRand(AuUInt32 seed); diff --git a/Source/RNG/mtwister.hpp b/Source/RNG/mtwister.hpp index 418e9b18..5fc620c5 100644 --- a/Source/RNG/mtwister.hpp +++ b/Source/RNG/mtwister.hpp @@ -7,7 +7,7 @@ struct MTRand { AuUInt32 mt[STATE_VECTOR_LENGTH]; int index; - Aurora::Threading::Primitives::SpinLock lock; + AuThreadPrimitives::SpinLock lock; }; MTRand MT_SeedRand(AuUInt32 seed); diff --git a/Source/Registry/Registry.cpp b/Source/Registry/Registry.cpp index ebf57f64..4d0fee0e 100644 --- a/Source/Registry/Registry.cpp +++ b/Source/Registry/Registry.cpp @@ -43,7 +43,7 @@ namespace Aurora::Registry bool Save(); private: - Threading::Primitives::RWLockUnique_t lock_; + AuThreadPrimitives::RWLockUnique_t lock_; EWriteMode writeMode_; json currentStreamDocument_; json cacheDocument_; @@ -54,7 +54,7 @@ namespace Aurora::Registry bool FSRegistry::Init() { - lock_ = Threading::Primitives::RWLockUnique(); + lock_ = AuThreadPrimitives::RWLockUnique(); return lock_ ? true : false; } diff --git a/Source/Threading/Primitives/Event.cpp b/Source/Threading/Primitives/Event.cpp index bf063fac..e4799d9f 100644 --- a/Source/Threading/Primitives/Event.cpp +++ b/Source/Threading/Primitives/Event.cpp @@ -33,7 +33,7 @@ namespace Aurora::Threading::Primitives { AU_LOCK_GUARD(mutex_); - AuInt64 startTime = Aurora::Time::CurrentClockMS(); + AuInt64 startTime = Time::CurrentClockMS(); AuInt64 endTime = startTime + timeout; while (!AtomicIsEventSet()) @@ -42,7 +42,7 @@ namespace Aurora::Threading::Primitives if (timeout) { - timeoutMs = endTime - static_cast(Aurora::Time::CurrentClockMS()); + timeoutMs = endTime - static_cast(Time::CurrentClockMS()); if (timeoutMs < 0) { return false; diff --git a/Source/Threading/Threads/OSThread.cpp b/Source/Threading/Threads/OSThread.cpp index e04efb62..992bb638 100644 --- a/Source/Threading/Threads/OSThread.cpp +++ b/Source/Threading/Threads/OSThread.cpp @@ -27,8 +27,7 @@ namespace Aurora::Threading::Threads { - static AbstractThreadVectors gDummyVectors {}; - static ThreadInfo gDummyThreadInfo(gDummyVectors); + static ThreadInfo gDummyThreadInfo; OSThread::OSThread(const ThreadInfo &info) : info_(info) { @@ -119,11 +118,7 @@ namespace Aurora::Threading::Threads try { // this functional backends are being deprecated - if (info_.vectors.DoRun) - { - info_.vectors.DoRun(this); - } - else if (info_.callbacks) + if (info_.callbacks) { info_.callbacks->OnEntry(this); } @@ -558,11 +553,7 @@ namespace Aurora::Threading::Threads try { // dispatch kill callback - if (info_.vectors.DoExit) - { - info_.vectors.DoExit(this); - } - else if (info_.callbacks) + if (info_.callbacks) { info_.callbacks->OnExit(this); } diff --git a/Source/Threading/Threads/Threads.cpp b/Source/Threading/Threads/Threads.cpp index 26ba18a4..74adee7b 100644 --- a/Source/Threading/Threads/Threads.cpp +++ b/Source/Threading/Threads/Threads.cpp @@ -13,7 +13,7 @@ namespace Aurora::Threading::Threads { AUKN_SYM IAuroraThread *ThreadNew(const ThreadInfo &info) { - if (!info.callbacks && !(info.vectors.DoRun)) return {}; + if (!info.callbacks) return {}; return _new OSThread(info); } diff --git a/Source/Threading/WaitFor.hpp b/Source/Threading/WaitFor.hpp index eed2fa32..8aed5927 100644 --- a/Source/Threading/WaitFor.hpp +++ b/Source/Threading/WaitFor.hpp @@ -42,7 +42,7 @@ namespace Aurora::Threading void FastSnooze(long &count, AuUInt64 &startTime, AuUInt64 maxStallMS); - bool YieldPoll(bool permitMultipleContextSwitches, AuUInt64 timeoutMs, Aurora::Threading::PollCallback_cb cb); + bool YieldPoll(bool permitMultipleContextSwitches, AuUInt64 timeoutMs, Threading::PollCallback_cb cb); void YieldToOtherThread(); } \ No newline at end of file