[*] Refactor and clean up exception and threading API

[-] Deprecated abstract vectors struct
This commit is contained in:
Reece Wilson 2021-10-24 11:19:47 +01:00
parent e01fa33445
commit b8fde0bdf0
34 changed files with 115 additions and 142 deletions

View File

@ -11,6 +11,6 @@
namespace Aurora::Compression
{
AUKN_SHARED_API(Decompressor, ICompressionStream, const AuSPtr<Aurora::IO::IStreamReader> &reader, const DecompressInfo &info);
AUKN_SHARED_API(Compressor, ICompressionStream, const AuSPtr<Aurora::IO::IStreamReader> &reader, const CompressionInfo &info);
AUKN_SHARED_API(Decompressor, ICompressionStream, const AuSPtr<IO::IStreamReader> &reader, const DecompressInfo &info);
AUKN_SHARED_API(Compressor, ICompressionStream, const AuSPtr<IO::IStreamReader> &reader, const CompressionInfo &info);
}

View File

@ -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<AuPair<ECodePage, AuUInt8>> DecodeBOM(const Aurora::Memory::MemoryViewRead & binary);
AUKN_SYM std::optional<AuPair<ECodePage, AuUInt8>> 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);
}

View File

@ -79,7 +79,7 @@ namespace Aurora::Loop
virtual void UpdateTime(AuUInt64 absTimeMs) = 0;
};
AUKN_SYM AuSPtr<IConditionVar> NewLSCondVar(const AuSPtr<Aurora::Threading::IWaitable> &primitive);
AUKN_SYM AuSPtr<IConditionVar> NewLSCondVar(const AuSPtr<Threading::IWaitable> &primitive);
AUKN_SYM AuSPtr<IConditionVar> NewLSCondVar(const AuSPtr<ILSMutex> &source);
AUKN_SYM AuSPtr<ITimer> NewLSTimer(AuUInt64 absTimeMs);

View File

@ -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()
{

View File

@ -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 <br>
DoRun/DoExit are called within the threads context
*/
/// @deprecated
struct AbstractThreadVectors
{
AuConsumer<IAuroraThread *> DoRun;
AuConsumer<IAuroraThread *> DoExit;
};
AUKN_INTERFACE(IThreadVectors,
AUI_METHOD(void, OnEntry, (IAuroraThread *, thread)),

View File

@ -11,14 +11,11 @@ namespace Aurora::Threading::Threads
{
struct ThreadInfo
{
/// @deprecated
AbstractThreadVectors vectors;
AuSPtr<IThreadVectors> callbacks;
/// @deprecated
ThreadInfo(const AbstractThreadVectors &vectors) : vectors(vectors)
ThreadInfo()
{}
ThreadInfo(const AuSPtr<IThreadVectors> &callbacks) : callbacks(callbacks)
{}

View File

@ -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"

View File

@ -60,7 +60,7 @@ namespace Aurora::Async
//std::stack<jmp_buf> jmpStack;
AuWPtr<GroupState> parent;
Threading::Primitives::SemaphoreUnique_t syncSema;
AuThreadPrimitives::SemaphoreUnique_t syncSema;
AuList<AuSPtr<Threading::Threads::IThreadFeature>> 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<Loop::ILSEvent> eventLs;
AuList<WorkEntry_t> 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<bool>(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>();
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>(AuThreading::Threads::IThreadVectorsFunctional::OnEntry_t(std::bind(&AsyncApp::Entrypoint, this, threadState->id)),
AuThreading::Threads::IThreadVectorsFunctional::OnExit_t{})
));
threadState->threadObject->Run();
}
else

View File

@ -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<GroupState> GetGroup(ThreadGroup_t type);

View File

@ -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<SchedEntry> gEntries;
static void GetDispatchableTasks(AuList<SchedEntry> &pending)
@ -103,7 +103,7 @@ namespace Aurora::Async
void InitSched()
{
gSchedLock = Threading::Primitives::MutexUnique();
gSchedLock = AuThreadPrimitives::MutexUnique();
}
void DeinitSched()

View File

@ -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()

View File

@ -44,8 +44,8 @@ namespace Aurora::Async
WorkerId_t worker_;
AuList<AuSPtr<IWorkItem>> waitOn_;
AuList<AuSPtr<IWorkItem>> waiters_;
Threading::Primitives::SpinLock lock;
Threading::Primitives::EventUnique_t finishedEvent_;
AuThreadPrimitives::SpinLock lock;
AuThreadPrimitives::EventUnique_t finishedEvent_;
bool finished {};
bool failed {};

View File

@ -16,7 +16,7 @@ namespace Aurora::Compression
virtual ~BaseCompressionStream() {}
virtual bool Init(const AuSPtr<Aurora::IO::IStreamReader> &reader) = 0;
virtual bool Init(const AuSPtr<IO::IStreamReader> &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;
};
}

View File

@ -115,7 +115,7 @@ namespace Aurora::Compression
}
}
bool Init(const AuSPtr<Aurora::IO::IStreamReader> &reader)
bool Init(const AuSPtr<IO::IStreamReader> &reader)
{
this->reader_ = reader;
this->dctx_ = ZSTD_createDCtx();
@ -172,7 +172,7 @@ namespace Aurora::Compression
private:
AuSPtr<Aurora::IO::IStreamReader> reader_;
AuSPtr<IO::IStreamReader> 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<Aurora::IO::IStreamReader> &reader)
bool Init(const AuSPtr<IO::IStreamReader> &reader)
{
this->reader_ = reader;
@ -263,7 +263,7 @@ namespace Aurora::Compression
private:
AuSPtr<Aurora::IO::IStreamReader> reader_;
AuSPtr<IO::IStreamReader> reader_;
z_stream ctx_ {};
bool init_ {};
unsigned char din_[4096];
@ -286,7 +286,7 @@ namespace Aurora::Compression
}
}
bool Init(const AuSPtr<Aurora::IO::IStreamReader> &reader)
bool Init(const AuSPtr<IO::IStreamReader> &reader)
{
this->reader_ = reader;
@ -347,7 +347,7 @@ namespace Aurora::Compression
private:
AuSPtr<Aurora::IO::IStreamReader> reader_;
AuSPtr<IO::IStreamReader> reader_;
bz_stream ctx_ {};
bool init_ {};
char dout_[4096];
@ -372,7 +372,7 @@ namespace Aurora::Compression
}
}
bool Init(const AuSPtr<Aurora::IO::IStreamReader> &reader)
bool Init(const AuSPtr<IO::IStreamReader> &reader)
{
this->reader_ = reader;
@ -459,11 +459,11 @@ namespace Aurora::Compression
private:
AuSPtr<Aurora::IO::IStreamReader> reader_;
AuSPtr<IO::IStreamReader> reader_;
LZ4F_dctx* lz4Stream_ {};
};
AUKN_SYM ICompressionStream *DecompressorNew(const AuSPtr<Aurora::IO::IStreamReader> &reader, const DecompressInfo &ref)
AUKN_SYM ICompressionStream *DecompressorNew(const AuSPtr<IO::IStreamReader> &reader, const DecompressInfo &ref)
{
DecompressInfo info = ref;
BaseStream * ret{};

View File

@ -16,7 +16,7 @@ namespace Aurora::Compression
virtual ~BaseStream() {}
virtual bool Init(const AuSPtr<Aurora::IO::IStreamReader> &reader) = 0;
virtual bool Init(const AuSPtr<IO::IStreamReader> &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;
};
}

View File

@ -16,8 +16,8 @@ namespace Aurora::Console::Commands
static AuHashMap<AuString, Command> gCommands;
static AuList<Hooks::LineHook_cb> gLineCallbacks;
static AuList<CommandDispatch> 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<Async::WorkerId_t> gCommandDispatcher;
struct Command

View File

@ -11,7 +11,7 @@
namespace Aurora::Console::ConsoleFIO
{
static AuList<AuUInt8> 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;

View File

@ -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)

View File

@ -25,10 +25,10 @@
class ConsoleFrame;
static AuList<Aurora::Console::ConsoleMessage> gPendingLines;
static Aurora::Threading::Primitives::MutexUnique_t gMutex;
static bool gWxConsoleReady;
static bool gConsoleStarted = false;
static AuList<Aurora::Console::ConsoleMessage> 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>(AuThreading::Threads::IThreadVectorsFunctional::OnEntry_t(std::bind(WxWidgetsThreadMain)),
AuThreading::Threads::IThreadVectorsFunctional::OnExit_t{}),
"WxWidgets"
));
if (!gWxWidgetsThread)
{
return;
}
gWxWidgetsThread->SetName("WxWidgets");
gWxWidgetsThread->Run();
}

View File

@ -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>(AuThreading::Threads::IThreadVectorsFunctional::OnEntry_t(std::bind(LogThreadEP)),
AuThreading::Threads::IThreadVectorsFunctional::OnExit_t{}),
"CasualConsoleAsyncWritter"
));
if (!gWriterThread)
{
return;
}
gWriterThread->SetName("CasualConsoleAsyncWritter");
gWriterThread->Run();
}

View File

@ -10,9 +10,9 @@
namespace Aurora::Console::Hooks
{
static Threading::Primitives::MutexUnique_t gMutex;
static AuList<Hooks::LineHook_cb> gLineFunctionalCallbacks;
static AuList<AuSPtr<IConsoleSubscriber>> gLineSubscribers;
static AuThreadPrimitives::MutexUnique_t gMutex;
static AuList<LineHook_cb> gLineFunctionalCallbacks;
static AuList<AuSPtr<IConsoleSubscriber>> gLineSubscribers;
AUKN_SYM void AddSubscription(const AuSPtr<IConsoleSubscriber> &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()

View File

@ -46,7 +46,7 @@ namespace Aurora::Crypto::PEM
static AuString SerializePEM(const AuString &begin, const AuString &end, const AuList<AuUInt8> &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;

View File

@ -237,7 +237,6 @@ namespace Aurora::Debug
handle = reinterpret_cast<HMODULE>(ExceptionInfo->ExceptionRecord->ExceptionInformation[3]);
}
auto exception = reinterpret_cast<std::exception *>(ExceptionInfo->ExceptionRecord->ExceptionInformation[1]);
const auto catchableTypeArray = reinterpret_cast<const CatchableTypeArray*>(reinterpret_cast<AuUInt>(handle) + static_cast<AuUInt>(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<std::exception *>(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;

View File

@ -11,7 +11,7 @@
namespace Aurora::Locale::Encoding
{
AUKN_SYM AuOptional<AuPair<ECodePage, AuUInt8>> DecodeBOM(const Aurora::Memory::MemoryViewRead & binary)
AUKN_SYM AuOptional<AuPair<ECodePage, AuUInt8>> DecodeBOM(const Memory::MemoryViewRead & binary)
{
#define ADD_PATTERN(str, code) {str, AuArraySize(str) - 1, ECodePage::code}
AuList<std::tuple<const char *, int, ECodePage>> 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;
}

View File

@ -10,7 +10,7 @@
namespace Aurora::Loop
{
AUKN_SYM AuSPtr<IConditionVar> NewLSCondVar(const AuSPtr<Aurora::Threading::IWaitable> &primitive)
AUKN_SYM AuSPtr<IConditionVar> NewLSCondVar(const AuSPtr<AuThreading::IWaitable> &primitive)
{
return {};
}

View File

@ -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<void *>(length);

View File

@ -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>(AuThreading::Threads::IThreadVectorsFunctional::OnEntry_t(std::bind(a)),
AuThreading::Threads::IThreadVectorsFunctional::OnExit_t{})
));
if (!this->thread_)
{
return false;
}
this->thread_->Run();
return true;

View File

@ -4,7 +4,7 @@ struct WELLRand
{
AuUInt32 state[16];
int index;
Aurora::Threading::Primitives::SpinLock lock;
AuThreadPrimitives::SpinLock lock;
};
WELLRand WELL_SeedRand(AuUInt32 seed);

View File

@ -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);

View File

@ -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;
}

View File

@ -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<AuInt64>(Aurora::Time::CurrentClockMS());
timeoutMs = endTime - static_cast<AuInt64>(Time::CurrentClockMS());
if (timeoutMs < 0)
{
return false;

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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();
}