IntrGuard

Struct IntrGuard 

Source
pub struct IntrGuard {
    flags: usize,
}
Expand description

中断保护器,基于 RAII 实现中断保护。 在创建时原子地禁用中断并保存之前的状态; 在销毁时自动恢复之前的中断状态。 不可重入 (即不能嵌套调用 IntrGuard::new())。 使用示例:

{
    let guard = IntrGuard::new(); // 禁用中断
    // 临界区代码
} // 离开作用域,自动恢复中断状态

Fields§

§flags: usize

Implementations§

Source§

impl IntrGuard

Source

pub fn new() -> Self

原子地禁用中断并返回一个 IntrGuard 实例。 该实例在离开作用域时会自动恢复中断状态。

Source

pub fn was_enabled(&self) -> bool

检查进入临界区前,中断是否处于启用状态。 返回值:中断是否处于启用状态

Trait Implementations§

Source§

impl Drop for IntrGuard

Source§

fn drop(&mut self)

当 IntrGuard 离开作用域时,自动恢复中断状态。

Auto Trait Implementations§

§

impl Freeze for IntrGuard

§

impl RefUnwindSafe for IntrGuard

§

impl Send for IntrGuard

§

impl Sync for IntrGuard

§

impl Unpin for IntrGuard

§

impl UnwindSafe for IntrGuard

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.