mirror of https://github.com/encounter/SDL.git
Enabled thread naming on Windows.
This is now done without compiler or C runtime support for __try/__except. (Granted, it uses Visual Studio-style inline asm, but still...)
This commit is contained in:
parent
ace1e98a18
commit
2bafbedac7
|
@ -146,6 +146,7 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(disable : 4733)
|
||||||
#pragma pack(push,8)
|
#pragma pack(push,8)
|
||||||
typedef struct tagTHREADNAME_INFO
|
typedef struct tagTHREADNAME_INFO
|
||||||
{
|
{
|
||||||
|
@ -155,31 +156,46 @@ typedef struct tagTHREADNAME_INFO
|
||||||
DWORD dwFlags; /* reserved for future use, must be zero */
|
DWORD dwFlags; /* reserved for future use, must be zero */
|
||||||
} THREADNAME_INFO;
|
} THREADNAME_INFO;
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
|
static EXCEPTION_DISPOSITION
|
||||||
|
ignore_exception(void *a, void *b, void *c, void *d)
|
||||||
|
{
|
||||||
|
return ExceptionContinueExecution;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
SDL_SYS_SetupThread(const char *name)
|
SDL_SYS_SetupThread(const char *name)
|
||||||
{
|
{
|
||||||
if (name != NULL) {
|
if (name != NULL) {
|
||||||
#if 0 /* !!! FIXME: __except needs C runtime, which we don't link against. */
|
#ifdef _MSC_VER
|
||||||
#ifdef _MSC_VER /* !!! FIXME: can we do SEH on other compilers yet? */
|
/* This magic tells the debugger to name a thread if it's listening.
|
||||||
/* This magic tells the debugger to name a thread if it's listening. */
|
The inline asm sets up SEH (__try/__except) without C runtime
|
||||||
|
support. See Microsoft Systems Journal, January 1997:
|
||||||
|
http://www.microsoft.com/msj/0197/exception/exception.aspx */
|
||||||
|
INT_PTR handler = (INT_PTR) ignore_exception;
|
||||||
THREADNAME_INFO inf;
|
THREADNAME_INFO inf;
|
||||||
|
|
||||||
inf.dwType = 0x1000;
|
inf.dwType = 0x1000;
|
||||||
inf.szName = name;
|
inf.szName = name;
|
||||||
inf.dwThreadID = (DWORD) -1;
|
inf.dwThreadID = (DWORD) -1;
|
||||||
inf.dwFlags = 0;
|
inf.dwFlags = 0;
|
||||||
|
|
||||||
__try
|
__asm { /* set up SEH */
|
||||||
{
|
push handler
|
||||||
RaiseException(0x406D1388, 0, sizeof(inf)/sizeof(DWORD), (DWORD*)&inf);
|
push fs:[0]
|
||||||
|
mov fs:[0],esp
|
||||||
}
|
}
|
||||||
__except(EXCEPTION_CONTINUE_EXECUTION)
|
|
||||||
{
|
/* The program itself should ignore this bogus exception. */
|
||||||
/* The program itself should ignore this bogus exception. */
|
RaiseException(0x406D1388, 0, sizeof(inf)/sizeof(DWORD), (DWORD*)&inf);
|
||||||
|
|
||||||
|
__asm { /* tear down SEH. */
|
||||||
|
mov eax,[esp]
|
||||||
|
mov fs:[0], eax
|
||||||
|
add esp, 8
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue