mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Windows: set main thread name without reencoding
This commit is contained in:
parent
b48e7e5496
commit
952d432666
@ -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.
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user