xwrust::xwos::sync::sem

Struct SemSel

source
pub struct SemSel<'a, const M: XwSz>
where [XwBmp; { _ }]: Sized,
{ /* private fields */ }
Expand description

信号量的选择子

SemSel<'a, M>SemSel<M> 具有相同的生命周期约束 'a 。因为 SemSel<'a, M> 中包含了 SemSel<M> 的引用。

SemSel<'a, M> 中包含了绑定的位置,信号量 独占 一个位置。

SemSel::selected() 可用来判断信号量是否被选择。

SemSel<'a, M>drop() 时,会自动将 SemSel<M> 解绑。

Implementations§

source§

impl<'a, const M: XwSz> SemSel<'a, M>
where [XwBmp; { _ }]: Sized,

source

pub fn selected(&self, trg: &Bmp<M>) -> bool

判断触发的 选择信号 是否包括此信号量

§示例
    let msk = Bmp::<8>::new(); // 8位位图
    msk.s1all(); // 掩码为0xFF
    loop {
        let res = sel.select(&msk);
        match res {
            Ok(t) => { // 信号选择器上有 **选择信号** , `t` 为 **选择信号** 的位图。
                if sem0sel.selected(&t) { // 信号量0被选择到
                    sem0.trywait();
                }
                if sem1sel.selected(&t) { // 信号量1被选择到
                    sem1.trywait();
                }
            },
            Err(e) => { // 等待信号选择器失败,`e` 为 `SelError`
                break;
            },
        }
    }

Trait Implementations§

source§

impl<'a, const M: XwSz> Drop for SemSel<'a, M>
where [XwBmp; { _ }]: Sized,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a, const M: XwSz> Send for SemSel<'a, M>
where [XwBmp; { _ }]: Sized,

source§

impl<'a, const M: XwSz> Sync for SemSel<'a, M>
where [XwBmp; { _ }]: Sized,

Auto Trait Implementations§

§

impl<'a, const M: usize> Freeze for SemSel<'a, M>
where [usize; { _ }]: Sized,

§

impl<'a, const M: usize> !RefUnwindSafe for SemSel<'a, M>

§

impl<'a, const M: usize> Unpin for SemSel<'a, M>
where [usize; { _ }]: Sized,

§

impl<'a, const M: usize> !UnwindSafe for SemSel<'a, M>

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.