#![doc = include_str!("../README.md")]
pub fn gettid() -> u64 {
gettid_impl()
}
#[cfg(any(target_os = "linux", target_os = "android"))]
pub fn gettid_impl() -> u64 {
unsafe { libc::gettid() as u64 }
}
#[cfg(target_os = "macos")]
pub fn gettid_impl() -> u64 {
let mut result = 0;
let res = unsafe { libc::pthread_threadid_np(0, &mut result) };
assert_eq!(res, 0, "error retrieving thread ID");
result
}
#[cfg(target_os = "freebsd")]
pub fn gettid_impl() -> u64 {
unsafe { libc::pthread_getthreadid_np() as u64 }
}
#[cfg(target_os = "openbsd")]
pub fn gettid_impl() -> u64 {
unsafe { libc::getthrid() as u64 }
}
#[cfg(target_os = "netbsd")]
pub fn gettid_impl() -> u64 {
unsafe { libc::_lwp_self() as u64 }
}
#[cfg(target_os = "windows")]
pub fn gettid_impl() -> u64 {
unsafe extern "system" {
fn GetCurrentThreadId() -> u32;
}
unsafe { GetCurrentThreadId().into() }
}