set thread name for Windows (#57)
This commit is contained in:
		
				
					committed by
					
						
						Benjamin Sergeant
					
				
			
			
				
	
			
			
			
						parent
						
							1e1d5c3f7d
						
					
				
				
					commit
					88abb79a96
				
			@@ -5,12 +5,41 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
#include "../IXSetThreadName.h"
 | 
					#include "../IXSetThreadName.h"
 | 
				
			||||||
#include <iostream>
 | 
					#include <iostream>
 | 
				
			||||||
 | 
					#include <Windows.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace ix
 | 
					namespace ix
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    const DWORD MS_VC_EXCEPTION = 0x406D1388;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#pragma pack(push,8)
 | 
				
			||||||
 | 
					    typedef struct tagTHREADNAME_INFO
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        DWORD dwType;     // Must be 0x1000.
 | 
				
			||||||
 | 
					        LPCSTR szName;    // Pointer to name (in user addr space).
 | 
				
			||||||
 | 
					        DWORD dwThreadID; // Thread ID (-1=caller thread).
 | 
				
			||||||
 | 
					        DWORD dwFlags;    // Reserved for future use, must be zero.
 | 
				
			||||||
 | 
					    } THREADNAME_INFO;
 | 
				
			||||||
 | 
					#pragma pack(pop)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    void SetThreadName(DWORD dwThreadID, const char* threadName)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        THREADNAME_INFO info;
 | 
				
			||||||
 | 
					        info.dwType = 0x1000;
 | 
				
			||||||
 | 
					        info.szName = threadName;
 | 
				
			||||||
 | 
					        info.dwThreadID = dwThreadID;
 | 
				
			||||||
 | 
					        info.dwFlags = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        __try
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)& info);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        __except (EXCEPTION_EXECUTE_HANDLER)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void setThreadName(const std::string& name)
 | 
					    void setThreadName(const std::string& name)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // FIXME
 | 
					        SetThreadName(-1, name.c_str());
 | 
				
			||||||
        std::cerr << "setThreadName not implemented on Windows yet" << std::endl;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user