Windows utility to setTheadName to help debugging.

R=juberti@google.com, mflodman@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/49919004

Cr-Original-Commit-Position: refs/heads/master@{#9182}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: 5ec998511c5ac8e0602fe3373f214fcc3ef33a24
diff --git a/base/win32.cc b/base/win32.cc
index c1b55bf..fa75559 100644
--- a/base/win32.cc
+++ b/base/win32.cc
@@ -453,4 +453,19 @@
   }
   return ret;
 }
+
+void SetCurrentThreadName(const char* name) {
+  struct {
+    DWORD dwType;
+    LPCSTR szName;
+    DWORD dwThreadID;
+    DWORD dwFlags;
+  } threadname_info = {0x100, name, static_cast<DWORD>(-1), 0};
+
+  __try {
+    ::RaiseException(0x406D1388, 0, sizeof(threadname_info) / sizeof(DWORD),
+                     reinterpret_cast<ULONG_PTR*>(&threadname_info));
+  } __except (EXCEPTION_EXECUTE_HANDLER) {
+  }
+}
 }  // namespace rtc
diff --git a/base/win32.h b/base/win32.h
index 07e1e1e..a302c47 100644
--- a/base/win32.h
+++ b/base/win32.h
@@ -46,8 +46,6 @@
 const char* win32_inet_ntop(int af, const void *src, char* dst, socklen_t size);
 int win32_inet_pton(int af, const char* src, void *dst);
 
-///////////////////////////////////////////////////////////////////////////////
-
 inline std::wstring ToUtf16(const char* utf8, size_t len) {
   int len16 = ::MultiByteToWideChar(CP_UTF8, 0, utf8, static_cast<int>(len),
                                     NULL, 0);
@@ -128,7 +126,8 @@
 
 bool AdjustCurrentProcessPrivilege(const TCHAR* privilege, bool to_enable);
 
-///////////////////////////////////////////////////////////////////////////////
+// Sets the current thread name for the windows debugger.
+void SetCurrentThreadName(const char* name);
 
 }  // namespace rtc