@@ -45,29 +45,31 @@ impl Thread {
45
45
Err(io::Error::last_os_error())
46
46
};
47
47
48
- extern "system" fn thread_start(main: *mut c_void) -> c::DWORD {
49
- unsafe {
50
- // Next, reserve some stack space for if we otherwise run out of stack.
51
- stack_overflow::reserve_stack();
52
- // Finally, let's run some code.
53
- Box::from_raw(main as *mut Box<dyn FnOnce()>)();
54
- }
48
+ unsafe extern "system" fn thread_start(main: *mut c_void) -> c::DWORD {
49
+ // Next, reserve some stack space for if we otherwise run out of stack.
50
+ stack_overflow::reserve_stack();
51
+ // Finally, let's run some code.
52
+ Box::from_raw(main as *mut Box<dyn FnOnce()>)();
55
53
0
56
54
}
57
55
}
58
56
59
57
pub fn set_name(name: &CStr) {
60
58
if let Ok(utf8) = name.to_str() {
61
59
if let Ok(utf16) = to_u16s(utf8) {
62
- Self::set_name_wide(&utf16)
60
+ unsafe {
61
+ // SAFETY: the vec returned by `to_u16s` ends with a zero value
62
+ Self::set_name_wide(&utf16)
63
+ }
63
64
};
64
65
};
65
66
}
66
67
67
- pub fn set_name_wide(name: &[u16]) {
68
- unsafe {
69
- c::SetThreadDescription(c::GetCurrentThread(), name.as_ptr());
70
- };
68
+ /// # Safety
69
+ ///
70
+ /// `name` must end with a zero value
71
+ pub unsafe fn set_name_wide(name: &[u16]) {
72
+ c::SetThreadDescription(c::GetCurrentThread(), name.as_ptr());
71
73
}
72
74
73
75
pub fn join(self) {
0 commit comments