From 00b2d18a8e5a9d52d8200d2afbce323f066dfebc Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 17 Sep 2004 02:36:04 +0000 Subject: [PATCH] show thread names in the VC debugger --- stepmania/src/arch/Threads/Threads_Win32.cpp | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/stepmania/src/arch/Threads/Threads_Win32.cpp b/stepmania/src/arch/Threads/Threads_Win32.cpp index 42b79eded9..1784c12ce3 100644 --- a/stepmania/src/arch/Threads/Threads_Win32.cpp +++ b/stepmania/src/arch/Threads/Threads_Win32.cpp @@ -57,10 +57,37 @@ int ThreadImpl_Win32::Wait() return ret; } +/* SetThreadName magic comes from VirtualDub. */ +#define MS_VC_EXCEPTION 0x406d1388 + +typedef struct tagTHREADNAME_INFO +{ + DWORD dwType; // must be 0x1000 + LPCSTR szName; // pointer to name (in same addr space) + DWORD dwThreadID; // thread ID (-1 caller thread) + DWORD dwFlags; // reserved for future use, most be zero +} THREADNAME_INFO; + +static void SetThreadName( DWORD dwThreadID, LPCTSTR szThreadName ) +{ + THREADNAME_INFO info; + info.dwType = 0x1000; + info.szName = szThreadName; + info.dwThreadID = dwThreadID; + info.dwFlags = 0; + + __try { + RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(DWORD), (ULONG_PTR *)&info); + } __except (EXCEPTION_CONTINUE_EXECUTION) { + } +} + static DWORD WINAPI StartThread( LPVOID pData ) { ThreadImpl_Win32 *pThis = (ThreadImpl_Win32 *) pData; + SetThreadName( GetCurrentThreadId(), RageThread::GetCurThreadName() ); + DWORD ret = (DWORD) pThis->m_pFunc( pThis->m_pData ); for( int i = 0; i < MAX_THREADS; ++i ) @@ -99,6 +126,8 @@ ThreadImpl *MakeThisThread() { ThreadImpl_Win32 *thread = new ThreadImpl_Win32; + SetThreadName( GetCurrentThreadId(), RageThread::GetCurThreadName() ); + const HANDLE CurProc = GetCurrentProcess(); int ret = DuplicateHandle( CurProc, GetCurrentThread(), CurProc, &thread->ThreadHandle, 0, false, DUPLICATE_SAME_ACCESS );