[Fuzzer] SetThreadName implementation for Windows

Api available since Windows Server 2016/Windows 10 1607.

Reviewers: vitalybuka

Reviewed-By: vitalybuka

Differential Revision: https://reviews.llvm.org/D156317

GitOrigin-RevId: e3f935c7f80cfb8bdcbe0479672bc92485eecd85
diff --git a/FuzzerUtilWindows.cpp b/FuzzerUtilWindows.cpp
index 7177016..a59a496 100644
--- a/FuzzerUtilWindows.cpp
+++ b/FuzzerUtilWindows.cpp
@@ -24,7 +24,9 @@
 #include <windows.h>
 
 // This must be included after windows.h.
+#include <processthreadsapi.h>
 #include <psapi.h>
+#include <stringapiset.h>
 
 namespace fuzzer {
 
@@ -234,8 +236,9 @@
 }
 
 void SetThreadName(std::thread &thread, const std::string &name) {
-  // TODO ?
-  // to UTF-8 then SetThreadDescription ?
+  wchar_t wname[16];
+  if (MultiByteToWideChar(CP_UTF8, 0, name.c_str(), -1, wname, 16) > 0)
+    (void)SetThreadDescription(thread.native_handle(), wname);
 }
 
 } // namespace fuzzer