Skip to main content

ThreadExtension

Struct ThreadExtension 

Source
pub struct ThreadExtension { /* private fields */ }
Expand description

Opaque OS-specific data attached to a thread.

Implementations§

Source§

impl ThreadExtension

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub const fn data(&self) -> usize

Returns the opaque OS-owned value.

Source

pub const fn ops(&self) -> &'static ThreadExtensionOps

Returns the callback table used as the extension type identity.

Source

pub const fn running_policy_applied_hook( &self, ) -> Option<RunningPolicyAppliedHook>

Returns the callback used to observe running-thread base-policy changes.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for ThreadExtension

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for ThreadExtension

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.