Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3206)

Unified Diff: base/threading/platform_thread_win.cc

Issue 2692213003: Use Windows 10 thread naming API, SetThreadDescription (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/platform_thread_win.cc
diff --git a/base/threading/platform_thread_win.cc b/base/threading/platform_thread_win.cc
index 2644eee520b82c0520c760addc8e9fc3415aadf2..1326f2f5dcfe2a557c5fc92e231fc05bb8370918 100644
--- a/base/threading/platform_thread_win.cc
+++ b/base/threading/platform_thread_win.cc
@@ -10,6 +10,8 @@
#include "base/debug/alias.h"
#include "base/debug/profiler.h"
#include "base/logging.h"
+#include "base/strings/string_piece.h"
+#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_id_name_manager.h"
#include "base/threading/thread_restrictions.h"
#include "base/tracked_objects.h"
@@ -30,6 +32,9 @@ typedef struct tagTHREADNAME_INFO {
DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
+typedef HRESULT(WINAPI* SETTHREADDESCRIPTION)(HANDLE hThread,
brucedawson 2017/02/21 22:12:40 Somewhere you need a comment saying which version
chengx 2017/02/22 21:24:34 Done.
+ PCWSTR lpThreadDescription);
+
// This function has try handling, so it is separated out of its caller.
void SetNameInternal(PlatformThreadId thread_id, const char* name) {
THREADNAME_INFO info;
@@ -179,6 +184,19 @@ void PlatformThread::SetName(const std::string& name) {
if (!::IsDebuggerPresent() && !base::debug::IsBinaryInstrumented())
return;
brucedawson 2017/02/21 22:12:40 Oops! This will return early in those cases where
chengx 2017/02/22 21:24:34 Done.
+ HMODULE kernal32dll = ::GetModuleHandle(L"Kernel32.dll");
brucedawson 2017/02/21 22:12:40 Spelling - should be kernel32dll. Or "kernel32". O
chengx 2017/02/22 21:24:34 Done.
+ if (kernal32dll) {
+ SETTHREADDESCRIPTION set_thread_description_ptr =
brucedawson 2017/02/21 22:12:40 Consider using 'auto' for the type - no need to sp
chengx 2017/02/22 21:24:34 Done.
+ reinterpret_cast<SETTHREADDESCRIPTION>(
+ ::GetProcAddress(kernal32dll, "SetThreadDescription"));
+ base::StringPiece name_string(name);
+ std::wstring name_wstring = base::UTF8ToWide(name_string);
brucedawson 2017/02/21 22:12:40 The initialization of name_wstring should be insid
chengx 2017/02/22 21:24:34 Done.
+ if (set_thread_description_ptr) {
+ set_thread_description_ptr(GetCurrentThread(), name_wstring.c_str());
+ return;
+ }
+ }
+
SetNameInternal(CurrentId(), name.c_str());
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698