Skip to main content

ax_task/thread/
current_token.rs

1//! Typed identity capability for the executing scheduler thread.
2
3use core::marker::PhantomData;
4
5use super::ThreadId;
6
7/// Move-only proof of the scheduler thread executing this task context.
8///
9/// Scheduler-adjacent primitives may retain this token on the current stack
10/// across preemption and park/resume, then reuse it for bounded metadata
11/// transitions. It owns no scheduler resource and cannot cross threads.
12#[derive(Debug)]
13pub struct CurrentThreadToken {
14    thread: ThreadId,
15    _not_send: PhantomData<*mut ()>,
16}
17
18impl CurrentThreadToken {
19    pub(crate) const fn new(thread: ThreadId) -> Self {
20        Self {
21            thread,
22            _not_send: PhantomData,
23        }
24    }
25
26    /// Returns the generation-bearing identity captured for this execution.
27    pub const fn id(&self) -> ThreadId {
28        self.thread
29    }
30}