Skip to main content

ThreadParker

Struct ThreadParker 

pub struct ThreadParker { /* private fields */ }
Expand description

只有创建线程可以停放和消费通知;不可跨线程转移或共享。

提交、任务唤醒、取消和关闭的实际发布者通过ThreadNotifier通知。 策略、来源重查和最迟再次检查时刻由执行器负责,本对象不判断空闲,不访问队列。

Implementations§

§

impl ThreadParker

pub fn new() -> Self

绑定当前线程,准备一份共享通知状态,初始notified=true以安排首次检查。

pub fn notifier(&self) -> ThreadNotifier

克隆同一原线程的受限通知,不产生另一个停放拥有者。

pub fn owner_thread(&self) -> ThreadId

读取固定原线程身份,不取得其它线程推进权。

pub fn is_notified(&self) -> bool

Acquire取样,不消费通知,不证明下一瞬间可以休眠。

pub fn take_notification(&mut self) -> bool

原线程一次Acquire交换,取走现有通知;取走后必须实际重新检查工作。

pub fn park_timeout(&mut self, duration: Duration) -> ThreadParkResult

通知存在则直接返回,否则限时停放,返回后再次取得通知并重新分类。

duration是调用方选定的本次上限,零不等待。休眠策略与定时来源最迟检查时刻须 在调用前组合;本层不擅自延长上限。最后通知检查到实际park之间不得执行用户回调、 日志或另一个park,以免其它代码消费同一线程permit。任何返回都需要上层重查来源。 系统调度可能延迟线程恢复,本函数不承诺墙钟硬上界。

Trait Implementations§

§

impl Default for ThreadParker

§

fn default() -> Self

Returns the “default value” for a type. 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.