ax_task/thread/id.rs
1//! Generation-checked thread identity.
2
3/// A thread registry identity containing a slot and reuse generation.
4#[repr(transparent)]
5#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
6pub struct ThreadId(u64);
7
8impl ThreadId {
9 /// Creates an identifier from a registry slot and generation.
10 pub const fn from_parts(slot: u32, generation: u32) -> Self {
11 Self(((generation as u64) << 32) | slot as u64)
12 }
13
14 /// Returns the registry slot.
15 pub const fn slot(self) -> u32 {
16 self.0 as u32
17 }
18
19 /// Returns the slot reuse generation.
20 pub const fn generation(self) -> u32 {
21 (self.0 >> 32) as u32
22 }
23
24 /// Returns the stable integer representation.
25 pub const fn as_u64(self) -> u64 {
26 self.0
27 }
28}