[*] 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", "linkSources": "Source/Alloc.cpp",
"actions": [ "actions": [
{ {
"if_": "win32",
"filter": {"platforms": "win32"}, "filter": {"platforms": "win32"},
"then": { "then": {
"links": ["Bcrypt.lib", "UxTheme.lib"] "links": ["Bcrypt.lib", "UxTheme.lib", "Aux_ulib.lib"]
} }
} }
] ]

View File

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

View File

@ -22,6 +22,7 @@
#if defined(AURORA_PLATFORM_WIN32) #if defined(AURORA_PLATFORM_WIN32)
#include <process.h> #include <process.h>
#include <Aux_ulib.h>
#endif #endif
@ -322,6 +323,33 @@ namespace Aurora::Threading::Threads
return 0; 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); auto ok = _beginthreadex(nullptr, info_.stackSize, OSEP_f, this, 0, 0);
if (ok == -1L) if (ok == -1L)
{ {
@ -712,4 +740,9 @@ namespace Aurora::Threading::Threads
{ {
return this->terminateSignalLs_; return this->terminateSignalLs_;
} }
void InitThreading()
{
AuxUlibInitialize();
}
} }