Skip to content

Commit ee2f398

Browse files
committed
Windows: set main thread name without reencoding
1 parent 30840c5 commit ee2f398

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

library/std/src/sys/pal/windows/mod.rs

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

6161
// Normally, `thread::spawn` will call `Thread::set_name` but since this thread already
6262
// exists, we have to call it ourselves.
63-
thread::Thread::set_name(&c"main");
63+
thread::Thread::set_name_wide(&['m' as u16, 'a' as u16, 'i' as u16, 'n' as u16, 0]);
6464
}
6565

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

library/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)