windows: fix race condition with exception-based thread naming.
This commit is contained in:
committed by
Sam Lantinga
parent
faa404a652
commit
186c6e5c9d
13
src/thread/windows/SDL_systhread.c
Normal file → Executable file
13
src/thread/windows/SDL_systhread.c
Normal file → Executable file
@@ -32,6 +32,8 @@
|
|||||||
#define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
|
#define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define SDL_DEBUGGER_NAME_EXCEPTION_CODE 0x406D1388
|
||||||
|
|
||||||
typedef void (__cdecl * SDL_EndThreadExCallback) (unsigned retval);
|
typedef void (__cdecl * SDL_EndThreadExCallback) (unsigned retval);
|
||||||
typedef uintptr_t (__cdecl * SDL_BeginThreadExCallback)
|
typedef uintptr_t (__cdecl * SDL_BeginThreadExCallback)
|
||||||
(void *security, unsigned stacksize, unsigned (__stdcall *startaddr)(void *),
|
(void *security, unsigned stacksize, unsigned (__stdcall *startaddr)(void *),
|
||||||
@@ -97,10 +99,13 @@ typedef struct tagTHREADNAME_INFO
|
|||||||
} THREADNAME_INFO;
|
} THREADNAME_INFO;
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
static LONG NTAPI EmptyVectoredExceptionHandler(EXCEPTION_POINTERS *ExceptionInfo)
|
static LONG NTAPI EmptyVectoredExceptionHandler(EXCEPTION_POINTERS *info)
|
||||||
{
|
{
|
||||||
(void)ExceptionInfo;
|
if (info != NULL && info->ExceptionRecord != NULL && info->ExceptionRecord->ExceptionCode == SDL_DEBUGGER_NAME_EXCEPTION_CODE) {
|
||||||
return EXCEPTION_CONTINUE_EXECUTION;
|
return EXCEPTION_CONTINUE_EXECUTION;
|
||||||
|
} else {
|
||||||
|
return EXCEPTION_CONTINUE_SEARCH;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef HRESULT(WINAPI *pfnSetThreadDescription)(HANDLE, PCWSTR);
|
typedef HRESULT(WINAPI *pfnSetThreadDescription)(HANDLE, PCWSTR);
|
||||||
@@ -148,7 +153,7 @@ void SDL_SYS_SetupThread(const char *name)
|
|||||||
inf.dwFlags = 0;
|
inf.dwFlags = 0;
|
||||||
|
|
||||||
// The debugger catches this, renames the thread, continues on.
|
// The debugger catches this, renames the thread, continues on.
|
||||||
RaiseException(0x406D1388, 0, sizeof(inf) / sizeof(ULONG), (const ULONG_PTR *)&inf);
|
RaiseException(SDL_DEBUGGER_NAME_EXCEPTION_CODE, 0, sizeof(inf) / sizeof(ULONG), (const ULONG_PTR *)&inf);
|
||||||
RemoveVectoredExceptionHandler(exceptionHandlerHandle);
|
RemoveVectoredExceptionHandler(exceptionHandlerHandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user