1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
pub fn set_current_thread_name(name: &str) -> Result<(), SetCurrentThreadNameError>
{
match name.len()
{
0 => Err(SetCurrentThreadNameError::NameIsEmpty),
length if length > 15 => Err(SetCurrentThreadNameError::NameIsTooLong),
_ =>
{
let c_string = CString::new(name.to_owned())?;
let pointer = c_string.as_ptr();
#[cfg(any(target_os = "android", target_os = "linux"))] unsafe { ::libc::prctl(::libc::PR_SET_NAME, pointer) };
#[cfg(target_os = "netbsd")] unsafe { ::libc::pthread_setname_np(::libc::pthread_self(), pointer) };
#[cfg(any(target_os = "ios", target_os = "macos"))] unsafe { ::libc::pthread_setname_np(pointer) };
#[cfg(any(target_os = "bitrig", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))] unsafe { ::libc::pthread_set_name_np(::libc::pthread_self(), pointer) };
Ok(())
}
}
}