[*] Simplify when to call _beginthreadex (we probably shouldn't)

This commit is contained in:
Reece Wilson 2023-08-23 19:11:21 +01:00
parent 61eaa701b7
commit 293a8ddd66

View File

@ -18,18 +18,6 @@ namespace Aurora::Threading::Threads
{
AuPair<bool, AuUInt> /*success, oshandle*/ SpawnThread(const AuFunction<void()> &entrypoint, const AuString &debugString, AuUInt32 staskSize)
{
// https://github.com/webrtc-uwp/chromium-base/blob/master/threading/platform_thread_win.cc#L129-L136
// Do we care yet?
// When targeting older CRTs, _beginthreadex
// When targeting at least UWP, CreateThread but _beginthreadex is fine
// https://web.archive.org/web/20110928122401/http://www.microsoft.com/msj/1099/win32/win321099.aspx
// Even in 1999 it sounded like _tiddata was setup for all modules that may come across our thread
// It wasn't until 2005, 6 years later, it became less of a requirement.
// Does the modern CRT need it for anything estoeric or evil?
// I think so long as we're targeting modern windows its fine to call _beginthreadex for all CRT users
// Userland icds, plugins, software not in our build chain, it makes sense for them to have a _fully_ initialized crt
// I think I switched it from CreateThread to _beginthreadex at somepoint and i don't remember why
if (!entrypoint)
{
return {false, 0};
@ -62,6 +50,21 @@ namespace Aurora::Threading::Threads
return 0;
};
#if defined(_DLL) /* dynamic system vcruntime of the 2016+ crt */ || \
!defined(AURORA_PLATFORM_WIN32)
// msvcrt.dll era code should also prefer _beginthreadex
auto handle = CreateThread(NULL, staskSize, OSCreateThreadEP_f, reinterpret_cast<LPVOID>(callbackClone), NULL, NULL);
if (!handle)
{
handle = INVALID_HANDLE_VALUE;
SysPushErrorGen("Couldn't create locked thread: {}", debugString);
return { false, 0 };
}
return { true, reinterpret_cast<AuUInt>(handle) };
#else
#if defined(AURORA_PLATFORM_WIN32)
BOOL a {};
if (AuxUlibIsDLLSynchronizationHeld(&a))
@ -90,5 +93,6 @@ namespace Aurora::Threading::Threads
}
return {true, ok};
#endif
}
}