Skip to content

Commit d3716a5

Browse files
committed
Windows: set main thread name without reencoding
1 parent 3f90d4a commit d3716a5

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Diff for: std/src/sys/pal/windows/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub unsafe fn init(_argc: isize, _argv: *const *const u8, _sigpipe: u8) {
6161

6262
// Normally, `thread::spawn` will call `Thread::set_name` but since this thread already
6363
// exists, we have to call it ourselves.
64-
thread::Thread::set_name(&c"main");
64+
thread::Thread::set_name_wide(wide_str!("main"));
6565
}
6666

6767
// SAFETY: must be called only once during runtime cleanup.

Diff for: std/src/sys/pal/windows/thread.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,17 @@ impl Thread {
5959
pub fn set_name(name: &CStr) {
6060
if let Ok(utf8) = name.to_str() {
6161
if let Ok(utf16) = to_u16s(utf8) {
62-
unsafe {
63-
c::SetThreadDescription(c::GetCurrentThread(), utf16.as_ptr());
64-
};
62+
Self::set_name_wide(&utf16)
6563
};
6664
};
6765
}
6866

67+
pub fn set_name_wide(name: &[u16]) {
68+
unsafe {
69+
c::SetThreadDescription(c::GetCurrentThread(), name.as_ptr());
70+
};
71+
}
72+
6973
pub fn join(self) {
7074
let rc = unsafe { c::WaitForSingleObject(self.handle.as_raw_handle(), c::INFINITE) };
7175
if rc == c::WAIT_FAILED {

0 commit comments

Comments
 (0)