Windows: Call SetThreadStackGuarantee for all threads, not just main thread
This commit is contained in:
@@ -685,6 +685,7 @@ static const OptionData _options[] = {
|
|||||||
int openttd_main(int argc, char *argv[])
|
int openttd_main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
SetSelfAsMainThread();
|
SetSelfAsMainThread();
|
||||||
|
PerThreadSetup();
|
||||||
std::string musicdriver;
|
std::string musicdriver;
|
||||||
std::string sounddriver;
|
std::string sounddriver;
|
||||||
std::string videodriver;
|
std::string videodriver;
|
||||||
|
@@ -219,6 +219,8 @@ void SetCurrentThreadName(const char *)
|
|||||||
int GetCurrentThreadName(char *str, const char *last) { return 0; }
|
int GetCurrentThreadName(char *str, const char *last) { return 0; }
|
||||||
|
|
||||||
void SetSelfAsMainThread() { }
|
void SetSelfAsMainThread() { }
|
||||||
|
void PerThreadSetup() { }
|
||||||
|
void PerThreadSetupInit() { }
|
||||||
|
|
||||||
bool IsMainThread() { return false; }
|
bool IsMainThread() { return false; }
|
||||||
bool IsNonMainThread() { return false; }
|
bool IsNonMainThread() { return false; }
|
||||||
|
@@ -256,6 +256,7 @@ int CDECL main(int argc, char *argv[])
|
|||||||
argc = 1;
|
argc = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
PerThreadSetupInit();
|
||||||
CrashLog::InitialiseCrashLog();
|
CrashLog::InitialiseCrashLog();
|
||||||
|
|
||||||
SetRandomSeed(time(nullptr));
|
SetRandomSeed(time(nullptr));
|
||||||
@@ -348,6 +349,10 @@ void SetSelfAsMainThread()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PerThreadSetup() { }
|
||||||
|
|
||||||
|
void PerThreadSetupInit() { }
|
||||||
|
|
||||||
bool IsMainThread()
|
bool IsMainThread()
|
||||||
{
|
{
|
||||||
#if !defined(NO_THREADS)
|
#if !defined(NO_THREADS)
|
||||||
|
@@ -725,12 +725,6 @@ static void CDECL CustomAbort(int signal)
|
|||||||
if (LoadLibraryList((Function*)&AddVectoredExceptionHandler, "kernel32.dll\0AddVectoredExceptionHandler\0\0")) {
|
if (LoadLibraryList((Function*)&AddVectoredExceptionHandler, "kernel32.dll\0AddVectoredExceptionHandler\0\0")) {
|
||||||
AddVectoredExceptionHandler(1, VectoredExceptionHandler);
|
AddVectoredExceptionHandler(1, VectoredExceptionHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL (WINAPI *SetThreadStackGuarantee)(PULONG);
|
|
||||||
if (LoadLibraryList((Function*)&SetThreadStackGuarantee, "kernel32.dll\0SetThreadStackGuarantee\0\0")) {
|
|
||||||
ULONG stacksize = 65536;
|
|
||||||
SetThreadStackGuarantee(&stacksize);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ void CrashLog::DesyncCrashLog(const std::string *log_in, std::string *log_out, const DesyncExtraInfo &info)
|
/* static */ void CrashLog::DesyncCrashLog(const std::string *log_in, std::string *log_out, const DesyncExtraInfo &info)
|
||||||
|
@@ -436,6 +436,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
|
|||||||
/* Set system timer resolution to 1ms. */
|
/* Set system timer resolution to 1ms. */
|
||||||
timeBeginPeriod(1);
|
timeBeginPeriod(1);
|
||||||
|
|
||||||
|
PerThreadSetupInit();
|
||||||
CrashLog::InitialiseCrashLog();
|
CrashLog::InitialiseCrashLog();
|
||||||
|
|
||||||
/* Convert the command line to UTF-8. We need a dedicated buffer
|
/* Convert the command line to UTF-8. We need a dedicated buffer
|
||||||
@@ -739,6 +740,21 @@ void SetSelfAsMainThread()
|
|||||||
main_thread_id = GetCurrentThreadId();
|
main_thread_id = GetCurrentThreadId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static BOOL (WINAPI *_SetThreadStackGuarantee)(PULONG) = nullptr;
|
||||||
|
|
||||||
|
void PerThreadSetup()
|
||||||
|
{
|
||||||
|
if (_SetThreadStackGuarantee != nullptr) {
|
||||||
|
ULONG stacksize = 65536;
|
||||||
|
_SetThreadStackGuarantee(&stacksize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PerThreadSetupInit()
|
||||||
|
{
|
||||||
|
LoadLibraryList((Function*)&_SetThreadStackGuarantee, "kernel32.dll\0SetThreadStackGuarantee\0\0");
|
||||||
|
}
|
||||||
|
|
||||||
bool IsMainThread()
|
bool IsMainThread()
|
||||||
{
|
{
|
||||||
return main_thread_id == GetCurrentThreadId();
|
return main_thread_id == GetCurrentThreadId();
|
||||||
|
11
src/thread.h
11
src/thread.h
@@ -49,6 +49,16 @@ int GetCurrentThreadName(char *str, const char *last);
|
|||||||
*/
|
*/
|
||||||
void SetSelfAsMainThread();
|
void SetSelfAsMainThread();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform per-thread setup
|
||||||
|
*/
|
||||||
|
void PerThreadSetup();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup thread functionality required for later calls to PerThreadSetup
|
||||||
|
*/
|
||||||
|
void PerThreadSetupInit();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if the current thread definitely the "main" thread. If in doubt returns false.
|
* @return true if the current thread definitely the "main" thread. If in doubt returns false.
|
||||||
*/
|
*/
|
||||||
@@ -77,6 +87,7 @@ inline bool StartNewThread(std::thread *thr, const char *name, TFn&& _Fx, TArgs&
|
|||||||
try {
|
try {
|
||||||
std::thread t([] (const char *name, TFn&& F, TArgs&&... A) {
|
std::thread t([] (const char *name, TFn&& F, TArgs&&... A) {
|
||||||
SetCurrentThreadName(name);
|
SetCurrentThreadName(name);
|
||||||
|
PerThreadSetup();
|
||||||
try {
|
try {
|
||||||
/* Call user function with the given arguments. */
|
/* Call user function with the given arguments. */
|
||||||
F(A...);
|
F(A...);
|
||||||
|
Reference in New Issue
Block a user