use libc::{c_long, getpid, syscall, SYS_gettid}; pub fn is_main_thread() -> bool { let ttid = unsafe { syscall(SYS_gettid) }; let pid = c_long::from(unsafe { getpid() }); ttid == pid } macro_rules! enum_from_repr { ( #[repr($repr: ident)] $(#[$attr: meta])* $visibility: vis enum $name: ident { $($variant: ident = $raw: path,)* } ) => { $(#[$attr])* #[repr($repr)] $visibility enum $name { $($variant = $raw,)* } impl $name { fn from_repr(repr: $repr) -> Option { match repr { $($raw => Some(Self::$variant),)* _ => None } } } }; } pub(crate) use enum_from_repr;