From 48a8e4ae5ab1bea3fb781b81c016d31b6a5a0330 Mon Sep 17 00:00:00 2001 From: Reece Wilson Date: Fri, 14 Oct 2022 07:14:56 +0100 Subject: [PATCH] [+] Catch around all async DispatchFrames. Will add optional forced panic later. [*] Fix thread handle bug on non-au threads --- Source/Async/WorkItem.cpp | 13 +++++++++++-- Source/Threading/Threads/OSThread.cpp | 12 +++++++++++- Source/Threading/Threads/ThreadHandles.cpp | 4 ++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Source/Async/WorkItem.cpp b/Source/Async/WorkItem.cpp index c75853f3..f04bc06e 100644 --- a/Source/Async/WorkItem.cpp +++ b/Source/Async/WorkItem.cpp @@ -236,13 +236,22 @@ namespace Aurora::Async void WorkItem::RunAsyncLocked() { - IWorkItemHandler::ProcessInfo info(true); info.pool = this->owner_->ToThreadPool(); if (this->task_) { - this->task_->DispatchFrame(info); + try + { + this->task_->DispatchFrame(info); + } + catch (...) + { + // TODO: runtime config for root level exception caught behaviour + SysPushErrorCatch(); + Fail(); + return; + } } switch (info.type) diff --git a/Source/Threading/Threads/OSThread.cpp b/Source/Threading/Threads/OSThread.cpp index 5209cd18..969edbdb 100644 --- a/Source/Threading/Threads/OSThread.cpp +++ b/Source/Threading/Threads/OSThread.cpp @@ -89,7 +89,6 @@ namespace Aurora::Threading::Threads this->bNotOwned = true; } - bool DeadTest(); OSThread::~OSThread() @@ -99,6 +98,10 @@ namespace Aurora::Threading::Threads if (this->bNotOwned) { + #if defined(AURORA_IS_MODERNNT_DERIVED) + auto hHandle = (HANDLE)this->handle_; + AuWin32CloseHandle(hHandle); + #endif return; } @@ -352,6 +355,7 @@ namespace Aurora::Threading::Threads void OSThread::SetName(const AuString &name) { this->name_ = name; + this->UpdateName(); } EThreadThrottle OSThread::GetThrottle() @@ -430,8 +434,14 @@ namespace Aurora::Threading::Threads { this->task_ = task; + this->handle_ = 0; + auto ret = SpawnThread([this]() { + while (!this->handle_) + { + }; + this->_ThreadEP(); }, GetName(), this->info_.stackSize); diff --git a/Source/Threading/Threads/ThreadHandles.cpp b/Source/Threading/Threads/ThreadHandles.cpp index 1112e4e0..60ca2b95 100644 --- a/Source/Threading/Threads/ThreadHandles.cpp +++ b/Source/Threading/Threads/ThreadHandles.cpp @@ -42,9 +42,9 @@ namespace Aurora::Threading::Threads HANDLE ret; auto process = GetCurrentProcess(); - auto thread = GetCurrentProcess(); + auto thread = GetCurrentThread(); - if (!DuplicateHandle(process, thread, process, &ret, DUPLICATE_SAME_ACCESS, FALSE, DUPLICATE_SAME_ACCESS)) + if (!DuplicateHandle(process, thread, process, &ret, THREAD_ALL_ACCESS, FALSE, FALSE)) { return reinterpret_cast(INVALID_HANDLE_VALUE); }