[*] Continue to perfer beginthreadex, use CreateThread when the OS loader is locked on Win32

This commit is contained in:
Reece Wilson 2022-01-18 16:02:24 +00:00
parent 82370fea1d
commit 29bd8dca0c
4 changed files with 41 additions and 7 deletions

View File

@ -13,10 +13,9 @@
"linkSources": "Source/Alloc.cpp",
"actions": [
{
"if_": "win32",
"filter": { "platforms": "win32"} ,
"filter": {"platforms": "win32"},
"then": {
"links": ["Bcrypt.lib", "UxTheme.lib"]
"links": ["Bcrypt.lib", "UxTheme.lib", "Aux_ulib.lib"]
}
}
]

View File

@ -228,9 +228,9 @@ namespace Aurora::Debug
if ((ExceptionInfo->ExceptionRecord->ExceptionCode == EH_EXCEPTION_NUMBER) &&
(ExceptionInfo->ExceptionRecord->NumberParameters >= 4) &&
((cxxThrow) ||
(cxxThrowPure))
)
((cxxThrow) ||
(cxxThrowPure))
)
{
HMODULE handle {};
auto *throwInfo = reinterpret_cast<ThrowInfo *>(ExceptionInfo->ExceptionRecord->ExceptionInformation[2]);

View File

@ -19,6 +19,7 @@
#include "Debug/Debug.hpp"
#include "Async/Async.hpp"
#include "HWInfo/HWInfo.hpp"
#include "Threading/Threads/OSThread.hpp"
#if defined(AURORA_PLATFORM_WIN32)
#include "Extensions/Win32/DarkTheme.hpp"
#endif
@ -30,6 +31,7 @@ static void Init()
#endif
Crypto::InitCrypto();
Aurora::Threading::Threads::InitThreading();
Aurora::Console::Init();
Aurora::IO::FS::InitResources();
Aurora::Console::Init2();

View File

@ -22,6 +22,7 @@
#if defined(AURORA_PLATFORM_WIN32)
#include <process.h>
#include <Aux_ulib.h>
#endif
@ -315,13 +316,40 @@ namespace Aurora::Threading::Threads
// I think I switched it from CreateThread to _beginthreadex at somepoint and i don't remember why
#if defined(AURORA_IS_MODERNNT_DERIVED)
unsigned(WINAPI *OSEP_f)(void *) = [](void *that) -> unsigned
unsigned(WINAPI * OSEP_f)(void *) = [](void *that) -> unsigned
{
auto thiz = reinterpret_cast<OSThread *>(that);
thiz->_ThreadEP();
return 0;
};
DWORD(WINAPI * OSCreateThreadEP_f)(void *) = [](void *that) -> DWORD
{
auto thiz = reinterpret_cast<OSThread *>(that);
thiz->_ThreadEP();
return 0;
};
#if defined(AURORA_PLATFORM_WIN32)
BOOL a {};
if (AuxUlibIsDLLSynchronizationHeld(&a))
{
if (a)
{
handle_ = CreateThread(NULL, info_.stackSize, OSCreateThreadEP_f, reinterpret_cast<LPVOID>(this), NULL, NULL);
if (!handle_)
{
handle_ = INVALID_HANDLE_VALUE;
SysPushErrorGen("Couldn't create locked thread: {}", GetName());
return false;
}
return true;
}
}
#endif
auto ok = _beginthreadex(nullptr, info_.stackSize, OSEP_f, this, 0, 0);
if (ok == -1L)
{
@ -712,4 +740,9 @@ namespace Aurora::Threading::Threads
{
return this->terminateSignalLs_;
}
void InitThreading()
{
AuxUlibInitialize();
}
}