Windows: set main thread name without reencoding

This commit is contained in:
Chris Denton 2024-04-06 03:15:06 +00:00
parent b48e7e5496
commit 952d432666
No known key found for this signature in database
GPG Key ID: 713472F2F45627DE
2 changed files with 8 additions and 4 deletions

View File

@ -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.

View File

@ -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 {