is_main_thread/platform_impl/
linux.rs1#![cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
2
3pub fn is_main_thread() -> Option<bool> {
4 Some(is_main_thread_internal())
5}
6
7#[cfg(target_os = "linux")]
8fn is_main_thread_internal() -> bool {
9 use libc::{c_long, getpid, syscall, SYS_gettid};
10
11 unsafe { syscall(SYS_gettid) == getpid() as c_long }
12}
13
14#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd"))]
15fn is_main_thread_internal() -> bool {
16 use libc::pthread_main_np;
17
18 unsafe { pthread_main_np() == 1 }
19}
20
21#[cfg(target_os = "netbsd")]
22fn is_main_thread_internal() -> bool {
23 use libc::_lwp_self;
24
25 unsafe { _lwp_self() == 1 }
26}