pub struct ThreadExtension { /* private fields */ }Expand description
Opaque OS-specific data attached to a thread.
Implementations§
Source§impl ThreadExtension
impl ThreadExtension
Sourcepub const unsafe fn new(data: usize, ops: &'static ThreadExtensionOps) -> Self
pub const unsafe fn new(data: usize, ops: &'static ThreadExtensionOps) -> Self
Creates an extension from opaque data and a static callback table.
§Safety
data must satisfy every callback contract in ops, and the owning OS
must ensure callbacks do not allocate, block, or re-enter the scheduler
when invoked as switch hooks. Task-context callbacks must return to the
dedicated service thread; abandoning that stack leaves their explicit
in-flight lifetime claim closed to prevent use-after-free.
Sourcepub fn with_scheduler_tick_cpu_time(
self,
accounting: Arc<SchedulerTickCpuTime>,
) -> Self
pub fn with_scheduler_tick_cpu_time( self, accounting: Arc<SchedulerTickCpuTime>, ) -> Self
Attaches IRQ-safe user/system CPU-time sampling to this thread.
The scheduler retains the capability and charges it directly from each periodic tick. No OS callback or deferred task work runs in hard IRQ.
Sourcepub unsafe fn with_running_policy_applied_hook(
self,
callback: RunningPolicyAppliedHook,
) -> Self
pub unsafe fn with_running_policy_applied_hook( self, callback: RunningPolicyAppliedHook, ) -> Self
Adds a bounded callback for base-policy changes applied to a running thread.
The callback runs after the scheduler releases the thread-state lock. The current CPU still owns the scheduler baton, so the callback is serialized with switch hooks for the same thread. Queued and inactive base-policy changes are observed through the policy snapshot passed to the next switch-in instead. PI donation does not change this value.
§Safety
callback must interpret data according to this extension, remain
valid for its complete lifetime, and perform only bounded operations.
It must not allocate, block, or re-enter the scheduler.
Sourcepub unsafe fn with_scheduler_tick_work(
self,
gate: Arc<SchedulerTickGate>,
callback: SchedulerTickTaskWork,
) -> Self
pub unsafe fn with_scheduler_tick_work( self, gate: Arc<SchedulerTickGate>, callback: SchedulerTickTaskWork, ) -> Self
Adds task-context work gated by scheduler tick interest.
The scheduler hard-IRQ path only publishes a typed deferred-work record. The callback runs later on the dedicated task-work service thread.
§Safety
callback must interpret data according to this extension, remain
valid for its complete lifetime, and return normally to the task-work
service. The callback may use task-context synchronization but must not
retain the borrowed extension data after it returns. It may return
SchedulerTickWorkDisposition::Retry only after a transient conflict
and before publishing any accounting, timer, or signal state.
Sourcepub const fn ops(&self) -> &'static ThreadExtensionOps
pub const fn ops(&self) -> &'static ThreadExtensionOps
Returns the callback table used as the extension type identity.
Sourcepub const fn running_policy_applied_hook(
&self,
) -> Option<RunningPolicyAppliedHook>
pub const fn running_policy_applied_hook( &self, ) -> Option<RunningPolicyAppliedHook>
Returns the callback used to observe running-thread base-policy changes.
Sourcepub unsafe fn forward_running_policy_applied(
&self,
thread: ThreadId,
base_policy: SchedulePolicy,
observed_ns: u64,
) -> bool
pub unsafe fn forward_running_policy_applied( &self, thread: ThreadId, base_policy: SchedulePolicy, observed_ns: u64, ) -> bool
Forwards a running-thread base-policy change to this extension.
Returns false when this extension did not register such a hook.
§Safety
The caller must retain this extension, invoke the callback only after scheduler metadata locks are released, and preserve the hook’s bounded, non-blocking context contract.
Sourcepub fn scheduler_tick_work_gate(&self) -> Option<Arc<SchedulerTickGate>>
pub fn scheduler_tick_work_gate(&self) -> Option<Arc<SchedulerTickGate>>
Clones the gate used to select scheduler-tick task work.
Runtime extension composition uses this to install the same interest generation on an outer scheduler-owned extension.
Sourcepub fn scheduler_tick_cpu_time(&self) -> Option<Arc<SchedulerTickCpuTime>>
pub fn scheduler_tick_cpu_time(&self) -> Option<Arc<SchedulerTickCpuTime>>
Clones the IRQ-safe CPU-time sampling capability.
Runtime extension composition uses this to preserve the inner OS capability on the outer scheduler-owned extension.
Sourcepub unsafe fn forward_scheduler_tick_work(
&self,
thread: ThreadId,
observed_ns: u64,
) -> Option<SchedulerTickWorkDisposition>
pub unsafe fn forward_scheduler_tick_work( &self, thread: ThreadId, observed_ns: u64, ) -> Option<SchedulerTickWorkDisposition>
Forwards one scheduler-tick task-work callback to this extension.
Returns None when this extension did not register such work.
§Safety
The caller must own an ordinary task-context publication authorized by
the gate returned from Self::scheduler_tick_work_gate, keep this
extension alive for the call, and invoke it at most once for that
publication. A forwarded SchedulerTickWorkDisposition::Retry keeps
the same no-partial-publication contract as the original callback.