Skip to content

Commit

Permalink
Windows: set main thread name without reencoding
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisDenton committed Apr 6, 2024
1 parent a2ce517 commit 3bcd03a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion library/std/src/sys/pal/windows/mod.rs
Expand Up @@ -61,7 +61,7 @@ pub unsafe fn init(_argc: isize, _argv: *const *const u8, _sigpipe: u8) {

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

// SAFETY: must be called only once during runtime cleanup.
Expand Down
10 changes: 7 additions & 3 deletions library/std/src/sys/pal/windows/thread.rs
Expand Up @@ -59,13 +59,17 @@ impl Thread {
pub fn set_name(name: &CStr) {
if let Ok(utf8) = name.to_str() {
if let Ok(utf16) = to_u16s(utf8) {
unsafe {
c::SetThreadDescription(c::GetCurrentThread(), utf16.as_ptr());
};
Self::set_name_wide(&utf16)
};
};
}

pub fn set_name_wide(name: &[u16]) {
unsafe {
c::SetThreadDescription(c::GetCurrentThread(), name.as_ptr());
};
}

pub fn join(self) {
let rc = unsafe { c::WaitForSingleObject(self.handle.as_raw_handle(), c::INFINITE) };
if rc == c::WAIT_FAILED {
Expand Down

0 comments on commit 3bcd03a

Please sign in to comment.