blob: 98dcb9bde4e22417a1c80ca3e668e21722e21687 (
plain)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
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<Self>
{
match repr {
$($raw => Some(Self::$variant),)*
_ => None
}
}
}
};
}
pub(crate) use enum_from_repr;
|