1/*
2 *  Use of this source code is governed by the MICROSOFT LIMITED PUBLIC LICENSE
3 *  copyright license which can be found in the LICENSE file in the
4 *  third_party_mods/mslpl directory of the source tree or at
5 *  http://msdn.microsoft.com/en-us/cc300389.aspx#P.
6 */
7/*
8 *  The original code can be found here:
9 *  http://msdn.microsoft.com/en-us/library/xcb2z8hs(VS.71).aspx
10 */
11
12#ifndef WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WINDOWS_SET_NAME_H_
13#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WINDOWS_SET_NAME_H_
14
15namespace webrtc {
16
17struct THREADNAME_INFO
18{
19   DWORD dwType;     // must be 0x1000
20   LPCSTR szName;    // pointer to name (in user addr space)
21   DWORD dwThreadID; // thread ID (-1 = caller thread)
22   DWORD dwFlags;    // reserved for future use, must be zero
23};
24
25void SetThreadName(DWORD dwThreadID, LPCSTR szThreadName)
26{
27    THREADNAME_INFO info;
28    info.dwType = 0x1000;
29    info.szName = szThreadName;
30    info.dwThreadID = dwThreadID;
31    info.dwFlags = 0;
32
33    __try
34    {
35        RaiseException(0x406D1388, 0, sizeof(info) / sizeof(DWORD),
36                       (ULONG_PTR*)&info);
37    }
38    __except (EXCEPTION_CONTINUE_EXECUTION)
39    {
40    }
41}
42} // namespace webrtc
43#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_THREAD_WINDOWS_SET_NAME_H_
44