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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#[cfg(windows)]
mod win32;
#[cfg(windows)]
pub use win32::*;
#[cfg(unix)]
mod unix;
#[cfg(unix)]
pub use unix::*;
#[cfg(all(not(unix), not(windows)))]
mod no_os;
#[cfg(all(not(unix), not(windows)))]
pub use no_os::*;
#[repr(transparent)]
#[derive(Copy, Clone, Debug)]
pub struct ThreadId {
id: RawId,
}
impl ThreadId {
#[inline]
pub fn current() -> Self {
Self {
id: get_raw_id(),
}
}
#[inline]
pub const fn as_raw(&self) -> RawId {
self.id
}
}
impl core::cmp::Eq for ThreadId {}
impl core::cmp::PartialEq<ThreadId> for ThreadId {
#[inline(always)]
fn eq(&self, other: &ThreadId) -> bool {
raw_thread_eq(self.id, other.id)
}
}
impl core::hash::Hash for ThreadId {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.id.hash(state);
}
}
impl core::fmt::Display for ThreadId {
#[inline]
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Display::fmt(&self.id, f)
}
}
impl core::fmt::LowerHex for ThreadId {
#[inline]
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::LowerHex::fmt(&self.id, f)
}
}
impl core::fmt::UpperHex for ThreadId {
#[inline]
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::UpperHex::fmt(&self.id, f)
}
}
impl core::fmt::Octal for ThreadId {
#[inline]
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
core::fmt::Octal::fmt(&self.id, f)
}
}